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); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 153 | if (mirror::kUseStringCompression) { |
| 154 | __ andl(length_loc.AsRegister<Register>(), Immediate(INT32_MAX)); |
| 155 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 156 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 157 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 158 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 159 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 160 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 161 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 162 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 163 | Primitive::kPrimInt); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 164 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 165 | ? kQuickThrowStringBounds |
| 166 | : kQuickThrowArrayBounds; |
| 167 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 168 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 169 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 172 | bool IsFatal() const OVERRIDE { return true; } |
| 173 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 174 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 175 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 176 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 178 | }; |
| 179 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 180 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 181 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 182 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 183 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 185 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 186 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 187 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 188 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 189 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 190 | if (successor_ == nullptr) { |
| 191 | __ jmp(GetReturnLabel()); |
| 192 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 193 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 194 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 197 | Label* GetReturnLabel() { |
| 198 | DCHECK(successor_ == nullptr); |
| 199 | return &return_label_; |
| 200 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 202 | HBasicBlock* GetSuccessor() const { |
| 203 | return successor_; |
| 204 | } |
| 205 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 206 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 207 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 208 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 209 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 210 | Label return_label_; |
| 211 | |
| 212 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 213 | }; |
| 214 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 215 | class LoadStringSlowPathX86 : public SlowPathCode { |
| 216 | public: |
| 217 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
| 218 | |
| 219 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 220 | LocationSummary* locations = instruction_->GetLocations(); |
| 221 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 222 | |
| 223 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 224 | __ Bind(GetEntryLabel()); |
| 225 | SaveLiveRegisters(codegen, locations); |
| 226 | |
| 227 | InvokeRuntimeCallingConvention calling_convention; |
| 228 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 229 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
| 230 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); |
| 231 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
| 232 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 233 | RestoreLiveRegisters(codegen, locations); |
| 234 | |
| 235 | // Store the resolved String to the BSS entry. |
| 236 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 237 | __ movl(Address(method_address, CodeGeneratorX86::kDummy32BitOffset), |
| 238 | locations->Out().AsRegister<Register>()); |
| 239 | Label* fixup_label = x86_codegen->NewStringBssEntryPatch(instruction_->AsLoadString()); |
| 240 | __ Bind(fixup_label); |
| 241 | |
| 242 | __ jmp(GetExitLabel()); |
| 243 | } |
| 244 | |
| 245 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 246 | |
| 247 | private: |
| 248 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 249 | }; |
| 250 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 251 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | public: |
| 253 | LoadClassSlowPathX86(HLoadClass* cls, |
| 254 | HInstruction* at, |
| 255 | uint32_t dex_pc, |
| 256 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 257 | : 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] | 258 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 259 | } |
| 260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 261 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 262 | LocationSummary* locations = at_->GetLocations(); |
| 263 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 264 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | |
| 267 | InvokeRuntimeCallingConvention calling_convention; |
| 268 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 269 | x86_codegen->InvokeRuntime(do_clinit_ ? kQuickInitializeStaticStorage |
| 270 | : kQuickInitializeType, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 271 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 272 | if (do_clinit_) { |
| 273 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 274 | } else { |
| 275 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 276 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | |
| 278 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 279 | Location out = locations->Out(); |
| 280 | if (out.IsValid()) { |
| 281 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 282 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 284 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 285 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 286 | __ jmp(GetExitLabel()); |
| 287 | } |
| 288 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 289 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 290 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | private: |
| 292 | // The class this slow path will load. |
| 293 | HLoadClass* const cls_; |
| 294 | |
| 295 | // The instruction where this slow path is happening. |
| 296 | // (Might be the load class or an initialization check). |
| 297 | HInstruction* const at_; |
| 298 | |
| 299 | // The dex PC of `at_`. |
| 300 | const uint32_t dex_pc_; |
| 301 | |
| 302 | // Whether to initialize the class. |
| 303 | const bool do_clinit_; |
| 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 306 | }; |
| 307 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 308 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 309 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 310 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 311 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 313 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 314 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 315 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 316 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 317 | DCHECK(instruction_->IsCheckCast() |
| 318 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | |
| 320 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 321 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 323 | if (!is_fatal_) { |
| 324 | SaveLiveRegisters(codegen, locations); |
| 325 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
| 327 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 328 | // move resolver. |
| 329 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 330 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 331 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 332 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 333 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 334 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 335 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 336 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 337 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | if (instruction_->IsInstanceOf()) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 339 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 340 | instruction_, |
| 341 | instruction_->GetDexPc(), |
| 342 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 343 | CheckEntrypointTypes< |
Andreas Gampe | 6740997 | 2016-07-19 22:34:53 -0700 | [diff] [blame] | 344 | kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 345 | } else { |
| 346 | DCHECK(instruction_->IsCheckCast()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 347 | x86_codegen->InvokeRuntime(kQuickCheckCast, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 348 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | if (!is_fatal_) { |
| 352 | if (instruction_->IsInstanceOf()) { |
| 353 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 354 | } |
| 355 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 356 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | __ jmp(GetExitLabel()); |
| 358 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 361 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 362 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 363 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 364 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 365 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 366 | |
| 367 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 368 | }; |
| 369 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 370 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 371 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 372 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 373 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 374 | |
| 375 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 376 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 377 | __ Bind(GetEntryLabel()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 378 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 379 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 383 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 386 | }; |
| 387 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 388 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 389 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 390 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 391 | |
| 392 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 393 | LocationSummary* locations = instruction_->GetLocations(); |
| 394 | __ Bind(GetEntryLabel()); |
| 395 | SaveLiveRegisters(codegen, locations); |
| 396 | |
| 397 | InvokeRuntimeCallingConvention calling_convention; |
| 398 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 399 | parallel_move.AddMove( |
| 400 | locations->InAt(0), |
| 401 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 402 | Primitive::kPrimNot, |
| 403 | nullptr); |
| 404 | parallel_move.AddMove( |
| 405 | locations->InAt(1), |
| 406 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 407 | Primitive::kPrimInt, |
| 408 | nullptr); |
| 409 | parallel_move.AddMove( |
| 410 | locations->InAt(2), |
| 411 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 412 | Primitive::kPrimNot, |
| 413 | nullptr); |
| 414 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 415 | |
| 416 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 417 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 418 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 419 | RestoreLiveRegisters(codegen, locations); |
| 420 | __ jmp(GetExitLabel()); |
| 421 | } |
| 422 | |
| 423 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 424 | |
| 425 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 426 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 427 | }; |
| 428 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 429 | // Slow path marking an object during a read barrier. |
| 430 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 431 | public: |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 432 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location obj, bool unpoison) |
| 433 | : SlowPathCode(instruction), obj_(obj), unpoison_(unpoison) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 434 | DCHECK(kEmitCompilerReadBarrier); |
| 435 | } |
| 436 | |
| 437 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 438 | |
| 439 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 440 | LocationSummary* locations = instruction_->GetLocations(); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 441 | Register reg = obj_.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 442 | DCHECK(locations->CanCall()); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 443 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 444 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 445 | instruction_->IsStaticFieldGet() || |
| 446 | instruction_->IsArrayGet() || |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 447 | instruction_->IsArraySet() || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 448 | instruction_->IsLoadClass() || |
| 449 | instruction_->IsLoadString() || |
| 450 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 451 | instruction_->IsCheckCast() || |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 452 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || |
| 453 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | << "Unexpected instruction in read barrier marking slow path: " |
| 455 | << instruction_->DebugName(); |
| 456 | |
| 457 | __ Bind(GetEntryLabel()); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 458 | if (unpoison_) { |
| 459 | // Object* ref = ref_addr->AsMirrorPtr() |
| 460 | __ MaybeUnpoisonHeapReference(reg); |
| 461 | } |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 462 | // No need to save live registers; it's taken care of by the |
| 463 | // entrypoint. Also, there is no need to update the stack mask, |
| 464 | // as this runtime call will not trigger a garbage collection. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 465 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 466 | DCHECK_NE(reg, ESP); |
| 467 | DCHECK(0 <= reg && reg < kNumberOfCpuRegisters) << reg; |
| 468 | // "Compact" slow path, saving two moves. |
| 469 | // |
| 470 | // Instead of using the standard runtime calling convention (input |
| 471 | // and output in EAX): |
| 472 | // |
| 473 | // EAX <- obj |
| 474 | // EAX <- ReadBarrierMark(EAX) |
| 475 | // obj <- EAX |
| 476 | // |
| 477 | // we just use rX (the register holding `obj`) as input and output |
| 478 | // of a dedicated entrypoint: |
| 479 | // |
| 480 | // rX <- ReadBarrierMarkRegX(rX) |
| 481 | // |
| 482 | int32_t entry_point_offset = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 483 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kX86PointerSize>(reg); |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 484 | // This runtime call does not require a stack map. |
| 485 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 486 | __ jmp(GetExitLabel()); |
| 487 | } |
| 488 | |
| 489 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 490 | const Location obj_; |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 491 | const bool unpoison_; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 492 | |
| 493 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 494 | }; |
| 495 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 496 | // Slow path generating a read barrier for a heap reference. |
| 497 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 498 | public: |
| 499 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 500 | Location out, |
| 501 | Location ref, |
| 502 | Location obj, |
| 503 | uint32_t offset, |
| 504 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 505 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 506 | out_(out), |
| 507 | ref_(ref), |
| 508 | obj_(obj), |
| 509 | offset_(offset), |
| 510 | index_(index) { |
| 511 | DCHECK(kEmitCompilerReadBarrier); |
| 512 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 513 | // has been overwritten by (or after) the heap object reference load |
| 514 | // to be instrumented, e.g.: |
| 515 | // |
| 516 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 517 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 518 | // |
| 519 | // In that case, we have lost the information about the original |
| 520 | // object, and the emitted read barrier cannot work properly. |
| 521 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 522 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 523 | } |
| 524 | |
| 525 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 526 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 527 | LocationSummary* locations = instruction_->GetLocations(); |
| 528 | Register reg_out = out_.AsRegister<Register>(); |
| 529 | DCHECK(locations->CanCall()); |
| 530 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 531 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 532 | instruction_->IsStaticFieldGet() || |
| 533 | instruction_->IsArrayGet() || |
| 534 | instruction_->IsInstanceOf() || |
| 535 | instruction_->IsCheckCast() || |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 536 | (instruction_->IsInvokeVirtual()) && instruction_->GetLocations()->Intrinsified()) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 537 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 538 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 539 | |
| 540 | __ Bind(GetEntryLabel()); |
| 541 | SaveLiveRegisters(codegen, locations); |
| 542 | |
| 543 | // We may have to change the index's value, but as `index_` is a |
| 544 | // constant member (like other "inputs" of this slow path), |
| 545 | // introduce a copy of it, `index`. |
| 546 | Location index = index_; |
| 547 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 548 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 549 | if (instruction_->IsArrayGet()) { |
| 550 | // Compute the actual memory offset and store it in `index`. |
| 551 | Register index_reg = index_.AsRegister<Register>(); |
| 552 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 553 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 554 | // We are about to change the value of `index_reg` (see the |
| 555 | // calls to art::x86::X86Assembler::shll and |
| 556 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 557 | // not been saved by the previous call to |
| 558 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 559 | // callee-save register -- |
| 560 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 561 | // callee-save registers, as it has been designed with the |
| 562 | // assumption that callee-save registers are supposed to be |
| 563 | // handled by the called function. So, as a callee-save |
| 564 | // register, `index_reg` _would_ eventually be saved onto |
| 565 | // the stack, but it would be too late: we would have |
| 566 | // changed its value earlier. Therefore, we manually save |
| 567 | // it here into another freely available register, |
| 568 | // `free_reg`, chosen of course among the caller-save |
| 569 | // registers (as a callee-save `free_reg` register would |
| 570 | // exhibit the same problem). |
| 571 | // |
| 572 | // Note we could have requested a temporary register from |
| 573 | // the register allocator instead; but we prefer not to, as |
| 574 | // this is a slow path, and we know we can find a |
| 575 | // caller-save register that is available. |
| 576 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 577 | __ movl(free_reg, index_reg); |
| 578 | index_reg = free_reg; |
| 579 | index = Location::RegisterLocation(index_reg); |
| 580 | } else { |
| 581 | // The initial register stored in `index_` has already been |
| 582 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 583 | // (as it is not a callee-save register), so we can freely |
| 584 | // use it. |
| 585 | } |
| 586 | // Shifting the index value contained in `index_reg` by the scale |
| 587 | // factor (2) cannot overflow in practice, as the runtime is |
| 588 | // unable to allocate object arrays with a size larger than |
| 589 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 590 | __ shll(index_reg, Immediate(TIMES_4)); |
| 591 | static_assert( |
| 592 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 593 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 594 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 595 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 596 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 597 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 598 | // (as in the case of ArrayGet), as it is actually an offset |
| 599 | // to an object field within an object. |
| 600 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 601 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 602 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 603 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 604 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 605 | DCHECK_EQ(offset_, 0U); |
| 606 | DCHECK(index_.IsRegisterPair()); |
| 607 | // UnsafeGet's offset location is a register pair, the low |
| 608 | // part contains the correct offset. |
| 609 | index = index_.ToLow(); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | // We're moving two or three locations to locations that could |
| 614 | // overlap, so we need a parallel move resolver. |
| 615 | InvokeRuntimeCallingConvention calling_convention; |
| 616 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 617 | parallel_move.AddMove(ref_, |
| 618 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 619 | Primitive::kPrimNot, |
| 620 | nullptr); |
| 621 | parallel_move.AddMove(obj_, |
| 622 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 623 | Primitive::kPrimNot, |
| 624 | nullptr); |
| 625 | if (index.IsValid()) { |
| 626 | parallel_move.AddMove(index, |
| 627 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 628 | Primitive::kPrimInt, |
| 629 | nullptr); |
| 630 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 631 | } else { |
| 632 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 633 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 634 | } |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 635 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 636 | CheckEntrypointTypes< |
| 637 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 638 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 639 | |
| 640 | RestoreLiveRegisters(codegen, locations); |
| 641 | __ jmp(GetExitLabel()); |
| 642 | } |
| 643 | |
| 644 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 645 | |
| 646 | private: |
| 647 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 648 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 649 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 650 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 651 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 652 | return static_cast<Register>(i); |
| 653 | } |
| 654 | } |
| 655 | // We shall never fail to find a free caller-save register, as |
| 656 | // there are more than two core caller-save registers on x86 |
| 657 | // (meaning it is possible to find one which is different from |
| 658 | // `ref` and `obj`). |
| 659 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 660 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 661 | UNREACHABLE(); |
| 662 | } |
| 663 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 664 | const Location out_; |
| 665 | const Location ref_; |
| 666 | const Location obj_; |
| 667 | const uint32_t offset_; |
| 668 | // An additional location containing an index to an array. |
| 669 | // Only used for HArrayGet and the UnsafeGetObject & |
| 670 | // UnsafeGetObjectVolatile intrinsics. |
| 671 | const Location index_; |
| 672 | |
| 673 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 674 | }; |
| 675 | |
| 676 | // Slow path generating a read barrier for a GC root. |
| 677 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 678 | public: |
| 679 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 680 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 681 | DCHECK(kEmitCompilerReadBarrier); |
| 682 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 683 | |
| 684 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 685 | LocationSummary* locations = instruction_->GetLocations(); |
| 686 | Register reg_out = out_.AsRegister<Register>(); |
| 687 | DCHECK(locations->CanCall()); |
| 688 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 689 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 690 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 691 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 692 | |
| 693 | __ Bind(GetEntryLabel()); |
| 694 | SaveLiveRegisters(codegen, locations); |
| 695 | |
| 696 | InvokeRuntimeCallingConvention calling_convention; |
| 697 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 698 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 699 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 700 | instruction_, |
| 701 | instruction_->GetDexPc(), |
| 702 | this); |
| 703 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 704 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 705 | |
| 706 | RestoreLiveRegisters(codegen, locations); |
| 707 | __ jmp(GetExitLabel()); |
| 708 | } |
| 709 | |
| 710 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 711 | |
| 712 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 713 | const Location out_; |
| 714 | const Location root_; |
| 715 | |
| 716 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 717 | }; |
| 718 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 719 | #undef __ |
Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 720 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 721 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 722 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 723 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 724 | switch (cond) { |
| 725 | case kCondEQ: return kEqual; |
| 726 | case kCondNE: return kNotEqual; |
| 727 | case kCondLT: return kLess; |
| 728 | case kCondLE: return kLessEqual; |
| 729 | case kCondGT: return kGreater; |
| 730 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 731 | case kCondB: return kBelow; |
| 732 | case kCondBE: return kBelowEqual; |
| 733 | case kCondA: return kAbove; |
| 734 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 735 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 736 | LOG(FATAL) << "Unreachable"; |
| 737 | UNREACHABLE(); |
| 738 | } |
| 739 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 740 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 741 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 742 | switch (cond) { |
| 743 | case kCondEQ: return kEqual; |
| 744 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 745 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 746 | case kCondLT: return kBelow; |
| 747 | case kCondLE: return kBelowEqual; |
| 748 | case kCondGT: return kAbove; |
| 749 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 750 | // Unsigned remain unchanged. |
| 751 | case kCondB: return kBelow; |
| 752 | case kCondBE: return kBelowEqual; |
| 753 | case kCondA: return kAbove; |
| 754 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 755 | } |
| 756 | LOG(FATAL) << "Unreachable"; |
| 757 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 760 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 761 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 765 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 768 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 769 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 770 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 773 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 774 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 775 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 776 | } |
| 777 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 778 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 779 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 780 | return GetFloatingPointSpillSlotSize(); |
| 781 | } |
| 782 | |
| 783 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 784 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 785 | return GetFloatingPointSpillSlotSize(); |
| 786 | } |
| 787 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 788 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 789 | HInstruction* instruction, |
| 790 | uint32_t dex_pc, |
| 791 | SlowPathCode* slow_path) { |
Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 792 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 793 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); |
| 794 | if (EntrypointRequiresStackMap(entrypoint)) { |
| 795 | RecordPcInfo(instruction, dex_pc, slow_path); |
| 796 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 797 | } |
| 798 | |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 799 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, |
| 800 | HInstruction* instruction, |
| 801 | SlowPathCode* slow_path) { |
| 802 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 803 | GenerateInvokeRuntime(entry_point_offset); |
| 804 | } |
| 805 | |
| 806 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { |
Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 807 | __ fs()->call(Address::Absolute(entry_point_offset)); |
| 808 | } |
| 809 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 810 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 811 | const X86InstructionSetFeatures& isa_features, |
| 812 | const CompilerOptions& compiler_options, |
| 813 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 814 | : CodeGenerator(graph, |
| 815 | kNumberOfCpuRegisters, |
| 816 | kNumberOfXmmRegisters, |
| 817 | kNumberOfRegisterPairs, |
| 818 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 819 | arraysize(kCoreCalleeSaves)) |
| 820 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 821 | 0, |
| 822 | compiler_options, |
| 823 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 824 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 825 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 826 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 827 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 828 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 829 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 830 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 831 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 832 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 833 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 834 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 835 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 836 | constant_area_start_(-1), |
| 837 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 838 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 839 | // Use a fake return address register to mimic Quick. |
| 840 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 841 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 842 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 843 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 844 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 845 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 846 | |
| 847 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 848 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 849 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 850 | UpdateBlockedPairRegisters(); |
| 851 | } |
| 852 | |
| 853 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 854 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 855 | X86ManagedRegister current = |
| 856 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 857 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 858 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 859 | blocked_register_pairs_[i] = true; |
| 860 | } |
| 861 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 864 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 865 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 866 | assembler_(codegen->GetAssembler()), |
| 867 | codegen_(codegen) {} |
| 868 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 869 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 870 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 871 | } |
| 872 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 873 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 874 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 875 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 876 | bool skip_overflow_check = |
| 877 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 878 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 879 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 880 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 881 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 882 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 885 | if (HasEmptyFrame()) { |
| 886 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 887 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 888 | |
| 889 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 890 | Register reg = kCoreCalleeSaves[i]; |
| 891 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 892 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 893 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 894 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 898 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 899 | __ subl(ESP, Immediate(adjust)); |
| 900 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 901 | // Save the current method if we need it. Note that we do not |
| 902 | // do this in HCurrentMethod, as the instruction might have been removed |
| 903 | // in the SSA graph. |
| 904 | if (RequiresCurrentMethod()) { |
| 905 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
| 906 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 910 | __ cfi().RememberState(); |
| 911 | if (!HasEmptyFrame()) { |
| 912 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 913 | __ addl(ESP, Immediate(adjust)); |
| 914 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 915 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 916 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 917 | Register reg = kCoreCalleeSaves[i]; |
| 918 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 919 | __ popl(reg); |
| 920 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 921 | __ cfi().Restore(DWARFReg(reg)); |
| 922 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 923 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 924 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 925 | __ ret(); |
| 926 | __ cfi().RestoreState(); |
| 927 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 930 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 931 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 934 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 935 | switch (type) { |
| 936 | case Primitive::kPrimBoolean: |
| 937 | case Primitive::kPrimByte: |
| 938 | case Primitive::kPrimChar: |
| 939 | case Primitive::kPrimShort: |
| 940 | case Primitive::kPrimInt: |
| 941 | case Primitive::kPrimNot: |
| 942 | return Location::RegisterLocation(EAX); |
| 943 | |
| 944 | case Primitive::kPrimLong: |
| 945 | return Location::RegisterPairLocation(EAX, EDX); |
| 946 | |
| 947 | case Primitive::kPrimVoid: |
| 948 | return Location::NoLocation(); |
| 949 | |
| 950 | case Primitive::kPrimDouble: |
| 951 | case Primitive::kPrimFloat: |
| 952 | return Location::FpuRegisterLocation(XMM0); |
| 953 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 954 | |
| 955 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 959 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 960 | } |
| 961 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 962 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 963 | switch (type) { |
| 964 | case Primitive::kPrimBoolean: |
| 965 | case Primitive::kPrimByte: |
| 966 | case Primitive::kPrimChar: |
| 967 | case Primitive::kPrimShort: |
| 968 | case Primitive::kPrimInt: |
| 969 | case Primitive::kPrimNot: { |
| 970 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 971 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 972 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 973 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 974 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 975 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 976 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 977 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 978 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 979 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 980 | uint32_t index = gp_index_; |
| 981 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 982 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 983 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 984 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 985 | calling_convention.GetRegisterPairAt(index)); |
| 986 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 987 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 988 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 993 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 994 | stack_index_++; |
| 995 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 996 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 997 | } else { |
| 998 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1003 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1004 | stack_index_ += 2; |
| 1005 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1006 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1007 | } else { |
| 1008 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1009 | } |
| 1010 | } |
| 1011 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1012 | case Primitive::kPrimVoid: |
| 1013 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1014 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1015 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1016 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1017 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1018 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1019 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1020 | if (source.Equals(destination)) { |
| 1021 | return; |
| 1022 | } |
| 1023 | if (destination.IsRegister()) { |
| 1024 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1025 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1026 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1027 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1028 | } else { |
| 1029 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1030 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1031 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1032 | } else if (destination.IsFpuRegister()) { |
| 1033 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1034 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1035 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1036 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1037 | } else { |
| 1038 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1039 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1040 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1041 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1042 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1043 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1044 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1045 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1046 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1047 | } else if (source.IsConstant()) { |
| 1048 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1049 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1050 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1051 | } else { |
| 1052 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1053 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1054 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1060 | if (source.Equals(destination)) { |
| 1061 | return; |
| 1062 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1063 | if (destination.IsRegisterPair()) { |
| 1064 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1065 | EmitParallelMoves( |
| 1066 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1067 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1068 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1069 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1070 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1071 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1072 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1073 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1074 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1075 | __ psrlq(src_reg, Immediate(32)); |
| 1076 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1077 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1078 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1079 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1080 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1081 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1082 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1083 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1084 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1085 | if (source.IsFpuRegister()) { |
| 1086 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1087 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1088 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1089 | } else if (source.IsRegisterPair()) { |
| 1090 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1091 | // Create stack space for 2 elements. |
| 1092 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1093 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1094 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1095 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1096 | // And remove the temporary stack space we allocated. |
| 1097 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1098 | } else { |
| 1099 | LOG(FATAL) << "Unimplemented"; |
| 1100 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1101 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1102 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1103 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1104 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1105 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1106 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1107 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1108 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1109 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1110 | } else if (source.IsConstant()) { |
| 1111 | HConstant* constant = source.GetConstant(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1112 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); |
| 1113 | int64_t value = GetInt64ValueOf(constant); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1114 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1115 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
| 1116 | Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1117 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1118 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1119 | EmitParallelMoves( |
| 1120 | Location::StackSlot(source.GetStackIndex()), |
| 1121 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1122 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1123 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1124 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1125 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1130 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1131 | DCHECK(location.IsRegister()); |
| 1132 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1133 | } |
| 1134 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1135 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1136 | HParallelMove move(GetGraph()->GetArena()); |
| 1137 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1138 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1139 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1140 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1141 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1142 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1143 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1147 | if (location.IsRegister()) { |
| 1148 | locations->AddTemp(location); |
| 1149 | } else if (location.IsRegisterPair()) { |
| 1150 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1151 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1152 | } else { |
| 1153 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1154 | } |
| 1155 | } |
| 1156 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1157 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1158 | DCHECK(!successor->IsExitBlock()); |
| 1159 | |
| 1160 | HBasicBlock* block = got->GetBlock(); |
| 1161 | HInstruction* previous = got->GetPrevious(); |
| 1162 | |
| 1163 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1164 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1165 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1166 | return; |
| 1167 | } |
| 1168 | |
| 1169 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1170 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1171 | } |
| 1172 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1173 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1177 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1178 | got->SetLocations(nullptr); |
| 1179 | } |
| 1180 | |
| 1181 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1182 | HandleGoto(got, got->GetSuccessor()); |
| 1183 | } |
| 1184 | |
| 1185 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1186 | try_boundary->SetLocations(nullptr); |
| 1187 | } |
| 1188 | |
| 1189 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1190 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1191 | if (!successor->IsExitBlock()) { |
| 1192 | HandleGoto(try_boundary, successor); |
| 1193 | } |
| 1194 | } |
| 1195 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1196 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1197 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1200 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1203 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1205 | LabelType* true_label, |
| 1206 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1207 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1208 | __ j(kUnordered, true_label); |
| 1209 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1210 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1211 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1212 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1215 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1216 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1217 | LabelType* true_label, |
| 1218 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1219 | LocationSummary* locations = cond->GetLocations(); |
| 1220 | Location left = locations->InAt(0); |
| 1221 | Location right = locations->InAt(1); |
| 1222 | IfCondition if_cond = cond->GetCondition(); |
| 1223 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1224 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1225 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1226 | IfCondition true_high_cond = if_cond; |
| 1227 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1228 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1229 | |
| 1230 | // Set the conditions for the test, remembering that == needs to be |
| 1231 | // decided using the low words. |
| 1232 | switch (if_cond) { |
| 1233 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1234 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1235 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1236 | break; |
| 1237 | case kCondLT: |
| 1238 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1239 | break; |
| 1240 | case kCondLE: |
| 1241 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1242 | break; |
| 1243 | case kCondGT: |
| 1244 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1245 | break; |
| 1246 | case kCondGE: |
| 1247 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1248 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1249 | case kCondB: |
| 1250 | false_high_cond = kCondA; |
| 1251 | break; |
| 1252 | case kCondBE: |
| 1253 | true_high_cond = kCondB; |
| 1254 | break; |
| 1255 | case kCondA: |
| 1256 | false_high_cond = kCondB; |
| 1257 | break; |
| 1258 | case kCondAE: |
| 1259 | true_high_cond = kCondA; |
| 1260 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | if (right.IsConstant()) { |
| 1264 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1265 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1266 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1267 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1268 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1270 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1271 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1272 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1273 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1274 | __ j(X86Condition(true_high_cond), true_label); |
| 1275 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1276 | } |
| 1277 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1278 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1279 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1280 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1281 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1282 | |
| 1283 | __ cmpl(left_high, right_high); |
| 1284 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1285 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1286 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1287 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1289 | __ j(X86Condition(true_high_cond), true_label); |
| 1290 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1291 | } |
| 1292 | // Must be equal high, so compare the lows. |
| 1293 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1294 | } else { |
| 1295 | DCHECK(right.IsDoubleStackSlot()); |
| 1296 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1297 | if (if_cond == kCondNE) { |
| 1298 | __ j(X86Condition(true_high_cond), true_label); |
| 1299 | } else if (if_cond == kCondEQ) { |
| 1300 | __ j(X86Condition(false_high_cond), false_label); |
| 1301 | } else { |
| 1302 | __ j(X86Condition(true_high_cond), true_label); |
| 1303 | __ j(X86Condition(false_high_cond), false_label); |
| 1304 | } |
| 1305 | // Must be equal high, so compare the lows. |
| 1306 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1307 | } |
| 1308 | // The last comparison might be unsigned. |
| 1309 | __ j(final_condition, true_label); |
| 1310 | } |
| 1311 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1312 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1313 | Location rhs, |
| 1314 | HInstruction* insn, |
| 1315 | bool is_double) { |
| 1316 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1317 | if (is_double) { |
| 1318 | if (rhs.IsFpuRegister()) { |
| 1319 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1320 | } else if (const_area != nullptr) { |
| 1321 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1322 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1323 | codegen_->LiteralDoubleAddress( |
| 1324 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1325 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1326 | } else { |
| 1327 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1328 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1329 | } |
| 1330 | } else { |
| 1331 | if (rhs.IsFpuRegister()) { |
| 1332 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1333 | } else if (const_area != nullptr) { |
| 1334 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1335 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1336 | codegen_->LiteralFloatAddress( |
| 1337 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1338 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1339 | } else { |
| 1340 | DCHECK(rhs.IsStackSlot()); |
| 1341 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1346 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1347 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1348 | LabelType* true_target_in, |
| 1349 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1350 | // Generated branching requires both targets to be explicit. If either of the |
| 1351 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1352 | LabelType fallthrough_target; |
| 1353 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1354 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1355 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1356 | LocationSummary* locations = condition->GetLocations(); |
| 1357 | Location left = locations->InAt(0); |
| 1358 | Location right = locations->InAt(1); |
| 1359 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1360 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1361 | switch (type) { |
| 1362 | case Primitive::kPrimLong: |
| 1363 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1364 | break; |
| 1365 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1366 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1367 | GenerateFPJumps(condition, true_target, false_target); |
| 1368 | break; |
| 1369 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1370 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1371 | GenerateFPJumps(condition, true_target, false_target); |
| 1372 | break; |
| 1373 | default: |
| 1374 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1375 | } |
| 1376 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1377 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1378 | __ jmp(false_target); |
| 1379 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1380 | |
| 1381 | if (fallthrough_target.IsLinked()) { |
| 1382 | __ Bind(&fallthrough_target); |
| 1383 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | } |
| 1385 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1386 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1387 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1388 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1389 | // conditions if they are materialized due to the complex branching. |
| 1390 | return cond->IsCondition() && |
| 1391 | cond->GetNext() == branch && |
| 1392 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1393 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1394 | } |
| 1395 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1396 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1397 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1398 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1399 | LabelType* true_target, |
| 1400 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1401 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1402 | |
| 1403 | if (true_target == nullptr && false_target == nullptr) { |
| 1404 | // Nothing to do. The code always falls through. |
| 1405 | return; |
| 1406 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1407 | // Constant condition, statically compared against "true" (integer value 1). |
| 1408 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1409 | if (true_target != nullptr) { |
| 1410 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1411 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1412 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1413 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1414 | if (false_target != nullptr) { |
| 1415 | __ jmp(false_target); |
| 1416 | } |
| 1417 | } |
| 1418 | return; |
| 1419 | } |
| 1420 | |
| 1421 | // The following code generates these patterns: |
| 1422 | // (1) true_target == nullptr && false_target != nullptr |
| 1423 | // - opposite condition true => branch to false_target |
| 1424 | // (2) true_target != nullptr && false_target == nullptr |
| 1425 | // - condition true => branch to true_target |
| 1426 | // (3) true_target != nullptr && false_target != nullptr |
| 1427 | // - condition true => branch to true_target |
| 1428 | // - branch to false_target |
| 1429 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1430 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1431 | if (true_target == nullptr) { |
| 1432 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1433 | } else { |
| 1434 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1435 | } |
| 1436 | } else { |
| 1437 | // Materialized condition, compare against 0. |
| 1438 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1439 | if (lhs.IsRegister()) { |
| 1440 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1441 | } else { |
| 1442 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1443 | } |
| 1444 | if (true_target == nullptr) { |
| 1445 | __ j(kEqual, false_target); |
| 1446 | } else { |
| 1447 | __ j(kNotEqual, true_target); |
| 1448 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1449 | } |
| 1450 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1451 | // Condition has not been materialized, use its inputs as the comparison and |
| 1452 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1453 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1454 | |
| 1455 | // If this is a long or FP comparison that has been folded into |
| 1456 | // the HCondition, generate the comparison directly. |
| 1457 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1458 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1459 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1460 | return; |
| 1461 | } |
| 1462 | |
| 1463 | Location lhs = condition->GetLocations()->InAt(0); |
| 1464 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1465 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1466 | codegen_->GenerateIntCompare(lhs, rhs); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1467 | if (true_target == nullptr) { |
| 1468 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1469 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1470 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1471 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1472 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1473 | |
| 1474 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1475 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1476 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1477 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1481 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1482 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1483 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1484 | locations->SetInAt(0, Location::Any()); |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1489 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1490 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1491 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1492 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1493 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1494 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1495 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1499 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1500 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1501 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1502 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1503 | locations->SetInAt(0, Location::Any()); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1508 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1509 | GenerateTestAndBranch<Label>(deoptimize, |
| 1510 | /* condition_input_index */ 0, |
| 1511 | slow_path->GetEntryLabel(), |
| 1512 | /* false_target */ nullptr); |
| 1513 | } |
| 1514 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1515 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1516 | // There are no conditional move instructions for XMMs. |
| 1517 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1518 | return false; |
| 1519 | } |
| 1520 | |
| 1521 | // A FP condition doesn't generate the single CC that we need. |
| 1522 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1523 | HInstruction* condition = select->GetCondition(); |
| 1524 | if (condition->IsCondition()) { |
| 1525 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1526 | if (compare_type == Primitive::kPrimLong || |
| 1527 | Primitive::IsFloatingPointType(compare_type)) { |
| 1528 | return false; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | // We can generate a CMOV for this Select. |
| 1533 | return true; |
| 1534 | } |
| 1535 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1536 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1537 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1538 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1540 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1541 | } else { |
| 1542 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1543 | if (SelectCanUseCMOV(select)) { |
| 1544 | if (select->InputAt(1)->IsConstant()) { |
| 1545 | // Cmov can't handle a constant value. |
| 1546 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1547 | } else { |
| 1548 | locations->SetInAt(1, Location::Any()); |
| 1549 | } |
| 1550 | } else { |
| 1551 | locations->SetInAt(1, Location::Any()); |
| 1552 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1553 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1554 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1555 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1556 | } |
| 1557 | locations->SetOut(Location::SameAsFirstInput()); |
| 1558 | } |
| 1559 | |
| 1560 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1561 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1562 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1563 | if (SelectCanUseCMOV(select)) { |
| 1564 | // If both the condition and the source types are integer, we can generate |
| 1565 | // a CMOV to implement Select. |
| 1566 | |
| 1567 | HInstruction* select_condition = select->GetCondition(); |
| 1568 | Condition cond = kNotEqual; |
| 1569 | |
| 1570 | // Figure out how to test the 'condition'. |
| 1571 | if (select_condition->IsCondition()) { |
| 1572 | HCondition* condition = select_condition->AsCondition(); |
| 1573 | if (!condition->IsEmittedAtUseSite()) { |
| 1574 | // This was a previously materialized condition. |
| 1575 | // Can we use the existing condition code? |
| 1576 | if (AreEflagsSetFrom(condition, select)) { |
| 1577 | // Materialization was the previous instruction. Condition codes are right. |
| 1578 | cond = X86Condition(condition->GetCondition()); |
| 1579 | } else { |
| 1580 | // No, we have to recreate the condition code. |
| 1581 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1582 | __ testl(cond_reg, cond_reg); |
| 1583 | } |
| 1584 | } else { |
| 1585 | // We can't handle FP or long here. |
| 1586 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1587 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1588 | LocationSummary* cond_locations = condition->GetLocations(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1589 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1590 | cond = X86Condition(condition->GetCondition()); |
| 1591 | } |
| 1592 | } else { |
| 1593 | // Must be a boolean condition, which needs to be compared to 0. |
| 1594 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1595 | __ testl(cond_reg, cond_reg); |
| 1596 | } |
| 1597 | |
| 1598 | // If the condition is true, overwrite the output, which already contains false. |
| 1599 | Location false_loc = locations->InAt(0); |
| 1600 | Location true_loc = locations->InAt(1); |
| 1601 | if (select->GetType() == Primitive::kPrimLong) { |
| 1602 | // 64 bit conditional move. |
| 1603 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1604 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1605 | if (true_loc.IsRegisterPair()) { |
| 1606 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1607 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1608 | } else { |
| 1609 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1610 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1611 | } |
| 1612 | } else { |
| 1613 | // 32 bit conditional move. |
| 1614 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1615 | if (true_loc.IsRegister()) { |
| 1616 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1617 | } else { |
| 1618 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1619 | } |
| 1620 | } |
| 1621 | } else { |
| 1622 | NearLabel false_target; |
| 1623 | GenerateTestAndBranch<NearLabel>( |
| 1624 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1625 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1626 | __ Bind(&false_target); |
| 1627 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1630 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1631 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1632 | } |
| 1633 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1634 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1635 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | void CodeGeneratorX86::GenerateNop() { |
| 1639 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1642 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1643 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1644 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1645 | // Handle the long/FP comparisons made in instruction simplification. |
| 1646 | switch (cond->InputAt(0)->GetType()) { |
| 1647 | case Primitive::kPrimLong: { |
| 1648 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1649 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1650 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1651 | locations->SetOut(Location::RequiresRegister()); |
| 1652 | } |
| 1653 | break; |
| 1654 | } |
| 1655 | case Primitive::kPrimFloat: |
| 1656 | case Primitive::kPrimDouble: { |
| 1657 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1658 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1659 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1660 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1661 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1662 | } else { |
| 1663 | locations->SetInAt(1, Location::Any()); |
| 1664 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1665 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1666 | locations->SetOut(Location::RequiresRegister()); |
| 1667 | } |
| 1668 | break; |
| 1669 | } |
| 1670 | default: |
| 1671 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1672 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1673 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1674 | // We need a byte register. |
| 1675 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1676 | } |
| 1677 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1678 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1681 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1682 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1683 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1684 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1685 | |
| 1686 | LocationSummary* locations = cond->GetLocations(); |
| 1687 | Location lhs = locations->InAt(0); |
| 1688 | Location rhs = locations->InAt(1); |
| 1689 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1690 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1691 | |
| 1692 | switch (cond->InputAt(0)->GetType()) { |
| 1693 | default: { |
| 1694 | // Integer case. |
| 1695 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1696 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1697 | __ xorl(reg, reg); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1698 | codegen_->GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1699 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1700 | return; |
| 1701 | } |
| 1702 | case Primitive::kPrimLong: |
| 1703 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1704 | break; |
| 1705 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1706 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1707 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1708 | break; |
| 1709 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1710 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1711 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1712 | break; |
| 1713 | } |
| 1714 | |
| 1715 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1716 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1717 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1718 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1719 | __ Bind(&false_label); |
| 1720 | __ xorl(reg, reg); |
| 1721 | __ jmp(&done_label); |
| 1722 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1723 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1724 | __ Bind(&true_label); |
| 1725 | __ movl(reg, Immediate(1)); |
| 1726 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1730 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1734 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1738 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1742 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1746 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1754 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1777 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1809 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1810 | LocationSummary* locations = |
| 1811 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1812 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1815 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1816 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1819 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1820 | LocationSummary* locations = |
| 1821 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1822 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1823 | } |
| 1824 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1825 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1826 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1829 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1830 | LocationSummary* locations = |
| 1831 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1832 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1833 | } |
| 1834 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1835 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1836 | // Will be generated at use site. |
| 1837 | } |
| 1838 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1839 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1840 | LocationSummary* locations = |
| 1841 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1842 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1843 | } |
| 1844 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1845 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1846 | // Will be generated at use site. |
| 1847 | } |
| 1848 | |
| 1849 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1850 | LocationSummary* locations = |
| 1851 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1852 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1853 | } |
| 1854 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1855 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1856 | // Will be generated at use site. |
| 1857 | } |
| 1858 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1859 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1860 | memory_barrier->SetLocations(nullptr); |
| 1861 | } |
| 1862 | |
| 1863 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1864 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1865 | } |
| 1866 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1867 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1868 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1871 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1872 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1875 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1876 | LocationSummary* locations = |
| 1877 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1878 | switch (ret->InputAt(0)->GetType()) { |
| 1879 | case Primitive::kPrimBoolean: |
| 1880 | case Primitive::kPrimByte: |
| 1881 | case Primitive::kPrimChar: |
| 1882 | case Primitive::kPrimShort: |
| 1883 | case Primitive::kPrimInt: |
| 1884 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1885 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1886 | break; |
| 1887 | |
| 1888 | case Primitive::kPrimLong: |
| 1889 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1890 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1891 | break; |
| 1892 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1893 | case Primitive::kPrimFloat: |
| 1894 | case Primitive::kPrimDouble: |
| 1895 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1896 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1897 | break; |
| 1898 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1899 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1900 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1901 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1904 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1905 | if (kIsDebugBuild) { |
| 1906 | switch (ret->InputAt(0)->GetType()) { |
| 1907 | case Primitive::kPrimBoolean: |
| 1908 | case Primitive::kPrimByte: |
| 1909 | case Primitive::kPrimChar: |
| 1910 | case Primitive::kPrimShort: |
| 1911 | case Primitive::kPrimInt: |
| 1912 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1913 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1914 | break; |
| 1915 | |
| 1916 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1917 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1918 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1919 | break; |
| 1920 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1921 | case Primitive::kPrimFloat: |
| 1922 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1923 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1924 | break; |
| 1925 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1926 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1927 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1928 | } |
| 1929 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1930 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1933 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1934 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1935 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1936 | // the method_idx. |
| 1937 | HandleInvoke(invoke); |
| 1938 | } |
| 1939 | |
| 1940 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1941 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1942 | } |
| 1943 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1944 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1945 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1946 | // art::PrepareForRegisterAllocation. |
| 1947 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1948 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1949 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1950 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1951 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1952 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1953 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1954 | return; |
| 1955 | } |
| 1956 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1957 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1958 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1959 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1960 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1961 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1962 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1963 | } |
| 1964 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1965 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1966 | if (invoke->GetLocations()->Intrinsified()) { |
| 1967 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1968 | intrinsic.Dispatch(invoke); |
| 1969 | return true; |
| 1970 | } |
| 1971 | return false; |
| 1972 | } |
| 1973 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1974 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1975 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1976 | // art::PrepareForRegisterAllocation. |
| 1977 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1978 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1979 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1980 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1981 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1982 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1983 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1984 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1985 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1986 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1990 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1991 | if (intrinsic.TryDispatch(invoke)) { |
| 1992 | return; |
| 1993 | } |
| 1994 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1995 | HandleInvoke(invoke); |
| 1996 | } |
| 1997 | |
| 1998 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1999 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2000 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2003 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2004 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2005 | return; |
| 2006 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2007 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2008 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2009 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2010 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2011 | } |
| 2012 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2013 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2014 | // This call to HandleInvoke allocates a temporary (core) register |
| 2015 | // which is also used to transfer the hidden argument from FP to |
| 2016 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2017 | HandleInvoke(invoke); |
| 2018 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2019 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2023 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2024 | LocationSummary* locations = invoke->GetLocations(); |
| 2025 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2026 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2027 | Location receiver = locations->InAt(0); |
| 2028 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2029 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2030 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2031 | // won't be modified thereafter, before the `call` instruction. |
| 2032 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2033 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2034 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2035 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2036 | if (receiver.IsStackSlot()) { |
| 2037 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2038 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2039 | __ movl(temp, Address(temp, class_offset)); |
| 2040 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2041 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2042 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2043 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2044 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2045 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2046 | // emit a read barrier for the previous class reference load. |
| 2047 | // However this is not required in practice, as this is an |
| 2048 | // intermediate/temporary reference and because the current |
| 2049 | // concurrent copying collector keeps the from-space memory |
| 2050 | // intact/accessible until the end of the marking phase (the |
| 2051 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2052 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2053 | // temp = temp->GetAddressOfIMT() |
| 2054 | __ movl(temp, |
| 2055 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2056 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2057 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2058 | invoke->GetImtIndex(), kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2059 | __ movl(temp, Address(temp, method_offset)); |
| 2060 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2061 | __ call(Address(temp, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2062 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2063 | |
| 2064 | DCHECK(!codegen_->IsLeafMethod()); |
| 2065 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2066 | } |
| 2067 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2068 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2069 | LocationSummary* locations = |
| 2070 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2071 | switch (neg->GetResultType()) { |
| 2072 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2073 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2074 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2075 | locations->SetOut(Location::SameAsFirstInput()); |
| 2076 | break; |
| 2077 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2078 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2079 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2080 | locations->SetOut(Location::SameAsFirstInput()); |
| 2081 | locations->AddTemp(Location::RequiresRegister()); |
| 2082 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2083 | break; |
| 2084 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2085 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2086 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2087 | locations->SetOut(Location::SameAsFirstInput()); |
| 2088 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2089 | break; |
| 2090 | |
| 2091 | default: |
| 2092 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2097 | LocationSummary* locations = neg->GetLocations(); |
| 2098 | Location out = locations->Out(); |
| 2099 | Location in = locations->InAt(0); |
| 2100 | switch (neg->GetResultType()) { |
| 2101 | case Primitive::kPrimInt: |
| 2102 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2103 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2104 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2105 | break; |
| 2106 | |
| 2107 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2108 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2109 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2110 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2111 | // Negation is similar to subtraction from zero. The least |
| 2112 | // significant byte triggers a borrow when it is different from |
| 2113 | // zero; to take it into account, add 1 to the most significant |
| 2114 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2115 | // operation. |
| 2116 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2117 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2118 | break; |
| 2119 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2120 | case Primitive::kPrimFloat: { |
| 2121 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2122 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2123 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2124 | // Implement float negation with an exclusive or with value |
| 2125 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2126 | // single-precision floating-point number). |
| 2127 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2128 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2129 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2130 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2131 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2132 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2133 | case Primitive::kPrimDouble: { |
| 2134 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2135 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2136 | // Implement double negation with an exclusive or with value |
| 2137 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2138 | // a double-precision floating-point number). |
| 2139 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2140 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2141 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2142 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2143 | |
| 2144 | default: |
| 2145 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2146 | } |
| 2147 | } |
| 2148 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2149 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2150 | LocationSummary* locations = |
| 2151 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2152 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2153 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2154 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2155 | locations->SetOut(Location::SameAsFirstInput()); |
| 2156 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2157 | } |
| 2158 | |
| 2159 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2160 | LocationSummary* locations = neg->GetLocations(); |
| 2161 | Location out = locations->Out(); |
| 2162 | DCHECK(locations->InAt(0).Equals(out)); |
| 2163 | |
| 2164 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2165 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2166 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2167 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2168 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2169 | } else { |
| 2170 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2171 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2172 | } |
| 2173 | } |
| 2174 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2175 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2176 | Primitive::Type result_type = conversion->GetResultType(); |
| 2177 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2178 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2179 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2180 | // The float-to-long and double-to-long type conversions rely on a |
| 2181 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2182 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2183 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2184 | && result_type == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2185 | ? LocationSummary::kCallOnMainOnly |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2186 | : LocationSummary::kNoCall; |
| 2187 | LocationSummary* locations = |
| 2188 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2189 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2190 | // The Java language does not allow treating boolean as an integral type but |
| 2191 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2192 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2193 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2194 | case Primitive::kPrimByte: |
| 2195 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2196 | case Primitive::kPrimLong: { |
| 2197 | // Type conversion from long to byte is a result of code transformations. |
| 2198 | HInstruction* input = conversion->InputAt(0); |
| 2199 | Location input_location = input->IsConstant() |
| 2200 | ? Location::ConstantLocation(input->AsConstant()) |
| 2201 | : Location::RegisterPairLocation(EAX, EDX); |
| 2202 | locations->SetInAt(0, input_location); |
| 2203 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2204 | // the validation of the linear scan implementation |
| 2205 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2206 | break; |
| 2207 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2208 | case Primitive::kPrimBoolean: |
| 2209 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2210 | case Primitive::kPrimShort: |
| 2211 | case Primitive::kPrimInt: |
| 2212 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2213 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2214 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2215 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2216 | // the validation of the linear scan implementation |
| 2217 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2218 | break; |
| 2219 | |
| 2220 | default: |
| 2221 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2222 | << " to " << result_type; |
| 2223 | } |
| 2224 | break; |
| 2225 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2226 | case Primitive::kPrimShort: |
| 2227 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2228 | case Primitive::kPrimLong: |
| 2229 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimBoolean: |
| 2231 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimByte: |
| 2233 | case Primitive::kPrimInt: |
| 2234 | case Primitive::kPrimChar: |
| 2235 | // Processing a Dex `int-to-short' instruction. |
| 2236 | locations->SetInAt(0, Location::Any()); |
| 2237 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2238 | break; |
| 2239 | |
| 2240 | default: |
| 2241 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2242 | << " to " << result_type; |
| 2243 | } |
| 2244 | break; |
| 2245 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimInt: |
| 2247 | switch (input_type) { |
| 2248 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2249 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2250 | locations->SetInAt(0, Location::Any()); |
| 2251 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2252 | break; |
| 2253 | |
| 2254 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2255 | // Processing a Dex `float-to-int' instruction. |
| 2256 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2257 | locations->SetOut(Location::RequiresRegister()); |
| 2258 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2259 | break; |
| 2260 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2262 | // Processing a Dex `double-to-int' instruction. |
| 2263 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2264 | locations->SetOut(Location::RequiresRegister()); |
| 2265 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2266 | break; |
| 2267 | |
| 2268 | default: |
| 2269 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2270 | << " to " << result_type; |
| 2271 | } |
| 2272 | break; |
| 2273 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2274 | case Primitive::kPrimLong: |
| 2275 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimBoolean: |
| 2277 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimByte: |
| 2279 | case Primitive::kPrimShort: |
| 2280 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2282 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2283 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2284 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2285 | break; |
| 2286 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2287 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2289 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2290 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2291 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2292 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2293 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2294 | // The runtime helper puts the result in EAX, EDX. |
| 2295 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2296 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2297 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2298 | |
| 2299 | default: |
| 2300 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2301 | << " to " << result_type; |
| 2302 | } |
| 2303 | break; |
| 2304 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2305 | case Primitive::kPrimChar: |
| 2306 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2307 | case Primitive::kPrimLong: |
| 2308 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2309 | case Primitive::kPrimBoolean: |
| 2310 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimByte: |
| 2312 | case Primitive::kPrimShort: |
| 2313 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2314 | // Processing a Dex `int-to-char' instruction. |
| 2315 | locations->SetInAt(0, Location::Any()); |
| 2316 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2317 | break; |
| 2318 | |
| 2319 | default: |
| 2320 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2321 | << " to " << result_type; |
| 2322 | } |
| 2323 | break; |
| 2324 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2325 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2326 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimBoolean: |
| 2328 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimByte: |
| 2330 | case Primitive::kPrimShort: |
| 2331 | case Primitive::kPrimInt: |
| 2332 | case Primitive::kPrimChar: |
| 2333 | // Processing a Dex `int-to-float' instruction. |
| 2334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2335 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2336 | break; |
| 2337 | |
| 2338 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2339 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2340 | locations->SetInAt(0, Location::Any()); |
| 2341 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2342 | break; |
| 2343 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2345 | // Processing a Dex `double-to-float' instruction. |
| 2346 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2347 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2352 | << " to " << result_type; |
| 2353 | }; |
| 2354 | break; |
| 2355 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2357 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimBoolean: |
| 2359 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimByte: |
| 2361 | case Primitive::kPrimShort: |
| 2362 | case Primitive::kPrimInt: |
| 2363 | case Primitive::kPrimChar: |
| 2364 | // Processing a Dex `int-to-double' instruction. |
| 2365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2366 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2367 | break; |
| 2368 | |
| 2369 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2370 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2371 | locations->SetInAt(0, Location::Any()); |
| 2372 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2375 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2376 | // Processing a Dex `float-to-double' instruction. |
| 2377 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2378 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | |
| 2381 | default: |
| 2382 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2383 | << " to " << result_type; |
| 2384 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2389 | << " to " << result_type; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2394 | LocationSummary* locations = conversion->GetLocations(); |
| 2395 | Location out = locations->Out(); |
| 2396 | Location in = locations->InAt(0); |
| 2397 | Primitive::Type result_type = conversion->GetResultType(); |
| 2398 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2399 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2400 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimByte: |
| 2402 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2403 | case Primitive::kPrimLong: |
| 2404 | // Type conversion from long to byte is a result of code transformations. |
| 2405 | if (in.IsRegisterPair()) { |
| 2406 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2407 | } else { |
| 2408 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2409 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2410 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2411 | } |
| 2412 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimBoolean: |
| 2414 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimShort: |
| 2416 | case Primitive::kPrimInt: |
| 2417 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2418 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2419 | if (in.IsRegister()) { |
| 2420 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2421 | } else { |
| 2422 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2423 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2424 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2425 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2426 | break; |
| 2427 | |
| 2428 | default: |
| 2429 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2430 | << " to " << result_type; |
| 2431 | } |
| 2432 | break; |
| 2433 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2434 | case Primitive::kPrimShort: |
| 2435 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2436 | case Primitive::kPrimLong: |
| 2437 | // Type conversion from long to short is a result of code transformations. |
| 2438 | if (in.IsRegisterPair()) { |
| 2439 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2440 | } else if (in.IsDoubleStackSlot()) { |
| 2441 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2442 | } else { |
| 2443 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2444 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2445 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2446 | } |
| 2447 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimBoolean: |
| 2449 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2450 | case Primitive::kPrimByte: |
| 2451 | case Primitive::kPrimInt: |
| 2452 | case Primitive::kPrimChar: |
| 2453 | // Processing a Dex `int-to-short' instruction. |
| 2454 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2455 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2456 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2457 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2458 | } else { |
| 2459 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2460 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2461 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2462 | } |
| 2463 | break; |
| 2464 | |
| 2465 | default: |
| 2466 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2467 | << " to " << result_type; |
| 2468 | } |
| 2469 | break; |
| 2470 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2471 | case Primitive::kPrimInt: |
| 2472 | switch (input_type) { |
| 2473 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2474 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2475 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2476 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2477 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2478 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2479 | } else { |
| 2480 | DCHECK(in.IsConstant()); |
| 2481 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2482 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2483 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2484 | } |
| 2485 | break; |
| 2486 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimFloat: { |
| 2488 | // Processing a Dex `float-to-int' instruction. |
| 2489 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2490 | Register output = out.AsRegister<Register>(); |
| 2491 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2492 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2493 | |
| 2494 | __ movl(output, Immediate(kPrimIntMax)); |
| 2495 | // temp = int-to-float(output) |
| 2496 | __ cvtsi2ss(temp, output); |
| 2497 | // if input >= temp goto done |
| 2498 | __ comiss(input, temp); |
| 2499 | __ j(kAboveEqual, &done); |
| 2500 | // if input == NaN goto nan |
| 2501 | __ j(kUnordered, &nan); |
| 2502 | // output = float-to-int-truncate(input) |
| 2503 | __ cvttss2si(output, input); |
| 2504 | __ jmp(&done); |
| 2505 | __ Bind(&nan); |
| 2506 | // output = 0 |
| 2507 | __ xorl(output, output); |
| 2508 | __ Bind(&done); |
| 2509 | break; |
| 2510 | } |
| 2511 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2512 | case Primitive::kPrimDouble: { |
| 2513 | // Processing a Dex `double-to-int' instruction. |
| 2514 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2515 | Register output = out.AsRegister<Register>(); |
| 2516 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2517 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2518 | |
| 2519 | __ movl(output, Immediate(kPrimIntMax)); |
| 2520 | // temp = int-to-double(output) |
| 2521 | __ cvtsi2sd(temp, output); |
| 2522 | // if input >= temp goto done |
| 2523 | __ comisd(input, temp); |
| 2524 | __ j(kAboveEqual, &done); |
| 2525 | // if input == NaN goto nan |
| 2526 | __ j(kUnordered, &nan); |
| 2527 | // output = double-to-int-truncate(input) |
| 2528 | __ cvttsd2si(output, input); |
| 2529 | __ jmp(&done); |
| 2530 | __ Bind(&nan); |
| 2531 | // output = 0 |
| 2532 | __ xorl(output, output); |
| 2533 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2534 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2535 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2536 | |
| 2537 | default: |
| 2538 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2539 | << " to " << result_type; |
| 2540 | } |
| 2541 | break; |
| 2542 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2543 | case Primitive::kPrimLong: |
| 2544 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimBoolean: |
| 2546 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2547 | case Primitive::kPrimByte: |
| 2548 | case Primitive::kPrimShort: |
| 2549 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2551 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2552 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2553 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2554 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2555 | __ cdq(); |
| 2556 | break; |
| 2557 | |
| 2558 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2559 | // Processing a Dex `float-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2560 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2561 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2565 | // Processing a Dex `double-to-long' instruction. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2566 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2567 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2568 | break; |
| 2569 | |
| 2570 | default: |
| 2571 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2572 | << " to " << result_type; |
| 2573 | } |
| 2574 | break; |
| 2575 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2576 | case Primitive::kPrimChar: |
| 2577 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2578 | case Primitive::kPrimLong: |
| 2579 | // Type conversion from long to short is a result of code transformations. |
| 2580 | if (in.IsRegisterPair()) { |
| 2581 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2582 | } else if (in.IsDoubleStackSlot()) { |
| 2583 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2584 | } else { |
| 2585 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2586 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2587 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2588 | } |
| 2589 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimBoolean: |
| 2591 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimByte: |
| 2593 | case Primitive::kPrimShort: |
| 2594 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2595 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2596 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2597 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2598 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2600 | } else { |
| 2601 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2602 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2603 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2604 | } |
| 2605 | break; |
| 2606 | |
| 2607 | default: |
| 2608 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2609 | << " to " << result_type; |
| 2610 | } |
| 2611 | break; |
| 2612 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2614 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2615 | case Primitive::kPrimBoolean: |
| 2616 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2617 | case Primitive::kPrimByte: |
| 2618 | case Primitive::kPrimShort: |
| 2619 | case Primitive::kPrimInt: |
| 2620 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2621 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2622 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2623 | break; |
| 2624 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2625 | case Primitive::kPrimLong: { |
| 2626 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2627 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2628 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2629 | // Create stack space for the call to |
| 2630 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2631 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2632 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2633 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2634 | __ subl(ESP, Immediate(adjustment)); |
| 2635 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2636 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2637 | // Load the value to the FP stack, using temporaries if needed. |
| 2638 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2639 | |
| 2640 | if (out.IsStackSlot()) { |
| 2641 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2642 | } else { |
| 2643 | __ fstps(Address(ESP, 0)); |
| 2644 | Location stack_temp = Location::StackSlot(0); |
| 2645 | codegen_->Move32(out, stack_temp); |
| 2646 | } |
| 2647 | |
| 2648 | // Remove the temporary stack space we allocated. |
| 2649 | if (adjustment != 0) { |
| 2650 | __ addl(ESP, Immediate(adjustment)); |
| 2651 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2652 | break; |
| 2653 | } |
| 2654 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2656 | // Processing a Dex `double-to-float' instruction. |
| 2657 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2658 | break; |
| 2659 | |
| 2660 | default: |
| 2661 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2662 | << " to " << result_type; |
| 2663 | }; |
| 2664 | break; |
| 2665 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2668 | case Primitive::kPrimBoolean: |
| 2669 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2670 | case Primitive::kPrimByte: |
| 2671 | case Primitive::kPrimShort: |
| 2672 | case Primitive::kPrimInt: |
| 2673 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2674 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2675 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 | break; |
| 2677 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimLong: { |
| 2679 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2680 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2681 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2682 | // Create stack space for the call to |
| 2683 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2684 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2685 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2686 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2687 | __ subl(ESP, Immediate(adjustment)); |
| 2688 | } |
| 2689 | |
| 2690 | // Load the value to the FP stack, using temporaries if needed. |
| 2691 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2692 | |
| 2693 | if (out.IsDoubleStackSlot()) { |
| 2694 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2695 | } else { |
| 2696 | __ fstpl(Address(ESP, 0)); |
| 2697 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2698 | codegen_->Move64(out, stack_temp); |
| 2699 | } |
| 2700 | |
| 2701 | // Remove the temporary stack space we allocated. |
| 2702 | if (adjustment != 0) { |
| 2703 | __ addl(ESP, Immediate(adjustment)); |
| 2704 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2705 | break; |
| 2706 | } |
| 2707 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2708 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2709 | // Processing a Dex `float-to-double' instruction. |
| 2710 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2711 | break; |
| 2712 | |
| 2713 | default: |
| 2714 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2715 | << " to " << result_type; |
| 2716 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2717 | break; |
| 2718 | |
| 2719 | default: |
| 2720 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2721 | << " to " << result_type; |
| 2722 | } |
| 2723 | } |
| 2724 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2725 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2726 | LocationSummary* locations = |
| 2727 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2728 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2729 | case Primitive::kPrimInt: { |
| 2730 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2731 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2732 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2733 | break; |
| 2734 | } |
| 2735 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2736 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2737 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2738 | locations->SetInAt(1, Location::Any()); |
| 2739 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2740 | break; |
| 2741 | } |
| 2742 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2743 | case Primitive::kPrimFloat: |
| 2744 | case Primitive::kPrimDouble: { |
| 2745 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2746 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2747 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2748 | } else if (add->InputAt(1)->IsConstant()) { |
| 2749 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2750 | } else { |
| 2751 | locations->SetInAt(1, Location::Any()); |
| 2752 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2753 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2754 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2755 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2756 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2757 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2758 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2759 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2760 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2764 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2765 | Location first = locations->InAt(0); |
| 2766 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2767 | Location out = locations->Out(); |
| 2768 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2770 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2771 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2772 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2773 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2774 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2775 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2776 | } else { |
| 2777 | __ leal(out.AsRegister<Register>(), Address( |
| 2778 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2779 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2780 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2781 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2782 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2783 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2784 | } else { |
| 2785 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2786 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2787 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2788 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2789 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2790 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2791 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2795 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2796 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2797 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2798 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2799 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2800 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2801 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2802 | } else { |
| 2803 | DCHECK(second.IsConstant()) << second; |
| 2804 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2805 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2806 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2807 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2808 | break; |
| 2809 | } |
| 2810 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2811 | case Primitive::kPrimFloat: { |
| 2812 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2813 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2814 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2815 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2816 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2817 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2818 | codegen_->LiteralFloatAddress( |
| 2819 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2820 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2821 | } else { |
| 2822 | DCHECK(second.IsStackSlot()); |
| 2823 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2824 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2825 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | case Primitive::kPrimDouble: { |
| 2829 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2830 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2831 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2832 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2833 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2834 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2835 | codegen_->LiteralDoubleAddress( |
| 2836 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2837 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2838 | } else { |
| 2839 | DCHECK(second.IsDoubleStackSlot()); |
| 2840 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2841 | } |
| 2842 | break; |
| 2843 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2844 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2845 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2846 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2850 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2851 | LocationSummary* locations = |
| 2852 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2853 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2854 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2855 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2857 | locations->SetInAt(1, Location::Any()); |
| 2858 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2859 | break; |
| 2860 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2861 | case Primitive::kPrimFloat: |
| 2862 | case Primitive::kPrimDouble: { |
| 2863 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2864 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2865 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2866 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2867 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2868 | } else { |
| 2869 | locations->SetInAt(1, Location::Any()); |
| 2870 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2871 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2872 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2873 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2874 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2875 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2876 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2877 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2881 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2882 | Location first = locations->InAt(0); |
| 2883 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2884 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2885 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2886 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2887 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2888 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2889 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2890 | __ subl(first.AsRegister<Register>(), |
| 2891 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2892 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2893 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2894 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2895 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2899 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2900 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2901 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2902 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2903 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2904 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2905 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2906 | } else { |
| 2907 | DCHECK(second.IsConstant()) << second; |
| 2908 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2909 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2910 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2911 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2912 | break; |
| 2913 | } |
| 2914 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2915 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2916 | if (second.IsFpuRegister()) { |
| 2917 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2918 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2919 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2920 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2921 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2922 | codegen_->LiteralFloatAddress( |
| 2923 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2924 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2925 | } else { |
| 2926 | DCHECK(second.IsStackSlot()); |
| 2927 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2928 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2929 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2933 | if (second.IsFpuRegister()) { |
| 2934 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2935 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2936 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2937 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2938 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2939 | codegen_->LiteralDoubleAddress( |
| 2940 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2941 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2942 | } else { |
| 2943 | DCHECK(second.IsDoubleStackSlot()); |
| 2944 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2945 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2946 | break; |
| 2947 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2948 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2949 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2950 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2954 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2955 | LocationSummary* locations = |
| 2956 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2957 | switch (mul->GetResultType()) { |
| 2958 | case Primitive::kPrimInt: |
| 2959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2960 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2961 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2962 | // Can use 3 operand multiply. |
| 2963 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2964 | } else { |
| 2965 | locations->SetOut(Location::SameAsFirstInput()); |
| 2966 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2967 | break; |
| 2968 | case Primitive::kPrimLong: { |
| 2969 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2970 | locations->SetInAt(1, Location::Any()); |
| 2971 | locations->SetOut(Location::SameAsFirstInput()); |
| 2972 | // Needed for imul on 32bits with 64bits output. |
| 2973 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2974 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2975 | break; |
| 2976 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2977 | case Primitive::kPrimFloat: |
| 2978 | case Primitive::kPrimDouble: { |
| 2979 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2980 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2981 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2982 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2983 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2984 | } else { |
| 2985 | locations->SetInAt(1, Location::Any()); |
| 2986 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2987 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2988 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2989 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2990 | |
| 2991 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2992 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2997 | LocationSummary* locations = mul->GetLocations(); |
| 2998 | Location first = locations->InAt(0); |
| 2999 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3000 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3001 | |
| 3002 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3003 | case Primitive::kPrimInt: |
| 3004 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3005 | // problems where the output may not be the same as the first operand. |
| 3006 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3007 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3008 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3009 | } else if (second.IsRegister()) { |
| 3010 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3011 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3012 | } else { |
| 3013 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3014 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3015 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3016 | } |
| 3017 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3018 | |
| 3019 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3020 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3021 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3022 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3023 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3024 | |
| 3025 | DCHECK_EQ(EAX, eax); |
| 3026 | DCHECK_EQ(EDX, edx); |
| 3027 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3028 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3029 | // output: in1 |
| 3030 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3031 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3032 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3033 | if (second.IsConstant()) { |
| 3034 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3035 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3036 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3037 | int32_t low_value = Low32Bits(value); |
| 3038 | int32_t high_value = High32Bits(value); |
| 3039 | Immediate low(low_value); |
| 3040 | Immediate high(high_value); |
| 3041 | |
| 3042 | __ movl(eax, high); |
| 3043 | // eax <- in1.lo * in2.hi |
| 3044 | __ imull(eax, in1_lo); |
| 3045 | // in1.hi <- in1.hi * in2.lo |
| 3046 | __ imull(in1_hi, low); |
| 3047 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3048 | __ addl(in1_hi, eax); |
| 3049 | // move in2_lo to eax to prepare for double precision |
| 3050 | __ movl(eax, low); |
| 3051 | // edx:eax <- in1.lo * in2.lo |
| 3052 | __ mull(in1_lo); |
| 3053 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3054 | __ addl(in1_hi, edx); |
| 3055 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3056 | __ movl(in1_lo, eax); |
| 3057 | } else if (second.IsRegisterPair()) { |
| 3058 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3059 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3060 | |
| 3061 | __ movl(eax, in2_hi); |
| 3062 | // eax <- in1.lo * in2.hi |
| 3063 | __ imull(eax, in1_lo); |
| 3064 | // in1.hi <- in1.hi * in2.lo |
| 3065 | __ imull(in1_hi, in2_lo); |
| 3066 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3067 | __ addl(in1_hi, eax); |
| 3068 | // move in1_lo to eax to prepare for double precision |
| 3069 | __ movl(eax, in1_lo); |
| 3070 | // edx:eax <- in1.lo * in2.lo |
| 3071 | __ mull(in2_lo); |
| 3072 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3073 | __ addl(in1_hi, edx); |
| 3074 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3075 | __ movl(in1_lo, eax); |
| 3076 | } else { |
| 3077 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3078 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3079 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3080 | |
| 3081 | __ movl(eax, in2_hi); |
| 3082 | // eax <- in1.lo * in2.hi |
| 3083 | __ imull(eax, in1_lo); |
| 3084 | // in1.hi <- in1.hi * in2.lo |
| 3085 | __ imull(in1_hi, in2_lo); |
| 3086 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3087 | __ addl(in1_hi, eax); |
| 3088 | // move in1_lo to eax to prepare for double precision |
| 3089 | __ movl(eax, in1_lo); |
| 3090 | // edx:eax <- in1.lo * in2.lo |
| 3091 | __ mull(in2_lo); |
| 3092 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3093 | __ addl(in1_hi, edx); |
| 3094 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3095 | __ movl(in1_lo, eax); |
| 3096 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3097 | |
| 3098 | break; |
| 3099 | } |
| 3100 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3101 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3102 | DCHECK(first.Equals(locations->Out())); |
| 3103 | if (second.IsFpuRegister()) { |
| 3104 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3105 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3106 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3107 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3108 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3109 | codegen_->LiteralFloatAddress( |
| 3110 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3111 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3112 | } else { |
| 3113 | DCHECK(second.IsStackSlot()); |
| 3114 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3115 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3116 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3120 | DCHECK(first.Equals(locations->Out())); |
| 3121 | if (second.IsFpuRegister()) { |
| 3122 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3123 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3124 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3125 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3126 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3127 | codegen_->LiteralDoubleAddress( |
| 3128 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3129 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3130 | } else { |
| 3131 | DCHECK(second.IsDoubleStackSlot()); |
| 3132 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3133 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3134 | break; |
| 3135 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3136 | |
| 3137 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3138 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3139 | } |
| 3140 | } |
| 3141 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3142 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3143 | uint32_t temp_offset, |
| 3144 | uint32_t stack_adjustment, |
| 3145 | bool is_fp, |
| 3146 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3147 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3148 | DCHECK(!is_wide); |
| 3149 | if (is_fp) { |
| 3150 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3151 | } else { |
| 3152 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3153 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3154 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3155 | DCHECK(is_wide); |
| 3156 | if (is_fp) { |
| 3157 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3158 | } else { |
| 3159 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3160 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3161 | } else { |
| 3162 | // 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] | 3163 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3164 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3165 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3166 | if (is_fp) { |
| 3167 | __ flds(Address(ESP, temp_offset)); |
| 3168 | } else { |
| 3169 | __ filds(Address(ESP, temp_offset)); |
| 3170 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3171 | } else { |
| 3172 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3173 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3174 | if (is_fp) { |
| 3175 | __ fldl(Address(ESP, temp_offset)); |
| 3176 | } else { |
| 3177 | __ fildl(Address(ESP, temp_offset)); |
| 3178 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3184 | Primitive::Type type = rem->GetResultType(); |
| 3185 | bool is_float = type == Primitive::kPrimFloat; |
| 3186 | size_t elem_size = Primitive::ComponentSize(type); |
| 3187 | LocationSummary* locations = rem->GetLocations(); |
| 3188 | Location first = locations->InAt(0); |
| 3189 | Location second = locations->InAt(1); |
| 3190 | Location out = locations->Out(); |
| 3191 | |
| 3192 | // Create stack space for 2 elements. |
| 3193 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3194 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3195 | |
| 3196 | // 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] | 3197 | const bool is_wide = !is_float; |
| 3198 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3199 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3200 | |
| 3201 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3202 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3203 | __ Bind(&retry); |
| 3204 | __ fprem(); |
| 3205 | |
| 3206 | // Move FP status to AX. |
| 3207 | __ fstsw(); |
| 3208 | |
| 3209 | // And see if the argument reduction is complete. This is signaled by the |
| 3210 | // C2 FPU flag bit set to 0. |
| 3211 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3212 | __ j(kNotEqual, &retry); |
| 3213 | |
| 3214 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3215 | // Store FP top of stack to real stack. |
| 3216 | if (is_float) { |
| 3217 | __ fsts(Address(ESP, 0)); |
| 3218 | } else { |
| 3219 | __ fstl(Address(ESP, 0)); |
| 3220 | } |
| 3221 | |
| 3222 | // Pop the 2 items from the FP stack. |
| 3223 | __ fucompp(); |
| 3224 | |
| 3225 | // Load the value from the stack into an XMM register. |
| 3226 | DCHECK(out.IsFpuRegister()) << out; |
| 3227 | if (is_float) { |
| 3228 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3229 | } else { |
| 3230 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3231 | } |
| 3232 | |
| 3233 | // And remove the temporary stack space we allocated. |
| 3234 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3235 | } |
| 3236 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3237 | |
| 3238 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3239 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3240 | |
| 3241 | LocationSummary* locations = instruction->GetLocations(); |
| 3242 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3243 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3244 | |
| 3245 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3246 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3247 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3248 | |
| 3249 | DCHECK(imm == 1 || imm == -1); |
| 3250 | |
| 3251 | if (instruction->IsRem()) { |
| 3252 | __ xorl(out_register, out_register); |
| 3253 | } else { |
| 3254 | __ movl(out_register, input_register); |
| 3255 | if (imm == -1) { |
| 3256 | __ negl(out_register); |
| 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3262 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3263 | LocationSummary* locations = instruction->GetLocations(); |
| 3264 | |
| 3265 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3266 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3267 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3268 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3269 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3270 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3271 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3272 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3273 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3274 | __ testl(input_register, input_register); |
| 3275 | __ cmovl(kGreaterEqual, num, input_register); |
| 3276 | int shift = CTZ(imm); |
| 3277 | __ sarl(num, Immediate(shift)); |
| 3278 | |
| 3279 | if (imm < 0) { |
| 3280 | __ negl(num); |
| 3281 | } |
| 3282 | |
| 3283 | __ movl(out_register, num); |
| 3284 | } |
| 3285 | |
| 3286 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3287 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3288 | |
| 3289 | LocationSummary* locations = instruction->GetLocations(); |
| 3290 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3291 | |
| 3292 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3293 | Register out = locations->Out().AsRegister<Register>(); |
| 3294 | Register num; |
| 3295 | Register edx; |
| 3296 | |
| 3297 | if (instruction->IsDiv()) { |
| 3298 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3299 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3300 | } else { |
| 3301 | edx = locations->Out().AsRegister<Register>(); |
| 3302 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3303 | } |
| 3304 | |
| 3305 | DCHECK_EQ(EAX, eax); |
| 3306 | DCHECK_EQ(EDX, edx); |
| 3307 | if (instruction->IsDiv()) { |
| 3308 | DCHECK_EQ(EAX, out); |
| 3309 | } else { |
| 3310 | DCHECK_EQ(EDX, out); |
| 3311 | } |
| 3312 | |
| 3313 | int64_t magic; |
| 3314 | int shift; |
| 3315 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3316 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3317 | // Save the numerator. |
| 3318 | __ movl(num, eax); |
| 3319 | |
| 3320 | // EAX = magic |
| 3321 | __ movl(eax, Immediate(magic)); |
| 3322 | |
| 3323 | // EDX:EAX = magic * numerator |
| 3324 | __ imull(num); |
| 3325 | |
| 3326 | if (imm > 0 && magic < 0) { |
| 3327 | // EDX += num |
| 3328 | __ addl(edx, num); |
| 3329 | } else if (imm < 0 && magic > 0) { |
| 3330 | __ subl(edx, num); |
| 3331 | } |
| 3332 | |
| 3333 | // Shift if needed. |
| 3334 | if (shift != 0) { |
| 3335 | __ sarl(edx, Immediate(shift)); |
| 3336 | } |
| 3337 | |
| 3338 | // EDX += 1 if EDX < 0 |
| 3339 | __ movl(eax, edx); |
| 3340 | __ shrl(edx, Immediate(31)); |
| 3341 | __ addl(edx, eax); |
| 3342 | |
| 3343 | if (instruction->IsRem()) { |
| 3344 | __ movl(eax, num); |
| 3345 | __ imull(edx, Immediate(imm)); |
| 3346 | __ subl(eax, edx); |
| 3347 | __ movl(edx, eax); |
| 3348 | } else { |
| 3349 | __ movl(eax, edx); |
| 3350 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3351 | } |
| 3352 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3353 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3354 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3355 | |
| 3356 | LocationSummary* locations = instruction->GetLocations(); |
| 3357 | Location out = locations->Out(); |
| 3358 | Location first = locations->InAt(0); |
| 3359 | Location second = locations->InAt(1); |
| 3360 | bool is_div = instruction->IsDiv(); |
| 3361 | |
| 3362 | switch (instruction->GetResultType()) { |
| 3363 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3364 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3365 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3366 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3367 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3368 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3369 | |
| 3370 | if (imm == 0) { |
| 3371 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3372 | } else if (imm == 1 || imm == -1) { |
| 3373 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3374 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3375 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3376 | } else { |
| 3377 | DCHECK(imm <= -2 || imm >= 2); |
| 3378 | GenerateDivRemWithAnyConstant(instruction); |
| 3379 | } |
| 3380 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3381 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3382 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3383 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3384 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3385 | Register second_reg = second.AsRegister<Register>(); |
| 3386 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3387 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3388 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3389 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3390 | __ cmpl(second_reg, Immediate(-1)); |
| 3391 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3392 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3393 | // edx:eax <- sign-extended of eax |
| 3394 | __ cdq(); |
| 3395 | // eax = quotient, edx = remainder |
| 3396 | __ idivl(second_reg); |
| 3397 | __ Bind(slow_path->GetExitLabel()); |
| 3398 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3399 | break; |
| 3400 | } |
| 3401 | |
| 3402 | case Primitive::kPrimLong: { |
| 3403 | InvokeRuntimeCallingConvention calling_convention; |
| 3404 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3405 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3406 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3407 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3408 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3409 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3410 | |
| 3411 | if (is_div) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3412 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3413 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3414 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3415 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3416 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3417 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3418 | break; |
| 3419 | } |
| 3420 | |
| 3421 | default: |
| 3422 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3423 | } |
| 3424 | } |
| 3425 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3426 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3427 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3428 | ? LocationSummary::kCallOnMainOnly |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3429 | : LocationSummary::kNoCall; |
| 3430 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3431 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3432 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3433 | case Primitive::kPrimInt: { |
| 3434 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3435 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3436 | locations->SetOut(Location::SameAsFirstInput()); |
| 3437 | // Intel uses edx:eax as the dividend. |
| 3438 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3439 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3440 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3441 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3442 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3443 | locations->AddTemp(Location::RequiresRegister()); |
| 3444 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3445 | break; |
| 3446 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3447 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3448 | InvokeRuntimeCallingConvention calling_convention; |
| 3449 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3450 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3451 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3452 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3453 | // Runtime helper puts the result in EAX, EDX. |
| 3454 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3455 | break; |
| 3456 | } |
| 3457 | case Primitive::kPrimFloat: |
| 3458 | case Primitive::kPrimDouble: { |
| 3459 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3460 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3461 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3462 | } else if (div->InputAt(1)->IsConstant()) { |
| 3463 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3464 | } else { |
| 3465 | locations->SetInAt(1, Location::Any()); |
| 3466 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3467 | locations->SetOut(Location::SameAsFirstInput()); |
| 3468 | break; |
| 3469 | } |
| 3470 | |
| 3471 | default: |
| 3472 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3477 | LocationSummary* locations = div->GetLocations(); |
| 3478 | Location first = locations->InAt(0); |
| 3479 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3480 | |
| 3481 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3482 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3483 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3484 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3489 | if (second.IsFpuRegister()) { |
| 3490 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3491 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3492 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3493 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3494 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3495 | codegen_->LiteralFloatAddress( |
| 3496 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3497 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3498 | } else { |
| 3499 | DCHECK(second.IsStackSlot()); |
| 3500 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3501 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | |
| 3505 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3506 | if (second.IsFpuRegister()) { |
| 3507 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3508 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3509 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3510 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3511 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3512 | codegen_->LiteralDoubleAddress( |
| 3513 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3514 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3515 | } else { |
| 3516 | DCHECK(second.IsDoubleStackSlot()); |
| 3517 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3518 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3519 | break; |
| 3520 | } |
| 3521 | |
| 3522 | default: |
| 3523 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3524 | } |
| 3525 | } |
| 3526 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3527 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3528 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3529 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3530 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3531 | ? LocationSummary::kCallOnMainOnly |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3532 | : LocationSummary::kNoCall; |
| 3533 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3534 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3535 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | case Primitive::kPrimInt: { |
| 3537 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3538 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3539 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3540 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3541 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3542 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3543 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3544 | locations->AddTemp(Location::RequiresRegister()); |
| 3545 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3546 | break; |
| 3547 | } |
| 3548 | case Primitive::kPrimLong: { |
| 3549 | InvokeRuntimeCallingConvention calling_convention; |
| 3550 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3551 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3552 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3553 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3554 | // Runtime helper puts the result in EAX, EDX. |
| 3555 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3556 | break; |
| 3557 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3558 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3559 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3560 | locations->SetInAt(0, Location::Any()); |
| 3561 | locations->SetInAt(1, Location::Any()); |
| 3562 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3563 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3564 | break; |
| 3565 | } |
| 3566 | |
| 3567 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3568 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3573 | Primitive::Type type = rem->GetResultType(); |
| 3574 | switch (type) { |
| 3575 | case Primitive::kPrimInt: |
| 3576 | case Primitive::kPrimLong: { |
| 3577 | GenerateDivRemIntegral(rem); |
| 3578 | break; |
| 3579 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3580 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3581 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3582 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3583 | break; |
| 3584 | } |
| 3585 | default: |
| 3586 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3587 | } |
| 3588 | } |
| 3589 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3590 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 3591 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3592 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3593 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3594 | case Primitive::kPrimByte: |
| 3595 | case Primitive::kPrimChar: |
| 3596 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3597 | case Primitive::kPrimInt: { |
| 3598 | locations->SetInAt(0, Location::Any()); |
| 3599 | break; |
| 3600 | } |
| 3601 | case Primitive::kPrimLong: { |
| 3602 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3603 | if (!instruction->IsConstant()) { |
| 3604 | locations->AddTemp(Location::RequiresRegister()); |
| 3605 | } |
| 3606 | break; |
| 3607 | } |
| 3608 | default: |
| 3609 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3610 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3614 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3615 | codegen_->AddSlowPath(slow_path); |
| 3616 | |
| 3617 | LocationSummary* locations = instruction->GetLocations(); |
| 3618 | Location value = locations->InAt(0); |
| 3619 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3620 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3621 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3622 | case Primitive::kPrimByte: |
| 3623 | case Primitive::kPrimChar: |
| 3624 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3625 | case Primitive::kPrimInt: { |
| 3626 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3627 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3628 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3629 | } else if (value.IsStackSlot()) { |
| 3630 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3631 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3632 | } else { |
| 3633 | DCHECK(value.IsConstant()) << value; |
| 3634 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 3635 | __ jmp(slow_path->GetEntryLabel()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3636 | } |
| 3637 | } |
| 3638 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3639 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3640 | case Primitive::kPrimLong: { |
| 3641 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3642 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3643 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3644 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3645 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3646 | } else { |
| 3647 | DCHECK(value.IsConstant()) << value; |
| 3648 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3649 | __ jmp(slow_path->GetEntryLabel()); |
| 3650 | } |
| 3651 | } |
| 3652 | break; |
| 3653 | } |
| 3654 | default: |
| 3655 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3656 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3657 | } |
| 3658 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3659 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3660 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3661 | |
| 3662 | LocationSummary* locations = |
| 3663 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3664 | |
| 3665 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3666 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3667 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3668 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3669 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3670 | // The shift count needs to be in CL or a constant. |
| 3671 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3672 | locations->SetOut(Location::SameAsFirstInput()); |
| 3673 | break; |
| 3674 | } |
| 3675 | default: |
| 3676 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3681 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3682 | |
| 3683 | LocationSummary* locations = op->GetLocations(); |
| 3684 | Location first = locations->InAt(0); |
| 3685 | Location second = locations->InAt(1); |
| 3686 | DCHECK(first.Equals(locations->Out())); |
| 3687 | |
| 3688 | switch (op->GetResultType()) { |
| 3689 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3690 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3691 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3692 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3693 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3694 | DCHECK_EQ(ECX, second_reg); |
| 3695 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3696 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3697 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3698 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3699 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3700 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3701 | } |
| 3702 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3703 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3704 | if (shift == 0) { |
| 3705 | return; |
| 3706 | } |
| 3707 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3708 | if (op->IsShl()) { |
| 3709 | __ shll(first_reg, imm); |
| 3710 | } else if (op->IsShr()) { |
| 3711 | __ sarl(first_reg, imm); |
| 3712 | } else { |
| 3713 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3714 | } |
| 3715 | } |
| 3716 | break; |
| 3717 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3718 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3719 | if (second.IsRegister()) { |
| 3720 | Register second_reg = second.AsRegister<Register>(); |
| 3721 | DCHECK_EQ(ECX, second_reg); |
| 3722 | if (op->IsShl()) { |
| 3723 | GenerateShlLong(first, second_reg); |
| 3724 | } else if (op->IsShr()) { |
| 3725 | GenerateShrLong(first, second_reg); |
| 3726 | } else { |
| 3727 | GenerateUShrLong(first, second_reg); |
| 3728 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3729 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3730 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3731 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3732 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3733 | if (shift != 0) { |
| 3734 | if (op->IsShl()) { |
| 3735 | GenerateShlLong(first, shift); |
| 3736 | } else if (op->IsShr()) { |
| 3737 | GenerateShrLong(first, shift); |
| 3738 | } else { |
| 3739 | GenerateUShrLong(first, shift); |
| 3740 | } |
| 3741 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3742 | } |
| 3743 | break; |
| 3744 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3745 | default: |
| 3746 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3747 | } |
| 3748 | } |
| 3749 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3750 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3751 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3752 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3753 | if (shift == 1) { |
| 3754 | // This is just an addition. |
| 3755 | __ addl(low, low); |
| 3756 | __ adcl(high, high); |
| 3757 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3758 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3759 | codegen_->EmitParallelMoves( |
| 3760 | loc.ToLow(), |
| 3761 | loc.ToHigh(), |
| 3762 | Primitive::kPrimInt, |
| 3763 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3764 | loc.ToLow(), |
| 3765 | Primitive::kPrimInt); |
| 3766 | } else if (shift > 32) { |
| 3767 | // Low part becomes 0. High part is low part << (shift-32). |
| 3768 | __ movl(high, low); |
| 3769 | __ shll(high, Immediate(shift - 32)); |
| 3770 | __ xorl(low, low); |
| 3771 | } else { |
| 3772 | // Between 1 and 31. |
| 3773 | __ shld(high, low, Immediate(shift)); |
| 3774 | __ shll(low, Immediate(shift)); |
| 3775 | } |
| 3776 | } |
| 3777 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3778 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3779 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3780 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3781 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3782 | __ testl(shifter, Immediate(32)); |
| 3783 | __ j(kEqual, &done); |
| 3784 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3785 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3786 | __ Bind(&done); |
| 3787 | } |
| 3788 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3789 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3790 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3791 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3792 | if (shift == 32) { |
| 3793 | // Need to copy the sign. |
| 3794 | DCHECK_NE(low, high); |
| 3795 | __ movl(low, high); |
| 3796 | __ sarl(high, Immediate(31)); |
| 3797 | } else if (shift > 32) { |
| 3798 | DCHECK_NE(low, high); |
| 3799 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3800 | __ movl(low, high); |
| 3801 | __ sarl(high, Immediate(31)); |
| 3802 | __ sarl(low, Immediate(shift - 32)); |
| 3803 | } else { |
| 3804 | // Between 1 and 31. |
| 3805 | __ shrd(low, high, Immediate(shift)); |
| 3806 | __ sarl(high, Immediate(shift)); |
| 3807 | } |
| 3808 | } |
| 3809 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3810 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3811 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3812 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3813 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3814 | __ testl(shifter, Immediate(32)); |
| 3815 | __ j(kEqual, &done); |
| 3816 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3817 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3818 | __ Bind(&done); |
| 3819 | } |
| 3820 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3821 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3822 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3823 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3824 | if (shift == 32) { |
| 3825 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3826 | codegen_->EmitParallelMoves( |
| 3827 | loc.ToHigh(), |
| 3828 | loc.ToLow(), |
| 3829 | Primitive::kPrimInt, |
| 3830 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3831 | loc.ToHigh(), |
| 3832 | Primitive::kPrimInt); |
| 3833 | } else if (shift > 32) { |
| 3834 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3835 | __ movl(low, high); |
| 3836 | __ shrl(low, Immediate(shift - 32)); |
| 3837 | __ xorl(high, high); |
| 3838 | } else { |
| 3839 | // Between 1 and 31. |
| 3840 | __ shrd(low, high, Immediate(shift)); |
| 3841 | __ shrl(high, Immediate(shift)); |
| 3842 | } |
| 3843 | } |
| 3844 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3845 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3846 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3847 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3848 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3849 | __ testl(shifter, Immediate(32)); |
| 3850 | __ j(kEqual, &done); |
| 3851 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3852 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3853 | __ Bind(&done); |
| 3854 | } |
| 3855 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3856 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3857 | LocationSummary* locations = |
| 3858 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3859 | |
| 3860 | switch (ror->GetResultType()) { |
| 3861 | case Primitive::kPrimLong: |
| 3862 | // Add the temporary needed. |
| 3863 | locations->AddTemp(Location::RequiresRegister()); |
| 3864 | FALLTHROUGH_INTENDED; |
| 3865 | case Primitive::kPrimInt: |
| 3866 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3867 | // The shift count needs to be in CL (unless it is a constant). |
| 3868 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3869 | locations->SetOut(Location::SameAsFirstInput()); |
| 3870 | break; |
| 3871 | default: |
| 3872 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3873 | UNREACHABLE(); |
| 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3878 | LocationSummary* locations = ror->GetLocations(); |
| 3879 | Location first = locations->InAt(0); |
| 3880 | Location second = locations->InAt(1); |
| 3881 | |
| 3882 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3883 | Register first_reg = first.AsRegister<Register>(); |
| 3884 | if (second.IsRegister()) { |
| 3885 | Register second_reg = second.AsRegister<Register>(); |
| 3886 | __ rorl(first_reg, second_reg); |
| 3887 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3888 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3889 | __ rorl(first_reg, imm); |
| 3890 | } |
| 3891 | return; |
| 3892 | } |
| 3893 | |
| 3894 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3895 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3896 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3897 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3898 | if (second.IsRegister()) { |
| 3899 | Register second_reg = second.AsRegister<Register>(); |
| 3900 | DCHECK_EQ(second_reg, ECX); |
| 3901 | __ movl(temp_reg, first_reg_hi); |
| 3902 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3903 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3904 | __ movl(temp_reg, first_reg_hi); |
| 3905 | __ testl(second_reg, Immediate(32)); |
| 3906 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3907 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3908 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3909 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3910 | if (shift_amt == 0) { |
| 3911 | // Already fine. |
| 3912 | return; |
| 3913 | } |
| 3914 | if (shift_amt == 32) { |
| 3915 | // Just swap. |
| 3916 | __ movl(temp_reg, first_reg_lo); |
| 3917 | __ movl(first_reg_lo, first_reg_hi); |
| 3918 | __ movl(first_reg_hi, temp_reg); |
| 3919 | return; |
| 3920 | } |
| 3921 | |
| 3922 | Immediate imm(shift_amt); |
| 3923 | // Save the constents of the low value. |
| 3924 | __ movl(temp_reg, first_reg_lo); |
| 3925 | |
| 3926 | // Shift right into low, feeding bits from high. |
| 3927 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3928 | |
| 3929 | // Shift right into high, feeding bits from the original low. |
| 3930 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3931 | |
| 3932 | // Swap if needed. |
| 3933 | if (shift_amt > 32) { |
| 3934 | __ movl(temp_reg, first_reg_lo); |
| 3935 | __ movl(first_reg_lo, first_reg_hi); |
| 3936 | __ movl(first_reg_hi, temp_reg); |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3941 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3942 | HandleShift(shl); |
| 3943 | } |
| 3944 | |
| 3945 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3946 | HandleShift(shl); |
| 3947 | } |
| 3948 | |
| 3949 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3950 | HandleShift(shr); |
| 3951 | } |
| 3952 | |
| 3953 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3954 | HandleShift(shr); |
| 3955 | } |
| 3956 | |
| 3957 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3958 | HandleShift(ushr); |
| 3959 | } |
| 3960 | |
| 3961 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3962 | HandleShift(ushr); |
| 3963 | } |
| 3964 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3965 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3966 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3967 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3968 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3969 | if (instruction->IsStringAlloc()) { |
| 3970 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3971 | } else { |
| 3972 | InvokeRuntimeCallingConvention calling_convention; |
| 3973 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3974 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3975 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3979 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3980 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3981 | if (instruction->IsStringAlloc()) { |
| 3982 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3983 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 3984 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3985 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3986 | __ call(Address(temp, code_offset.Int32Value())); |
| 3987 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3988 | } else { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3989 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3990 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3991 | DCHECK(!codegen_->IsLeafMethod()); |
| 3992 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3993 | } |
| 3994 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3995 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3996 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3997 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3998 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3999 | InvokeRuntimeCallingConvention calling_convention; |
| 4000 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4001 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4002 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4006 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4007 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4008 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4009 | // of poisoning the reference. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 4010 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4011 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4012 | DCHECK(!codegen_->IsLeafMethod()); |
| 4013 | } |
| 4014 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4015 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4016 | LocationSummary* locations = |
| 4017 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4018 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4019 | if (location.IsStackSlot()) { |
| 4020 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4021 | } else if (location.IsDoubleStackSlot()) { |
| 4022 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4023 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4024 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4025 | } |
| 4026 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4027 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4028 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4029 | } |
| 4030 | |
| 4031 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4032 | LocationSummary* locations = |
| 4033 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4034 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4035 | } |
| 4036 | |
| 4037 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4038 | } |
| 4039 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4040 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4041 | LocationSummary* locations = |
| 4042 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4043 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4044 | locations->SetOut(Location::RequiresRegister()); |
| 4045 | } |
| 4046 | |
| 4047 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4048 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4049 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4050 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4051 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4052 | __ movl(locations->Out().AsRegister<Register>(), |
| 4053 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4054 | } else { |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4055 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4056 | instruction->GetIndex(), kX86PointerSize)); |
Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4057 | __ movl(locations->Out().AsRegister<Register>(), |
| 4058 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4059 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4060 | // temp = temp->GetImtEntryAt(method_offset); |
| 4061 | __ movl(locations->Out().AsRegister<Register>(), |
| 4062 | Address(locations->Out().AsRegister<Register>(), method_offset)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4063 | } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4066 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4067 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4068 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4069 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4070 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4071 | } |
| 4072 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4073 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4074 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4075 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4076 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4077 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4078 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4079 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4080 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4081 | break; |
| 4082 | |
| 4083 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4084 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4085 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4086 | break; |
| 4087 | |
| 4088 | default: |
| 4089 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4090 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4091 | } |
| 4092 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4093 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4094 | LocationSummary* locations = |
| 4095 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4096 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4097 | locations->SetOut(Location::SameAsFirstInput()); |
| 4098 | } |
| 4099 | |
| 4100 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4101 | LocationSummary* locations = bool_not->GetLocations(); |
| 4102 | Location in = locations->InAt(0); |
| 4103 | Location out = locations->Out(); |
| 4104 | DCHECK(in.Equals(out)); |
| 4105 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4106 | } |
| 4107 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4108 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4109 | LocationSummary* locations = |
| 4110 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4111 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4112 | case Primitive::kPrimBoolean: |
| 4113 | case Primitive::kPrimByte: |
| 4114 | case Primitive::kPrimShort: |
| 4115 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4116 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4117 | case Primitive::kPrimLong: { |
| 4118 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4119 | locations->SetInAt(1, Location::Any()); |
| 4120 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4121 | break; |
| 4122 | } |
| 4123 | case Primitive::kPrimFloat: |
| 4124 | case Primitive::kPrimDouble: { |
| 4125 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4126 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4127 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4128 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4129 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4130 | } else { |
| 4131 | locations->SetInAt(1, Location::Any()); |
| 4132 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4133 | locations->SetOut(Location::RequiresRegister()); |
| 4134 | break; |
| 4135 | } |
| 4136 | default: |
| 4137 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4138 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4142 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4143 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4144 | Location left = locations->InAt(0); |
| 4145 | Location right = locations->InAt(1); |
| 4146 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4147 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4148 | Condition less_cond = kLess; |
| 4149 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4150 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4151 | case Primitive::kPrimBoolean: |
| 4152 | case Primitive::kPrimByte: |
| 4153 | case Primitive::kPrimShort: |
| 4154 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4155 | case Primitive::kPrimInt: { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4156 | codegen_->GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4157 | break; |
| 4158 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4159 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4160 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4161 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4162 | int32_t val_low = 0; |
| 4163 | int32_t val_high = 0; |
| 4164 | bool right_is_const = false; |
| 4165 | |
| 4166 | if (right.IsConstant()) { |
| 4167 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4168 | right_is_const = true; |
| 4169 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4170 | val_low = Low32Bits(val); |
| 4171 | val_high = High32Bits(val); |
| 4172 | } |
| 4173 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4174 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4175 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4176 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4177 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4178 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4179 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4180 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4181 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4182 | __ j(kLess, &less); // Signed compare. |
| 4183 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4184 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4185 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4186 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4187 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4188 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4189 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4190 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4191 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4192 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4193 | break; |
| 4194 | } |
| 4195 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4196 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4197 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4198 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4199 | break; |
| 4200 | } |
| 4201 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4202 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4203 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4204 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4205 | break; |
| 4206 | } |
| 4207 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4208 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4209 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4210 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4211 | __ movl(out, Immediate(0)); |
| 4212 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4213 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4214 | |
| 4215 | __ Bind(&greater); |
| 4216 | __ movl(out, Immediate(1)); |
| 4217 | __ jmp(&done); |
| 4218 | |
| 4219 | __ Bind(&less); |
| 4220 | __ movl(out, Immediate(-1)); |
| 4221 | |
| 4222 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4225 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4226 | LocationSummary* locations = |
| 4227 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4228 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4229 | locations->SetInAt(i, Location::Any()); |
| 4230 | } |
| 4231 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4232 | } |
| 4233 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4234 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4235 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4236 | } |
| 4237 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4238 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4239 | /* |
| 4240 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4241 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4242 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4243 | */ |
| 4244 | switch (kind) { |
| 4245 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4246 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4247 | break; |
| 4248 | } |
| 4249 | case MemBarrierKind::kAnyStore: |
| 4250 | case MemBarrierKind::kLoadAny: |
| 4251 | case MemBarrierKind::kStoreStore: { |
| 4252 | // nop |
| 4253 | break; |
| 4254 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4255 | case MemBarrierKind::kNTStoreStore: |
| 4256 | // Non-Temporal Store/Store needs an explicit fence. |
| 4257 | MemoryFence(/* non-temporal */ true); |
| 4258 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4259 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4260 | } |
| 4261 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4262 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4263 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4264 | HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4265 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4266 | |
| 4267 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4268 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4269 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4270 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4271 | if (GetGraph()->HasIrreducibleLoops() && |
| 4272 | (dispatch_info.method_load_kind == |
| 4273 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4274 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4275 | } |
| 4276 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4277 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4278 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4279 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4280 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4281 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4282 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4283 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4284 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4285 | 0u |
| 4286 | }; |
| 4287 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4288 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4289 | } |
| 4290 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4291 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4292 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4293 | Register temp) { |
| 4294 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4295 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4296 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4297 | return location.AsRegister<Register>(); |
| 4298 | } |
| 4299 | // For intrinsics we allow any location, so it may be on the stack. |
| 4300 | if (!location.IsRegister()) { |
| 4301 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4302 | return temp; |
| 4303 | } |
| 4304 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4305 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4306 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4307 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4308 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4309 | if (slow_path != nullptr) { |
| 4310 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4311 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4312 | __ movl(temp, Address(ESP, stack_offset)); |
| 4313 | return temp; |
| 4314 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4315 | } |
| 4316 | return location.AsRegister<Register>(); |
| 4317 | } |
| 4318 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4319 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4320 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4321 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4322 | switch (invoke->GetMethodLoadKind()) { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4323 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4324 | // temp = thread->string_init_entrypoint |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4325 | uint32_t offset = |
| 4326 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); |
| 4327 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4328 | break; |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4329 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4330 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4331 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4332 | break; |
| 4333 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4334 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4335 | break; |
| 4336 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4337 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4338 | method_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4339 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4340 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4341 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4342 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4343 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4344 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4345 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4346 | // Bind a new fixup label at the end of the "movl" insn. |
| 4347 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4348 | __ Bind(NewPcRelativeDexCacheArrayPatch(invoke->GetDexFile(), offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4349 | break; |
| 4350 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4351 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4352 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4353 | Register method_reg; |
| 4354 | Register reg = temp.AsRegister<Register>(); |
| 4355 | if (current_method.IsRegister()) { |
| 4356 | method_reg = current_method.AsRegister<Register>(); |
| 4357 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4358 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4359 | DCHECK(!current_method.IsValid()); |
| 4360 | method_reg = reg; |
| 4361 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4362 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4363 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4364 | __ movl(reg, Address(method_reg, |
| 4365 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4366 | // temp = temp[index_in_cache]; |
| 4367 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4368 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4369 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4370 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4371 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4372 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4373 | return callee_method; |
| 4374 | } |
| 4375 | |
| 4376 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4377 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4378 | |
| 4379 | switch (invoke->GetCodePtrLocation()) { |
| 4380 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4381 | __ call(GetFrameEntryLabel()); |
| 4382 | break; |
| 4383 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4384 | relative_call_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, |
| 4385 | invoke->GetTargetMethod().dex_method_index); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4386 | Label* label = &relative_call_patches_.back().label; |
| 4387 | __ call(label); // Bind to the patch label, override at link time. |
| 4388 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4389 | break; |
| 4390 | } |
| 4391 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4392 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4393 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4394 | LOG(FATAL) << "Unsupported"; |
| 4395 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4396 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4397 | // (callee_method + offset_of_quick_compiled_code)() |
| 4398 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4399 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4400 | kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4401 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4405 | } |
| 4406 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4407 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4408 | Register temp = temp_in.AsRegister<Register>(); |
| 4409 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4410 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4411 | |
| 4412 | // Use the calling convention instead of the location of the receiver, as |
| 4413 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4414 | // slow path, the arguments have been moved to the right place, so here we are |
| 4415 | // guaranteed that the receiver is the first register of the calling convention. |
| 4416 | InvokeDexCallingConvention calling_convention; |
| 4417 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4418 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4419 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4420 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4421 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4422 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4423 | // emit a read barrier for the previous class reference load. |
| 4424 | // However this is not required in practice, as this is an |
| 4425 | // intermediate/temporary reference and because the current |
| 4426 | // concurrent copying collector keeps the from-space memory |
| 4427 | // intact/accessible until the end of the marking phase (the |
| 4428 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4429 | __ MaybeUnpoisonHeapReference(temp); |
| 4430 | // temp = temp->GetMethodAt(method_offset); |
| 4431 | __ movl(temp, Address(temp, method_offset)); |
| 4432 | // call temp->GetEntryPoint(); |
| 4433 | __ call(Address( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4434 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4437 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4438 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4439 | simple_patches_.emplace_back(); |
| 4440 | __ Bind(&simple_patches_.back()); |
| 4441 | } |
| 4442 | } |
| 4443 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4444 | void CodeGeneratorX86::RecordBootStringPatch(HLoadString* load_string) { |
| 4445 | DCHECK(GetCompilerOptions().IsBootImage()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4446 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4447 | __ Bind(&string_patches_.back().label); |
| 4448 | } |
| 4449 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4450 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4451 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4452 | __ Bind(&type_patches_.back().label); |
| 4453 | } |
| 4454 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4455 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { |
| 4456 | DCHECK(!GetCompilerOptions().IsBootImage()); |
| 4457 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4458 | return &string_patches_.back().label; |
| 4459 | } |
| 4460 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4461 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4462 | uint32_t element_offset) { |
| 4463 | // Add the patch entry and bind its label at the end of the instruction. |
| 4464 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4465 | return &pc_relative_dex_cache_patches_.back().label; |
| 4466 | } |
| 4467 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4468 | // The label points to the end of the "movl" or another instruction but the literal offset |
| 4469 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4470 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
| 4471 | |
| 4472 | template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> |
| 4473 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( |
| 4474 | const ArenaDeque<PatchInfo<Label>>& infos, |
| 4475 | ArenaVector<LinkerPatch>* linker_patches) { |
| 4476 | for (const PatchInfo<Label>& info : infos) { |
| 4477 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4478 | linker_patches->push_back( |
| 4479 | Factory(literal_offset, &info.dex_file, GetMethodAddressOffset(), info.index)); |
| 4480 | } |
| 4481 | } |
| 4482 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4483 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4484 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4485 | size_t size = |
| 4486 | method_patches_.size() + |
| 4487 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4488 | pc_relative_dex_cache_patches_.size() + |
| 4489 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4490 | string_patches_.size() + |
| 4491 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4492 | linker_patches->reserve(size); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4493 | for (const PatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4494 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4495 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4496 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4497 | for (const PatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4498 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4499 | linker_patches->push_back( |
| 4500 | LinkerPatch::RelativeCodePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4501 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4502 | EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_, |
| 4503 | linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4504 | for (const Label& label : simple_patches_) { |
| 4505 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4506 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4507 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4508 | if (!GetCompilerOptions().IsBootImage()) { |
| 4509 | EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(string_patches_, linker_patches); |
| 4510 | } else if (GetCompilerOptions().GetCompilePic()) { |
| 4511 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(string_patches_, linker_patches); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4512 | } else { |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4513 | for (const PatchInfo<Label>& info : string_patches_) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4514 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4515 | linker_patches->push_back( |
| 4516 | LinkerPatch::StringPatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4517 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4518 | } |
| 4519 | if (GetCompilerOptions().GetCompilePic()) { |
| 4520 | EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(type_patches_, linker_patches); |
| 4521 | } else { |
| 4522 | for (const PatchInfo<Label>& info : type_patches_) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4523 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4524 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, &info.dex_file, info.index)); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4525 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4526 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4529 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4530 | Register card, |
| 4531 | Register object, |
| 4532 | Register value, |
| 4533 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4534 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4535 | if (value_can_be_null) { |
| 4536 | __ testl(value, value); |
| 4537 | __ j(kEqual, &is_null); |
| 4538 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4539 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4540 | __ movl(temp, object); |
| 4541 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4542 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4543 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4544 | if (value_can_be_null) { |
| 4545 | __ Bind(&is_null); |
| 4546 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4547 | } |
| 4548 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4549 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4550 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4551 | |
| 4552 | bool object_field_get_with_read_barrier = |
| 4553 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4554 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4555 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4556 | kEmitCompilerReadBarrier ? |
| 4557 | LocationSummary::kCallOnSlowPath : |
| 4558 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4559 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4560 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 4561 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4562 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4563 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4564 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4565 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4566 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4567 | // The output overlaps in case of long: we don't want the low move |
| 4568 | // to overwrite the object's location. Likewise, in the case of |
| 4569 | // an object field get with read barriers enabled, we do not want |
| 4570 | // the move to overwrite the object's location, as we need it to emit |
| 4571 | // the read barrier. |
| 4572 | locations->SetOut( |
| 4573 | Location::RequiresRegister(), |
| 4574 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4575 | Location::kOutputOverlap : |
| 4576 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4577 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | |
| 4579 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4580 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4581 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4582 | // load the temp into the XMM and then copy the XMM into the |
| 4583 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4584 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4585 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4589 | const FieldInfo& field_info) { |
| 4590 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4591 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4592 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4593 | Location base_loc = locations->InAt(0); |
| 4594 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4595 | Location out = locations->Out(); |
| 4596 | bool is_volatile = field_info.IsVolatile(); |
| 4597 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4598 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4599 | |
| 4600 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4601 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4602 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4603 | break; |
| 4604 | } |
| 4605 | |
| 4606 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4607 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4608 | break; |
| 4609 | } |
| 4610 | |
| 4611 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4613 | break; |
| 4614 | } |
| 4615 | |
| 4616 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4618 | break; |
| 4619 | } |
| 4620 | |
| 4621 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4623 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4624 | |
| 4625 | case Primitive::kPrimNot: { |
| 4626 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4627 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4628 | // Note that a potential implicit null check is handled in this |
| 4629 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4630 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 4631 | instruction, out, base, offset, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4632 | if (is_volatile) { |
| 4633 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4634 | } |
| 4635 | } else { |
| 4636 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4637 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4638 | if (is_volatile) { |
| 4639 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4640 | } |
| 4641 | // If read barriers are enabled, emit read barriers other than |
| 4642 | // Baker's using a slow path (and also unpoison the loaded |
| 4643 | // reference, if heap poisoning is enabled). |
| 4644 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4645 | } |
| 4646 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4650 | if (is_volatile) { |
| 4651 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4652 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4653 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4654 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4655 | __ psrlq(temp, Immediate(32)); |
| 4656 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4657 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4658 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4660 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4661 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4662 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4663 | break; |
| 4664 | } |
| 4665 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4666 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4667 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4668 | break; |
| 4669 | } |
| 4670 | |
| 4671 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4673 | break; |
| 4674 | } |
| 4675 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4676 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4677 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4678 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4679 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4680 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4681 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4682 | // Potential implicit null checks, in the case of reference or |
| 4683 | // long fields, are handled in the previous switch statement. |
| 4684 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4685 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4686 | } |
| 4687 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4688 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4689 | if (field_type == Primitive::kPrimNot) { |
| 4690 | // Memory barriers, in the case of references, are also handled |
| 4691 | // in the previous switch statement. |
| 4692 | } else { |
| 4693 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4694 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4695 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4699 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4700 | |
| 4701 | LocationSummary* locations = |
| 4702 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4703 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4704 | bool is_volatile = field_info.IsVolatile(); |
| 4705 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4706 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4707 | || (field_type == Primitive::kPrimByte); |
| 4708 | |
| 4709 | // The register allocator does not support multiple |
| 4710 | // inputs that die at entry with one in a specific register. |
| 4711 | if (is_byte_type) { |
| 4712 | // Ensure the value is in a byte register. |
| 4713 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4714 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4715 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4716 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4717 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4718 | } else { |
| 4719 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4720 | } |
| 4721 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4722 | // 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] | 4723 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4724 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4725 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4726 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4727 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4728 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4729 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4730 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4731 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4732 | } else { |
| 4733 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4734 | |
| 4735 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4736 | // Temporary registers for the write barrier. |
| 4737 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4738 | // Ensure the card is in a byte register. |
| 4739 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4740 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | } |
| 4742 | } |
| 4743 | |
| 4744 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4745 | const FieldInfo& field_info, |
| 4746 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4748 | |
| 4749 | LocationSummary* locations = instruction->GetLocations(); |
| 4750 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4751 | Location value = locations->InAt(1); |
| 4752 | bool is_volatile = field_info.IsVolatile(); |
| 4753 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4754 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4755 | bool needs_write_barrier = |
| 4756 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4757 | |
| 4758 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4759 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4760 | } |
| 4761 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4762 | bool maybe_record_implicit_null_check_done = false; |
| 4763 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4764 | switch (field_type) { |
| 4765 | case Primitive::kPrimBoolean: |
| 4766 | case Primitive::kPrimByte: { |
| 4767 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4768 | break; |
| 4769 | } |
| 4770 | |
| 4771 | case Primitive::kPrimShort: |
| 4772 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4773 | if (value.IsConstant()) { |
| 4774 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4775 | __ movw(Address(base, offset), Immediate(v)); |
| 4776 | } else { |
| 4777 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4778 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4779 | break; |
| 4780 | } |
| 4781 | |
| 4782 | case Primitive::kPrimInt: |
| 4783 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4784 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4785 | // Note that in the case where `value` is a null reference, |
| 4786 | // we do not enter this block, as the reference does not |
| 4787 | // need poisoning. |
| 4788 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4789 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4790 | __ movl(temp, value.AsRegister<Register>()); |
| 4791 | __ PoisonHeapReference(temp); |
| 4792 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4793 | } else if (value.IsConstant()) { |
| 4794 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4795 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4796 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4797 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4798 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4799 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4800 | break; |
| 4801 | } |
| 4802 | |
| 4803 | case Primitive::kPrimLong: { |
| 4804 | if (is_volatile) { |
| 4805 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4806 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4807 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4808 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4809 | __ punpckldq(temp1, temp2); |
| 4810 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4811 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4812 | } else if (value.IsConstant()) { |
| 4813 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4814 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4815 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4816 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4817 | } else { |
| 4818 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4819 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4820 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4821 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4822 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4823 | break; |
| 4824 | } |
| 4825 | |
| 4826 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4827 | if (value.IsConstant()) { |
| 4828 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4829 | __ movl(Address(base, offset), Immediate(v)); |
| 4830 | } else { |
| 4831 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4832 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4833 | break; |
| 4834 | } |
| 4835 | |
| 4836 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4837 | if (value.IsConstant()) { |
| 4838 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4839 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4840 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4841 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4842 | maybe_record_implicit_null_check_done = true; |
| 4843 | } else { |
| 4844 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4845 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4846 | break; |
| 4847 | } |
| 4848 | |
| 4849 | case Primitive::kPrimVoid: |
| 4850 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4851 | UNREACHABLE(); |
| 4852 | } |
| 4853 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4854 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4855 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4856 | } |
| 4857 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4858 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4859 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4860 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4861 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4862 | } |
| 4863 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4864 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4865 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4870 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4871 | } |
| 4872 | |
| 4873 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4874 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4875 | } |
| 4876 | |
| 4877 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4878 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4879 | } |
| 4880 | |
| 4881 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4882 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4886 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4890 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4894 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4895 | } |
| 4896 | |
| 4897 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4898 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4899 | } |
| 4900 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4901 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4902 | HUnresolvedInstanceFieldGet* instruction) { |
| 4903 | FieldAccessCallingConventionX86 calling_convention; |
| 4904 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4905 | instruction, instruction->GetFieldType(), calling_convention); |
| 4906 | } |
| 4907 | |
| 4908 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4909 | HUnresolvedInstanceFieldGet* instruction) { |
| 4910 | FieldAccessCallingConventionX86 calling_convention; |
| 4911 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4912 | instruction->GetFieldType(), |
| 4913 | instruction->GetFieldIndex(), |
| 4914 | instruction->GetDexPc(), |
| 4915 | calling_convention); |
| 4916 | } |
| 4917 | |
| 4918 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4919 | HUnresolvedInstanceFieldSet* instruction) { |
| 4920 | FieldAccessCallingConventionX86 calling_convention; |
| 4921 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4922 | instruction, instruction->GetFieldType(), calling_convention); |
| 4923 | } |
| 4924 | |
| 4925 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4926 | HUnresolvedInstanceFieldSet* instruction) { |
| 4927 | FieldAccessCallingConventionX86 calling_convention; |
| 4928 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4929 | instruction->GetFieldType(), |
| 4930 | instruction->GetFieldIndex(), |
| 4931 | instruction->GetDexPc(), |
| 4932 | calling_convention); |
| 4933 | } |
| 4934 | |
| 4935 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4936 | HUnresolvedStaticFieldGet* instruction) { |
| 4937 | FieldAccessCallingConventionX86 calling_convention; |
| 4938 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4939 | instruction, instruction->GetFieldType(), calling_convention); |
| 4940 | } |
| 4941 | |
| 4942 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4943 | HUnresolvedStaticFieldGet* instruction) { |
| 4944 | FieldAccessCallingConventionX86 calling_convention; |
| 4945 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4946 | instruction->GetFieldType(), |
| 4947 | instruction->GetFieldIndex(), |
| 4948 | instruction->GetDexPc(), |
| 4949 | calling_convention); |
| 4950 | } |
| 4951 | |
| 4952 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4953 | HUnresolvedStaticFieldSet* instruction) { |
| 4954 | FieldAccessCallingConventionX86 calling_convention; |
| 4955 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4956 | instruction, instruction->GetFieldType(), calling_convention); |
| 4957 | } |
| 4958 | |
| 4959 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4960 | HUnresolvedStaticFieldSet* instruction) { |
| 4961 | FieldAccessCallingConventionX86 calling_convention; |
| 4962 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4963 | instruction->GetFieldType(), |
| 4964 | instruction->GetFieldIndex(), |
| 4965 | instruction->GetDexPc(), |
| 4966 | calling_convention); |
| 4967 | } |
| 4968 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4969 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4970 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); |
| 4971 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
| 4972 | ? Location::RequiresRegister() |
| 4973 | : Location::Any(); |
| 4974 | locations->SetInAt(0, loc); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4975 | } |
| 4976 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4977 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4978 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4979 | return; |
| 4980 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4981 | LocationSummary* locations = instruction->GetLocations(); |
| 4982 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4983 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4984 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4985 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4986 | } |
| 4987 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4988 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4989 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4990 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4991 | |
| 4992 | LocationSummary* locations = instruction->GetLocations(); |
| 4993 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4994 | |
| 4995 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4996 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4997 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4998 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4999 | } else { |
| 5000 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5001 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5002 | __ jmp(slow_path->GetEntryLabel()); |
| 5003 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5004 | } |
| 5005 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5006 | } |
| 5007 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5008 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5009 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5012 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5013 | bool object_array_get_with_read_barrier = |
| 5014 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5015 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5016 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5017 | object_array_get_with_read_barrier ? |
| 5018 | LocationSummary::kCallOnSlowPath : |
| 5019 | LocationSummary::kNoCall); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5020 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5021 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5022 | } |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5023 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5024 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5025 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5026 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5027 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5028 | // The output overlaps in case of long: we don't want the low move |
| 5029 | // to overwrite the array's location. Likewise, in the case of an |
| 5030 | // object array get with read barriers enabled, we do not want the |
| 5031 | // move to overwrite the array's location, as we need it to emit |
| 5032 | // the read barrier. |
| 5033 | locations->SetOut( |
| 5034 | Location::RequiresRegister(), |
| 5035 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5036 | Location::kOutputOverlap : |
| 5037 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5038 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5039 | } |
| 5040 | |
| 5041 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5042 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5043 | Location obj_loc = locations->InAt(0); |
| 5044 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5045 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5046 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5047 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5048 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5049 | Primitive::Type type = instruction->GetType(); |
| 5050 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5051 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5052 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5053 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | break; |
| 5055 | } |
| 5056 | |
| 5057 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5058 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5059 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | break; |
| 5061 | } |
| 5062 | |
| 5063 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5064 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5065 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | break; |
| 5067 | } |
| 5068 | |
| 5069 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5070 | Register out = out_loc.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5071 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5072 | // Branch cases into compressed and uncompressed for each index's type. |
| 5073 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 5074 | NearLabel done, not_compressed; |
| 5075 | __ cmpl(Address(obj, count_offset), Immediate(0)); |
| 5076 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5077 | __ j(kGreaterEqual, ¬_compressed); |
| 5078 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); |
| 5079 | __ jmp(&done); |
| 5080 | __ Bind(¬_compressed); |
| 5081 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5082 | __ Bind(&done); |
| 5083 | } else { |
| 5084 | // Common case for charAt of array of char or when string compression's |
| 5085 | // feature is turned off. |
| 5086 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); |
| 5087 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5088 | break; |
| 5089 | } |
| 5090 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5091 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5092 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5093 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5094 | break; |
| 5095 | } |
| 5096 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5097 | case Primitive::kPrimNot: { |
| 5098 | static_assert( |
| 5099 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5100 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5101 | // /* HeapReference<Object> */ out = |
| 5102 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5103 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5104 | // Note that a potential implicit null check is handled in this |
| 5105 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5106 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 5107 | instruction, out_loc, obj, data_offset, index, /* needs_null_check */ true); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5108 | } else { |
| 5109 | Register out = out_loc.AsRegister<Register>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5110 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
| 5111 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5112 | // If read barriers are enabled, emit read barriers other than |
| 5113 | // Baker's using a slow path (and also unpoison the loaded |
| 5114 | // reference, if heap poisoning is enabled). |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5115 | if (index.IsConstant()) { |
| 5116 | uint32_t offset = |
| 5117 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5118 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5119 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5120 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5121 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5122 | } |
| 5123 | } |
| 5124 | break; |
| 5125 | } |
| 5126 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5128 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5129 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
| 5130 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
| 5131 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5132 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
| 5133 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5134 | break; |
| 5135 | } |
| 5136 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5137 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5138 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5139 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5140 | break; |
| 5141 | } |
| 5142 | |
| 5143 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5144 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5145 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5146 | break; |
| 5147 | } |
| 5148 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5149 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5150 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5151 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5152 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5153 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5154 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5155 | // Potential implicit null checks, in the case of reference or |
| 5156 | // long arrays, are handled in the previous switch statement. |
| 5157 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5158 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5159 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5163 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5164 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5165 | bool needs_write_barrier = |
| 5166 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5167 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5168 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5169 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5170 | instruction, |
Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5171 | may_need_runtime_call_for_type_check ? |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5172 | LocationSummary::kCallOnSlowPath : |
| 5173 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5174 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5175 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5176 | || (value_type == Primitive::kPrimByte); |
| 5177 | // We need the inputs to be different than the output in case of long operation. |
| 5178 | // In case of a byte operation, the register allocator does not support multiple |
| 5179 | // inputs that die at entry with one in a specific register. |
| 5180 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5181 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5182 | if (is_byte_type) { |
| 5183 | // Ensure the value is in a byte register. |
| 5184 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5185 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5186 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5187 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5188 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5189 | } |
| 5190 | if (needs_write_barrier) { |
| 5191 | // Temporary registers for the write barrier. |
| 5192 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5193 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5194 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5195 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5199 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5200 | Location array_loc = locations->InAt(0); |
| 5201 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5202 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5203 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5204 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5205 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5206 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5207 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5208 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5209 | bool needs_write_barrier = |
| 5210 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5211 | |
| 5212 | switch (value_type) { |
| 5213 | case Primitive::kPrimBoolean: |
| 5214 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5215 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5216 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5217 | if (value.IsRegister()) { |
| 5218 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5219 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5220 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5221 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5222 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5223 | break; |
| 5224 | } |
| 5225 | |
| 5226 | case Primitive::kPrimShort: |
| 5227 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5228 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5229 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5230 | if (value.IsRegister()) { |
| 5231 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5232 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5233 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5234 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5235 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5236 | break; |
| 5237 | } |
| 5238 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5239 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5240 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5241 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5242 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5243 | if (!value.IsRegister()) { |
| 5244 | // Just setting null. |
| 5245 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5246 | DCHECK(value.IsConstant()) << value; |
| 5247 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5248 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5249 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5250 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5251 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5252 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5253 | |
| 5254 | DCHECK(needs_write_barrier); |
| 5255 | Register register_value = value.AsRegister<Register>(); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5256 | // We cannot use a NearLabel for `done`, as its range may be too |
| 5257 | // short when Baker read barriers are enabled. |
| 5258 | Label done; |
| 5259 | NearLabel not_null, do_put; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5260 | SlowPathCode* slow_path = nullptr; |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5261 | Location temp_loc = locations->GetTemp(0); |
| 5262 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5263 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5264 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5265 | codegen_->AddSlowPath(slow_path); |
| 5266 | if (instruction->GetValueCanBeNull()) { |
| 5267 | __ testl(register_value, register_value); |
| 5268 | __ j(kNotEqual, ¬_null); |
| 5269 | __ movl(address, Immediate(0)); |
| 5270 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5271 | __ jmp(&done); |
| 5272 | __ Bind(¬_null); |
| 5273 | } |
| 5274 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5275 | // Note that when Baker read barriers are enabled, the type |
| 5276 | // checks are performed without read barriers. This is fine, |
| 5277 | // even in the case where a class object is in the from-space |
| 5278 | // after the flip, as a comparison involving such a type would |
| 5279 | // not produce a false positive; it may of course produce a |
| 5280 | // false negative, in which case we would take the ArraySet |
| 5281 | // slow path. |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5282 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5283 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5284 | __ movl(temp, Address(array, class_offset)); |
| 5285 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5286 | __ MaybeUnpoisonHeapReference(temp); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5287 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5288 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5289 | __ movl(temp, Address(temp, component_offset)); |
| 5290 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5291 | // nor the object reference in `register_value->klass`, as |
| 5292 | // we are comparing two poisoned references. |
| 5293 | __ cmpl(temp, Address(register_value, class_offset)); |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5294 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5295 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5296 | __ j(kEqual, &do_put); |
| 5297 | // If heap poisoning is enabled, the `temp` reference has |
| 5298 | // not been unpoisoned yet; unpoison it now. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5299 | __ MaybeUnpoisonHeapReference(temp); |
| 5300 | |
Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5301 | // If heap poisoning is enabled, no need to unpoison the |
| 5302 | // heap reference loaded below, as it is only used for a |
| 5303 | // comparison with null. |
| 5304 | __ cmpl(Address(temp, super_offset), Immediate(0)); |
| 5305 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5306 | __ Bind(&do_put); |
| 5307 | } else { |
| 5308 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5309 | } |
| 5310 | } |
| 5311 | |
| 5312 | if (kPoisonHeapReferences) { |
| 5313 | __ movl(temp, register_value); |
| 5314 | __ PoisonHeapReference(temp); |
| 5315 | __ movl(address, temp); |
| 5316 | } else { |
| 5317 | __ movl(address, register_value); |
| 5318 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5319 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5320 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5321 | } |
| 5322 | |
| 5323 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5324 | codegen_->MarkGCCard( |
| 5325 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5326 | __ Bind(&done); |
| 5327 | |
| 5328 | if (slow_path != nullptr) { |
| 5329 | __ Bind(slow_path->GetExitLabel()); |
| 5330 | } |
| 5331 | |
| 5332 | break; |
| 5333 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5334 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5335 | case Primitive::kPrimInt: { |
| 5336 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5337 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5338 | if (value.IsRegister()) { |
| 5339 | __ movl(address, value.AsRegister<Register>()); |
| 5340 | } else { |
| 5341 | DCHECK(value.IsConstant()) << value; |
| 5342 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5343 | __ movl(address, Immediate(v)); |
| 5344 | } |
| 5345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | break; |
| 5347 | } |
| 5348 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5349 | case Primitive::kPrimLong: { |
| 5350 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5351 | if (value.IsRegisterPair()) { |
| 5352 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5353 | value.AsRegisterPairLow<Register>()); |
| 5354 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5355 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5356 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5357 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5358 | DCHECK(value.IsConstant()); |
| 5359 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 5360 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), |
| 5361 | Immediate(Low32Bits(val))); |
| 5362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5363 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), |
| 5364 | Immediate(High32Bits(val))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5365 | } |
| 5366 | break; |
| 5367 | } |
| 5368 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5369 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5370 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5371 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5372 | if (value.IsFpuRegister()) { |
| 5373 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5374 | } else { |
| 5375 | DCHECK(value.IsConstant()); |
| 5376 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5377 | __ movl(address, Immediate(v)); |
| 5378 | } |
| 5379 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5380 | break; |
| 5381 | } |
| 5382 | |
| 5383 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5384 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5385 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5386 | if (value.IsFpuRegister()) { |
| 5387 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5388 | } else { |
| 5389 | DCHECK(value.IsConstant()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5390 | Address address_hi = |
| 5391 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5392 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5393 | __ movl(address, Immediate(Low32Bits(v))); |
| 5394 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5395 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5396 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5397 | break; |
| 5398 | } |
| 5399 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5400 | case Primitive::kPrimVoid: |
| 5401 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5402 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5407 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5408 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5409 | if (!instruction->IsEmittedAtUseSite()) { |
| 5410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5411 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5412 | } |
| 5413 | |
| 5414 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5415 | if (instruction->IsEmittedAtUseSite()) { |
| 5416 | return; |
| 5417 | } |
| 5418 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5419 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5420 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5421 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5422 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5423 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5424 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5425 | // Mask out most significant bit in case the array is String's array of char. |
| 5426 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { |
| 5427 | __ andl(out, Immediate(INT32_MAX)); |
| 5428 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5432 | RegisterSet caller_saves = RegisterSet::Empty(); |
| 5433 | InvokeRuntimeCallingConvention calling_convention; |
| 5434 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5435 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5436 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5437 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5438 | HInstruction* length = instruction->InputAt(1); |
| 5439 | if (!length->IsEmittedAtUseSite()) { |
| 5440 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5441 | } |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5442 | // Need register to see array's length. |
| 5443 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 5444 | locations->AddTemp(Location::RequiresRegister()); |
| 5445 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5449 | const bool is_string_compressed_char_at = |
| 5450 | mirror::kUseStringCompression && instruction->IsStringCharAt(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5451 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5452 | Location index_loc = locations->InAt(0); |
| 5453 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5454 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5455 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5456 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5457 | if (length_loc.IsConstant()) { |
| 5458 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5459 | if (index_loc.IsConstant()) { |
| 5460 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5461 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5462 | if (index < 0 || index >= length) { |
| 5463 | codegen_->AddSlowPath(slow_path); |
| 5464 | __ jmp(slow_path->GetEntryLabel()); |
| 5465 | } else { |
| 5466 | // Some optimization after BCE may have generated this, and we should not |
| 5467 | // generate a bounds check if it is a valid range. |
| 5468 | } |
| 5469 | return; |
| 5470 | } |
| 5471 | |
| 5472 | // We have to reverse the jump condition because the length is the constant. |
| 5473 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5474 | __ cmpl(index_reg, Immediate(length)); |
| 5475 | codegen_->AddSlowPath(slow_path); |
| 5476 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5477 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5478 | HInstruction* array_length = instruction->InputAt(1); |
| 5479 | if (array_length->IsEmittedAtUseSite()) { |
| 5480 | // Address the length field in the array. |
| 5481 | DCHECK(array_length->IsArrayLength()); |
| 5482 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5483 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5484 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5485 | if (is_string_compressed_char_at) { |
| 5486 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 5487 | __ movl(length_reg, array_len); |
| 5488 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
| 5489 | __ andl(length_reg, Immediate(INT32_MAX)); |
| 5490 | codegen_->GenerateIntCompare(length_reg, index_loc); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5491 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5492 | // Checking bounds for general case: |
| 5493 | // Array of char or string's array with feature compression off. |
| 5494 | if (index_loc.IsConstant()) { |
| 5495 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5496 | __ cmpl(array_len, Immediate(value)); |
| 5497 | } else { |
| 5498 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5499 | } |
| 5500 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 5501 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5502 | } else { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5503 | codegen_->GenerateIntCompare(length_loc, index_loc); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5504 | } |
| 5505 | codegen_->AddSlowPath(slow_path); |
| 5506 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5507 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5508 | } |
| 5509 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5510 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5511 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5512 | } |
| 5513 | |
| 5514 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5515 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5516 | } |
| 5517 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5518 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5519 | LocationSummary* locations = |
| 5520 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5521 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5522 | } |
| 5523 | |
| 5524 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5525 | HBasicBlock* block = instruction->GetBlock(); |
| 5526 | if (block->GetLoopInformation() != nullptr) { |
| 5527 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5528 | // The back edge will generate the suspend check. |
| 5529 | return; |
| 5530 | } |
| 5531 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5532 | // The goto will generate the suspend check. |
| 5533 | return; |
| 5534 | } |
| 5535 | GenerateSuspendCheck(instruction, nullptr); |
| 5536 | } |
| 5537 | |
| 5538 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5539 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5540 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5541 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5542 | if (slow_path == nullptr) { |
| 5543 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5544 | instruction->SetSlowPath(slow_path); |
| 5545 | codegen_->AddSlowPath(slow_path); |
| 5546 | if (successor != nullptr) { |
| 5547 | DCHECK(successor->IsLoopHeader()); |
| 5548 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5549 | } |
| 5550 | } else { |
| 5551 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5552 | } |
| 5553 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5554 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5555 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5556 | if (successor == nullptr) { |
| 5557 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5558 | __ Bind(slow_path->GetReturnLabel()); |
| 5559 | } else { |
| 5560 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5561 | __ jmp(slow_path->GetEntryLabel()); |
| 5562 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5563 | } |
| 5564 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5565 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5566 | return codegen_->GetAssembler(); |
| 5567 | } |
| 5568 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5569 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5570 | ScratchRegisterScope ensure_scratch( |
| 5571 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5572 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5573 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5574 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5575 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5579 | ScratchRegisterScope ensure_scratch( |
| 5580 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5581 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5582 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5583 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5584 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5585 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5586 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5590 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5591 | Location source = move->GetSource(); |
| 5592 | Location destination = move->GetDestination(); |
| 5593 | |
| 5594 | if (source.IsRegister()) { |
| 5595 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5596 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5597 | } else if (destination.IsFpuRegister()) { |
| 5598 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5599 | } else { |
| 5600 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5601 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5602 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5603 | } else if (source.IsRegisterPair()) { |
| 5604 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5605 | // Create stack space for 2 elements. |
| 5606 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5607 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5608 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5609 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5610 | // And remove the temporary stack space we allocated. |
| 5611 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5612 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5613 | if (destination.IsRegister()) { |
| 5614 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5615 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5616 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5617 | } else if (destination.IsRegisterPair()) { |
| 5618 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5619 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5620 | __ psrlq(src_reg, Immediate(32)); |
| 5621 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5622 | } else if (destination.IsStackSlot()) { |
| 5623 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5624 | } else { |
| 5625 | DCHECK(destination.IsDoubleStackSlot()); |
| 5626 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5627 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5628 | } else if (source.IsStackSlot()) { |
| 5629 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5630 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5631 | } else if (destination.IsFpuRegister()) { |
| 5632 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5633 | } else { |
| 5634 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5635 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5636 | } |
| 5637 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5638 | if (destination.IsRegisterPair()) { |
| 5639 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5640 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5641 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5642 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5643 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5644 | } else { |
| 5645 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5646 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5647 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5648 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5649 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5650 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5651 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5652 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5653 | if (value == 0) { |
| 5654 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5655 | } else { |
| 5656 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5657 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5658 | } else { |
| 5659 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5660 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5661 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5662 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5663 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5664 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5665 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5666 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5667 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5668 | if (value == 0) { |
| 5669 | // Easy handling of 0.0. |
| 5670 | __ xorps(dest, dest); |
| 5671 | } else { |
| 5672 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5673 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5674 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5675 | __ movl(temp, Immediate(value)); |
| 5676 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5677 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5678 | } else { |
| 5679 | DCHECK(destination.IsStackSlot()) << destination; |
| 5680 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5681 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5682 | } else if (constant->IsLongConstant()) { |
| 5683 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5684 | int32_t low_value = Low32Bits(value); |
| 5685 | int32_t high_value = High32Bits(value); |
| 5686 | Immediate low(low_value); |
| 5687 | Immediate high(high_value); |
| 5688 | if (destination.IsDoubleStackSlot()) { |
| 5689 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5690 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5691 | } else { |
| 5692 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5693 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5694 | } |
| 5695 | } else { |
| 5696 | DCHECK(constant->IsDoubleConstant()); |
| 5697 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5698 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5699 | int32_t low_value = Low32Bits(value); |
| 5700 | int32_t high_value = High32Bits(value); |
| 5701 | Immediate low(low_value); |
| 5702 | Immediate high(high_value); |
| 5703 | if (destination.IsFpuRegister()) { |
| 5704 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5705 | if (value == 0) { |
| 5706 | // Easy handling of 0.0. |
| 5707 | __ xorpd(dest, dest); |
| 5708 | } else { |
| 5709 | __ pushl(high); |
| 5710 | __ pushl(low); |
| 5711 | __ movsd(dest, Address(ESP, 0)); |
| 5712 | __ addl(ESP, Immediate(8)); |
| 5713 | } |
| 5714 | } else { |
| 5715 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5716 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5717 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5718 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5719 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5720 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5721 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5722 | } |
| 5723 | } |
| 5724 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5725 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5726 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5727 | ScratchRegisterScope ensure_scratch( |
| 5728 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5729 | |
| 5730 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5731 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5732 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5733 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5734 | } |
| 5735 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5736 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5737 | ScratchRegisterScope ensure_scratch( |
| 5738 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5739 | |
| 5740 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5741 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5742 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5743 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5744 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5745 | } |
| 5746 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5747 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5748 | ScratchRegisterScope ensure_scratch1( |
| 5749 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5750 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5751 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5752 | ScratchRegisterScope ensure_scratch2( |
| 5753 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5754 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5755 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5756 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5757 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5758 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5759 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5760 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5764 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5765 | Location source = move->GetSource(); |
| 5766 | Location destination = move->GetDestination(); |
| 5767 | |
| 5768 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5769 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5770 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5771 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5772 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5773 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5774 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5775 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5776 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5777 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5778 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5779 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5780 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5781 | // Use XOR Swap algorithm to avoid a temporary. |
| 5782 | DCHECK_NE(source.reg(), destination.reg()); |
| 5783 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5784 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5785 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5786 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5787 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5788 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5789 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5790 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5791 | // Take advantage of the 16 bytes in the XMM register. |
| 5792 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5793 | Address stack(ESP, destination.GetStackIndex()); |
| 5794 | // Load the double into the high doubleword. |
| 5795 | __ movhpd(reg, stack); |
| 5796 | |
| 5797 | // Store the low double into the destination. |
| 5798 | __ movsd(stack, reg); |
| 5799 | |
| 5800 | // Move the high double to the low double. |
| 5801 | __ psrldq(reg, Immediate(8)); |
| 5802 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5803 | // Take advantage of the 16 bytes in the XMM register. |
| 5804 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5805 | Address stack(ESP, source.GetStackIndex()); |
| 5806 | // Load the double into the high doubleword. |
| 5807 | __ movhpd(reg, stack); |
| 5808 | |
| 5809 | // Store the low double into the destination. |
| 5810 | __ movsd(stack, reg); |
| 5811 | |
| 5812 | // Move the high double to the low double. |
| 5813 | __ psrldq(reg, Immediate(8)); |
| 5814 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5815 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5816 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5817 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5818 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5819 | } |
| 5820 | } |
| 5821 | |
| 5822 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5823 | __ pushl(static_cast<Register>(reg)); |
| 5824 | } |
| 5825 | |
| 5826 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5827 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5828 | } |
| 5829 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5830 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5831 | HLoadClass::LoadKind desired_class_load_kind) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5832 | switch (desired_class_load_kind) { |
| 5833 | case HLoadClass::LoadKind::kReferrersClass: |
| 5834 | break; |
| 5835 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5836 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5837 | break; |
| 5838 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5839 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5840 | FALLTHROUGH_INTENDED; |
| 5841 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5842 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5843 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5844 | // is incompatible with it. |
| 5845 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5846 | // with irreducible loops. |
| 5847 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5848 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5849 | } |
| 5850 | break; |
| 5851 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5852 | break; |
| 5853 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5854 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5855 | break; |
| 5856 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5857 | break; |
| 5858 | } |
| 5859 | return desired_class_load_kind; |
| 5860 | } |
| 5861 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5862 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5863 | if (cls->NeedsAccessCheck()) { |
| 5864 | InvokeRuntimeCallingConvention calling_convention; |
| 5865 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5866 | cls, |
| 5867 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5868 | Location::RegisterLocation(EAX), |
| 5869 | /* code_generator_supports_read_barrier */ true); |
| 5870 | return; |
| 5871 | } |
| 5872 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5873 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
| 5874 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5875 | ? LocationSummary::kCallOnSlowPath |
| 5876 | : LocationSummary::kNoCall; |
| 5877 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5878 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5879 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5880 | } |
| 5881 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5882 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5883 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5884 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5885 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 5886 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5887 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5888 | } |
| 5889 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5893 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5894 | if (cls->NeedsAccessCheck()) { |
| 5895 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 5896 | codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5897 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5898 | return; |
| 5899 | } |
| 5900 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5901 | Location out_loc = locations->Out(); |
| 5902 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5903 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5904 | bool generate_null_check = false; |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5905 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5906 | switch (cls->GetLoadKind()) { |
| 5907 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5908 | DCHECK(!cls->CanCallRuntime()); |
| 5909 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5910 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5911 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5912 | GenerateGcRootFieldLoad( |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5913 | cls, |
| 5914 | out_loc, |
| 5915 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), |
| 5916 | /*fixup_label*/ nullptr, |
| 5917 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5918 | break; |
| 5919 | } |
| 5920 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5921 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5922 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 5923 | codegen_->RecordTypePatch(cls); |
| 5924 | break; |
| 5925 | } |
| 5926 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5927 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5928 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 5929 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 5930 | codegen_->RecordTypePatch(cls); |
| 5931 | break; |
| 5932 | } |
| 5933 | case HLoadClass::LoadKind::kBootImageAddress: { |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5934 | DCHECK(!requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5935 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5936 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5937 | __ movl(out, Immediate(address)); |
| 5938 | codegen_->RecordSimplePatch(); |
| 5939 | break; |
| 5940 | } |
| 5941 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 5942 | DCHECK_NE(cls->GetAddress(), 0u); |
| 5943 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 5944 | // /* GcRoot<mirror::Class> */ out = *address |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5945 | GenerateGcRootFieldLoad(cls, |
| 5946 | out_loc, |
| 5947 | Address::Absolute(address), |
| 5948 | /*fixup_label*/ nullptr, |
| 5949 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5950 | generate_null_check = !cls->IsInDexCache(); |
| 5951 | break; |
| 5952 | } |
| 5953 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 5954 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 5955 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 5956 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 5957 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5958 | GenerateGcRootFieldLoad(cls, |
| 5959 | out_loc, |
| 5960 | Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), |
| 5961 | fixup_label, |
| 5962 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5963 | generate_null_check = !cls->IsInDexCache(); |
| 5964 | break; |
| 5965 | } |
| 5966 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 5967 | // /* GcRoot<mirror::Class>[] */ out = |
| 5968 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5969 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5970 | __ movl(out, Address(current_method, |
| 5971 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 5972 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 5973 | GenerateGcRootFieldLoad(cls, |
| 5974 | out_loc, |
| 5975 | Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())), |
| 5976 | /*fixup_label*/ nullptr, |
| 5977 | requires_read_barrier); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5978 | generate_null_check = !cls->IsInDexCache(); |
| 5979 | break; |
| 5980 | } |
| 5981 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5982 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5983 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 5984 | DCHECK(cls->CanCallRuntime()); |
| 5985 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5986 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5987 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5988 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5989 | if (generate_null_check) { |
| 5990 | __ testl(out, out); |
| 5991 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5992 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5993 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5994 | if (cls->MustGenerateClinitCheck()) { |
| 5995 | GenerateClassInitializationCheck(slow_path, out); |
| 5996 | } else { |
| 5997 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5998 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6003 | LocationSummary* locations = |
| 6004 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6005 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6006 | if (check->HasUses()) { |
| 6007 | locations->SetOut(Location::SameAsFirstInput()); |
| 6008 | } |
| 6009 | } |
| 6010 | |
| 6011 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6012 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6013 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6014 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6015 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6016 | GenerateClassInitializationCheck(slow_path, |
| 6017 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6018 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6019 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6020 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6021 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6022 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6023 | Immediate(mirror::Class::kStatusInitialized)); |
| 6024 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6025 | __ Bind(slow_path->GetExitLabel()); |
| 6026 | // No need for memory fence, thanks to the X86 memory model. |
| 6027 | } |
| 6028 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6029 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6030 | HLoadString::LoadKind desired_string_load_kind) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6031 | switch (desired_string_load_kind) { |
| 6032 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6033 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6034 | break; |
| 6035 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6036 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6037 | FALLTHROUGH_INTENDED; |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6038 | case HLoadString::LoadKind::kBssEntry: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6039 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6040 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6041 | // is incompatible with it. |
| 6042 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6043 | // with irreducible loops. |
| 6044 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6045 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6046 | } |
| 6047 | break; |
| 6048 | case HLoadString::LoadKind::kBootImageAddress: |
| 6049 | break; |
| 6050 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6051 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6052 | break; |
| 6053 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6054 | break; |
| 6055 | } |
| 6056 | return desired_string_load_kind; |
| 6057 | } |
| 6058 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6059 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6060 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6061 | ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod) |
| 6062 | ? LocationSummary::kCallOnMainOnly |
| 6063 | : LocationSummary::kCallOnSlowPath) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6064 | : LocationSummary::kNoCall; |
| 6065 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6066 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6067 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 6068 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6069 | load_kind == HLoadString::LoadKind::kBssEntry) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6070 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6071 | } |
Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6072 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod) { |
| 6073 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 6074 | } else { |
| 6075 | locations->SetOut(Location::RequiresRegister()); |
| 6076 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6080 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6081 | Location out_loc = locations->Out(); |
| 6082 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6083 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6084 | switch (load->GetLoadKind()) { |
| 6085 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6086 | __ movl(out, Immediate(/* placeholder */ 0)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6087 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6088 | return; // No dex cache slow path. |
| 6089 | } |
| 6090 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6091 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6092 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6093 | codegen_->RecordBootStringPatch(load); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6094 | return; // No dex cache slow path. |
| 6095 | } |
| 6096 | case HLoadString::LoadKind::kBootImageAddress: { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6097 | DCHECK_NE(load->GetAddress(), 0u); |
| 6098 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6099 | __ movl(out, Immediate(address)); |
| 6100 | codegen_->RecordSimplePatch(); |
| 6101 | return; // No dex cache slow path. |
| 6102 | } |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6103 | case HLoadString::LoadKind::kBssEntry: { |
| 6104 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6105 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); |
| 6106 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); |
| 6107 | // /* GcRoot<mirror::Class> */ out = *address /* PC-relative */ |
| 6108 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label); |
| 6109 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6110 | codegen_->AddSlowPath(slow_path); |
| 6111 | __ testl(out, out); |
| 6112 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6113 | __ Bind(slow_path->GetExitLabel()); |
| 6114 | return; |
| 6115 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6116 | default: |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6117 | break; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6118 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6119 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6120 | // 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] | 6121 | InvokeRuntimeCallingConvention calling_convention; |
| 6122 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex())); |
| 6123 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); |
| 6124 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6127 | static Address GetExceptionTlsAddress() { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6128 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6129 | } |
| 6130 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6131 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6132 | LocationSummary* locations = |
| 6133 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6134 | locations->SetOut(Location::RequiresRegister()); |
| 6135 | } |
| 6136 | |
| 6137 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6138 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6139 | } |
| 6140 | |
| 6141 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6142 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6143 | } |
| 6144 | |
| 6145 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6146 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
| 6149 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6150 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6151 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6152 | InvokeRuntimeCallingConvention calling_convention; |
| 6153 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6154 | } |
| 6155 | |
| 6156 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6157 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6158 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6159 | } |
| 6160 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6161 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6162 | return kEmitCompilerReadBarrier && |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6163 | !kUseBakerReadBarrier && |
| 6164 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6165 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6166 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6167 | } |
| 6168 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6169 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6170 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6171 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6172 | bool baker_read_barrier_slow_path = false; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6173 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6174 | case TypeCheckKind::kExactCheck: |
| 6175 | case TypeCheckKind::kAbstractClassCheck: |
| 6176 | case TypeCheckKind::kClassHierarchyCheck: |
| 6177 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6178 | call_kind = |
| 6179 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6180 | baker_read_barrier_slow_path = kUseBakerReadBarrier; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | break; |
| 6182 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6183 | case TypeCheckKind::kUnresolvedCheck: |
| 6184 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6185 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6186 | break; |
| 6187 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6188 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6189 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6190 | if (baker_read_barrier_slow_path) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6191 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6192 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6193 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6194 | locations->SetInAt(1, Location::Any()); |
| 6195 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6196 | locations->SetOut(Location::RequiresRegister()); |
| 6197 | // When read barriers are enabled, we need a temporary register for |
| 6198 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6199 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6200 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6201 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6202 | } |
| 6203 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6204 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6205 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6206 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6207 | Location obj_loc = locations->InAt(0); |
| 6208 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6209 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6210 | Location out_loc = locations->Out(); |
| 6211 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6212 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6213 | locations->GetTemp(0) : |
| 6214 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6215 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6216 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6217 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6218 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6219 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6220 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6221 | |
| 6222 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6223 | // Avoid null check if we know obj is not null. |
| 6224 | if (instruction->MustDoNullCheck()) { |
| 6225 | __ testl(obj, obj); |
| 6226 | __ j(kEqual, &zero); |
| 6227 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6228 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6229 | // /* HeapReference<Class> */ out = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6230 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6231 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6232 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6233 | case TypeCheckKind::kExactCheck: { |
| 6234 | if (cls.IsRegister()) { |
| 6235 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6236 | } else { |
| 6237 | DCHECK(cls.IsStackSlot()) << cls; |
| 6238 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6239 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6240 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6241 | // Classes must be equal for the instanceof to succeed. |
| 6242 | __ j(kNotEqual, &zero); |
| 6243 | __ movl(out, Immediate(1)); |
| 6244 | __ jmp(&done); |
| 6245 | break; |
| 6246 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6247 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6248 | case TypeCheckKind::kAbstractClassCheck: { |
| 6249 | // If the class is abstract, we eagerly fetch the super class of the |
| 6250 | // object to avoid doing a comparison we know will fail. |
| 6251 | NearLabel loop; |
| 6252 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6253 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6254 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6255 | __ testl(out, out); |
| 6256 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6257 | __ j(kEqual, &done); |
| 6258 | if (cls.IsRegister()) { |
| 6259 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6260 | } else { |
| 6261 | DCHECK(cls.IsStackSlot()) << cls; |
| 6262 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6263 | } |
| 6264 | __ j(kNotEqual, &loop); |
| 6265 | __ movl(out, Immediate(1)); |
| 6266 | if (zero.IsLinked()) { |
| 6267 | __ jmp(&done); |
| 6268 | } |
| 6269 | break; |
| 6270 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6272 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6273 | // Walk over the class hierarchy to find a match. |
| 6274 | NearLabel loop, success; |
| 6275 | __ Bind(&loop); |
| 6276 | if (cls.IsRegister()) { |
| 6277 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6278 | } else { |
| 6279 | DCHECK(cls.IsStackSlot()) << cls; |
| 6280 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6281 | } |
| 6282 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6284 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6285 | __ testl(out, out); |
| 6286 | __ j(kNotEqual, &loop); |
| 6287 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6288 | __ jmp(&done); |
| 6289 | __ Bind(&success); |
| 6290 | __ movl(out, Immediate(1)); |
| 6291 | if (zero.IsLinked()) { |
| 6292 | __ jmp(&done); |
| 6293 | } |
| 6294 | break; |
| 6295 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6296 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6297 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6298 | // Do an exact check. |
| 6299 | NearLabel exact_check; |
| 6300 | if (cls.IsRegister()) { |
| 6301 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6302 | } else { |
| 6303 | DCHECK(cls.IsStackSlot()) << cls; |
| 6304 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6305 | } |
| 6306 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6307 | // 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] | 6308 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6309 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6310 | __ testl(out, out); |
| 6311 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6312 | __ j(kEqual, &done); |
| 6313 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6314 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6315 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6316 | __ movl(out, Immediate(1)); |
| 6317 | __ jmp(&done); |
| 6318 | break; |
| 6319 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6320 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6321 | case TypeCheckKind::kArrayCheck: { |
| 6322 | if (cls.IsRegister()) { |
| 6323 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6324 | } else { |
| 6325 | DCHECK(cls.IsStackSlot()) << cls; |
| 6326 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6327 | } |
| 6328 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6329 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6330 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6331 | codegen_->AddSlowPath(slow_path); |
| 6332 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6333 | __ movl(out, Immediate(1)); |
| 6334 | if (zero.IsLinked()) { |
| 6335 | __ jmp(&done); |
| 6336 | } |
| 6337 | break; |
| 6338 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6339 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6340 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6341 | case TypeCheckKind::kInterfaceCheck: { |
| 6342 | // 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] | 6343 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6344 | // cases. |
| 6345 | // |
| 6346 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6347 | // entry point without resorting to a type checking slow path |
| 6348 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6349 | // require to assign fixed registers for the inputs of this |
| 6350 | // HInstanceOf instruction (following the runtime calling |
| 6351 | // convention), which might be cluttered by the potential first |
| 6352 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6353 | // |
| 6354 | // TODO: Introduce a new runtime entry point taking the object |
| 6355 | // to test (instead of its class) as argument, and let it deal |
| 6356 | // with the read barrier issues. This will let us refactor this |
| 6357 | // case of the `switch` code as it was previously (with a direct |
| 6358 | // call to the runtime not using a type checking slow path). |
| 6359 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6360 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6361 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6362 | /* is_fatal */ false); |
| 6363 | codegen_->AddSlowPath(slow_path); |
| 6364 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | if (zero.IsLinked()) { |
| 6366 | __ jmp(&done); |
| 6367 | } |
| 6368 | break; |
| 6369 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6370 | } |
| 6371 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6372 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6373 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6374 | __ xorl(out, out); |
| 6375 | } |
| 6376 | |
| 6377 | if (done.IsLinked()) { |
| 6378 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6379 | } |
| 6380 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6381 | if (slow_path != nullptr) { |
| 6382 | __ Bind(slow_path->GetExitLabel()); |
| 6383 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6386 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6387 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6388 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6389 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6390 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6391 | case TypeCheckKind::kExactCheck: |
| 6392 | case TypeCheckKind::kAbstractClassCheck: |
| 6393 | case TypeCheckKind::kClassHierarchyCheck: |
| 6394 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6395 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6396 | LocationSummary::kCallOnSlowPath : |
| 6397 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6398 | break; |
| 6399 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | case TypeCheckKind::kUnresolvedCheck: |
| 6401 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6402 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6403 | break; |
| 6404 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6407 | locations->SetInAt(1, Location::Any()); |
| 6408 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6409 | locations->AddTemp(Location::RequiresRegister()); |
| 6410 | // When read barriers are enabled, we need an additional temporary |
| 6411 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6412 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6413 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6414 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6418 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6419 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 | Location obj_loc = locations->InAt(0); |
| 6421 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6422 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | Location temp_loc = locations->GetTemp(0); |
| 6424 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6425 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6426 | locations->GetTemp(1) : |
| 6427 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6428 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6429 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6430 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6431 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6432 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6433 | bool is_type_check_slow_path_fatal = |
| 6434 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6435 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6436 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6437 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6438 | !instruction->CanThrowIntoCatchBlock(); |
| 6439 | SlowPathCode* type_check_slow_path = |
| 6440 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6441 | is_type_check_slow_path_fatal); |
| 6442 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6443 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6444 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6445 | // Avoid null check if we know obj is not null. |
| 6446 | if (instruction->MustDoNullCheck()) { |
| 6447 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6448 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6449 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6450 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6451 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6452 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6453 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6454 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6455 | case TypeCheckKind::kExactCheck: |
| 6456 | case TypeCheckKind::kArrayCheck: { |
| 6457 | if (cls.IsRegister()) { |
| 6458 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6459 | } else { |
| 6460 | DCHECK(cls.IsStackSlot()) << cls; |
| 6461 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6462 | } |
| 6463 | // Jump to slow path for throwing the exception or doing a |
| 6464 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6466 | break; |
| 6467 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6468 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6469 | case TypeCheckKind::kAbstractClassCheck: { |
| 6470 | // If the class is abstract, we eagerly fetch the super class of the |
| 6471 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6472 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6473 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6474 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6475 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6476 | |
| 6477 | // If the class reference currently in `temp` is not null, jump |
| 6478 | // to the `compare_classes` label to compare it with the checked |
| 6479 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6480 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6481 | __ j(kNotEqual, &compare_classes); |
| 6482 | // Otherwise, jump to the slow path to throw the exception. |
| 6483 | // |
| 6484 | // But before, move back the object's class into `temp` before |
| 6485 | // going into the slow path, as it has been overwritten in the |
| 6486 | // meantime. |
| 6487 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6488 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6489 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6490 | |
| 6491 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6492 | if (cls.IsRegister()) { |
| 6493 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6494 | } else { |
| 6495 | DCHECK(cls.IsStackSlot()) << cls; |
| 6496 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6497 | } |
| 6498 | __ j(kNotEqual, &loop); |
| 6499 | break; |
| 6500 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6501 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6502 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6503 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6504 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6505 | __ Bind(&loop); |
| 6506 | if (cls.IsRegister()) { |
| 6507 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6508 | } else { |
| 6509 | DCHECK(cls.IsStackSlot()) << cls; |
| 6510 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6511 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6512 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6513 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6514 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6515 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6516 | |
| 6517 | // If the class reference currently in `temp` is not null, jump |
| 6518 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6519 | __ testl(temp, temp); |
| 6520 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6521 | // Otherwise, jump to the slow path to throw the exception. |
| 6522 | // |
| 6523 | // But before, move back the object's class into `temp` before |
| 6524 | // going into the slow path, as it has been overwritten in the |
| 6525 | // meantime. |
| 6526 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6527 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6528 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6529 | break; |
| 6530 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6531 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6532 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6533 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6534 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6535 | if (cls.IsRegister()) { |
| 6536 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6537 | } else { |
| 6538 | DCHECK(cls.IsStackSlot()) << cls; |
| 6539 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6540 | } |
| 6541 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6542 | |
| 6543 | // 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] | 6544 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6545 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6546 | |
| 6547 | // If the component type is not null (i.e. the object is indeed |
| 6548 | // an array), jump to label `check_non_primitive_component_type` |
| 6549 | // to further check that this component type is not a primitive |
| 6550 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6551 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6552 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6553 | // Otherwise, jump to the slow path to throw the exception. |
| 6554 | // |
| 6555 | // But before, move back the object's class into `temp` before |
| 6556 | // going into the slow path, as it has been overwritten in the |
| 6557 | // meantime. |
| 6558 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6559 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6560 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6561 | |
| 6562 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6563 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6564 | __ j(kEqual, &done); |
| 6565 | // Same comment as above regarding `temp` and the slow path. |
| 6566 | // /* HeapReference<Class> */ temp = obj->klass_ |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6567 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6568 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6569 | break; |
| 6570 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6571 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6572 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6573 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6574 | // We always go into the type check slow path for the unresolved |
| 6575 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6576 | // |
| 6577 | // We cannot directly call the CheckCast runtime entry point |
| 6578 | // without resorting to a type checking slow path here (i.e. by |
| 6579 | // calling InvokeRuntime directly), as it would require to |
| 6580 | // assign fixed registers for the inputs of this HInstanceOf |
| 6581 | // instruction (following the runtime calling convention), which |
| 6582 | // might be cluttered by the potential first read barrier |
| 6583 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6584 | // |
| 6585 | // TODO: Introduce a new runtime entry point taking the object |
| 6586 | // to test (instead of its class) as argument, and let it deal |
| 6587 | // with the read barrier issues. This will let us refactor this |
| 6588 | // case of the `switch` code as it was previously (with a direct |
| 6589 | // call to the runtime not using a type checking slow path). |
| 6590 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6591 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6592 | break; |
| 6593 | } |
| 6594 | __ Bind(&done); |
| 6595 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6596 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6599 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6600 | LocationSummary* locations = |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 6601 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6602 | InvokeRuntimeCallingConvention calling_convention; |
| 6603 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6604 | } |
| 6605 | |
| 6606 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6607 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject |
| 6608 | : kQuickUnlockObject, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6609 | instruction, |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6610 | instruction->GetDexPc()); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6611 | if (instruction->IsEnter()) { |
| 6612 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6613 | } else { |
| 6614 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6615 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6616 | } |
| 6617 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6618 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6619 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6620 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6621 | |
| 6622 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6623 | LocationSummary* locations = |
| 6624 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6625 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6626 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6627 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6628 | locations->SetInAt(1, Location::Any()); |
| 6629 | locations->SetOut(Location::SameAsFirstInput()); |
| 6630 | } |
| 6631 | |
| 6632 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6633 | HandleBitwiseOperation(instruction); |
| 6634 | } |
| 6635 | |
| 6636 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6637 | HandleBitwiseOperation(instruction); |
| 6638 | } |
| 6639 | |
| 6640 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6641 | HandleBitwiseOperation(instruction); |
| 6642 | } |
| 6643 | |
| 6644 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6645 | LocationSummary* locations = instruction->GetLocations(); |
| 6646 | Location first = locations->InAt(0); |
| 6647 | Location second = locations->InAt(1); |
| 6648 | DCHECK(first.Equals(locations->Out())); |
| 6649 | |
| 6650 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6651 | if (second.IsRegister()) { |
| 6652 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6653 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6654 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6655 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6656 | } else { |
| 6657 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6658 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6659 | } |
| 6660 | } else if (second.IsConstant()) { |
| 6661 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6662 | __ andl(first.AsRegister<Register>(), |
| 6663 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6664 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6665 | __ orl(first.AsRegister<Register>(), |
| 6666 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6667 | } else { |
| 6668 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6669 | __ xorl(first.AsRegister<Register>(), |
| 6670 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6671 | } |
| 6672 | } else { |
| 6673 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6674 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6675 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6676 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6677 | } else { |
| 6678 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6679 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6680 | } |
| 6681 | } |
| 6682 | } else { |
| 6683 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6684 | if (second.IsRegisterPair()) { |
| 6685 | if (instruction->IsAnd()) { |
| 6686 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6687 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6688 | } else if (instruction->IsOr()) { |
| 6689 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6690 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6691 | } else { |
| 6692 | DCHECK(instruction->IsXor()); |
| 6693 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6694 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6695 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6696 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6697 | if (instruction->IsAnd()) { |
| 6698 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6699 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6700 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6701 | } else if (instruction->IsOr()) { |
| 6702 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6703 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6704 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6705 | } else { |
| 6706 | DCHECK(instruction->IsXor()); |
| 6707 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6708 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6709 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6710 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6711 | } else { |
| 6712 | DCHECK(second.IsConstant()) << second; |
| 6713 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6714 | int32_t low_value = Low32Bits(value); |
| 6715 | int32_t high_value = High32Bits(value); |
| 6716 | Immediate low(low_value); |
| 6717 | Immediate high(high_value); |
| 6718 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6719 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6720 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6721 | if (low_value == 0) { |
| 6722 | __ xorl(first_low, first_low); |
| 6723 | } else if (low_value != -1) { |
| 6724 | __ andl(first_low, low); |
| 6725 | } |
| 6726 | if (high_value == 0) { |
| 6727 | __ xorl(first_high, first_high); |
| 6728 | } else if (high_value != -1) { |
| 6729 | __ andl(first_high, high); |
| 6730 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6731 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6732 | if (low_value != 0) { |
| 6733 | __ orl(first_low, low); |
| 6734 | } |
| 6735 | if (high_value != 0) { |
| 6736 | __ orl(first_high, high); |
| 6737 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6738 | } else { |
| 6739 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6740 | if (low_value != 0) { |
| 6741 | __ xorl(first_low, low); |
| 6742 | } |
| 6743 | if (high_value != 0) { |
| 6744 | __ xorl(first_high, high); |
| 6745 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6746 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6747 | } |
| 6748 | } |
| 6749 | } |
| 6750 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6751 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6752 | Location out, |
| 6753 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6754 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6755 | Register out_reg = out.AsRegister<Register>(); |
| 6756 | if (kEmitCompilerReadBarrier) { |
| 6757 | if (kUseBakerReadBarrier) { |
| 6758 | // Load with fast path based Baker's read barrier. |
| 6759 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6760 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6761 | instruction, out, out_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6762 | } else { |
| 6763 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6764 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6765 | // in the following move operation, as we will need it for the |
| 6766 | // read barrier below. |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6767 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6768 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6769 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6770 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6771 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6772 | } |
| 6773 | } else { |
| 6774 | // Plain load with no read barrier. |
| 6775 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6776 | __ movl(out_reg, Address(out_reg, offset)); |
| 6777 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6778 | } |
| 6779 | } |
| 6780 | |
| 6781 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6782 | Location out, |
| 6783 | Location obj, |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6784 | uint32_t offset) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6785 | Register out_reg = out.AsRegister<Register>(); |
| 6786 | Register obj_reg = obj.AsRegister<Register>(); |
| 6787 | if (kEmitCompilerReadBarrier) { |
| 6788 | if (kUseBakerReadBarrier) { |
| 6789 | // Load with fast path based Baker's read barrier. |
| 6790 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6791 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6792 | instruction, out, obj_reg, offset, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6793 | } else { |
| 6794 | // Load with slow path based read barrier. |
| 6795 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6796 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6797 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6798 | } |
| 6799 | } else { |
| 6800 | // Plain load with no read barrier. |
| 6801 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6802 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6803 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6804 | } |
| 6805 | } |
| 6806 | |
| 6807 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6808 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6809 | const Address& address, |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6810 | Label* fixup_label, |
| 6811 | bool requires_read_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6812 | Register root_reg = root.AsRegister<Register>(); |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6813 | if (requires_read_barrier) { |
| 6814 | DCHECK(kEmitCompilerReadBarrier); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6815 | if (kUseBakerReadBarrier) { |
| 6816 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6817 | // Baker's read barrier are used: |
| 6818 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6819 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6820 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6821 | // root = ReadBarrier::Mark(root) |
| 6822 | // } |
| 6823 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6824 | // /* GcRoot<mirror::Object> */ root = *address |
| 6825 | __ movl(root_reg, address); |
| 6826 | if (fixup_label != nullptr) { |
| 6827 | __ Bind(fixup_label); |
| 6828 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6829 | static_assert( |
| 6830 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6831 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6832 | "have different sizes."); |
| 6833 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6834 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6835 | "have different sizes."); |
| 6836 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6837 | // Slow path marking the GC root `root`. |
| 6838 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 6839 | instruction, root, /* unpoison */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6840 | codegen_->AddSlowPath(slow_path); |
| 6841 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6842 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86PointerSize>().Int32Value()), |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6843 | Immediate(0)); |
| 6844 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6845 | __ Bind(slow_path->GetExitLabel()); |
| 6846 | } else { |
| 6847 | // GC root loaded through a slow path for read barriers other |
| 6848 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6849 | // /* GcRoot<mirror::Object>* */ root = address |
| 6850 | __ leal(root_reg, address); |
| 6851 | if (fixup_label != nullptr) { |
| 6852 | __ Bind(fixup_label); |
| 6853 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6854 | // /* mirror::Object* */ root = root->Read() |
| 6855 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6856 | } |
| 6857 | } else { |
| 6858 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6859 | // /* GcRoot<mirror::Object> */ root = *address |
| 6860 | __ movl(root_reg, address); |
| 6861 | if (fixup_label != nullptr) { |
| 6862 | __ Bind(fixup_label); |
| 6863 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6864 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6865 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6866 | } |
| 6867 | } |
| 6868 | |
| 6869 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6870 | Location ref, |
| 6871 | Register obj, |
| 6872 | uint32_t offset, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6873 | bool needs_null_check) { |
| 6874 | DCHECK(kEmitCompilerReadBarrier); |
| 6875 | DCHECK(kUseBakerReadBarrier); |
| 6876 | |
| 6877 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6878 | Address src(obj, offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6879 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6883 | Location ref, |
| 6884 | Register obj, |
| 6885 | uint32_t data_offset, |
| 6886 | Location index, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6887 | bool needs_null_check) { |
| 6888 | DCHECK(kEmitCompilerReadBarrier); |
| 6889 | DCHECK(kUseBakerReadBarrier); |
| 6890 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6891 | static_assert( |
| 6892 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6893 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6894 | // /* HeapReference<Object> */ ref = |
| 6895 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6896 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6897 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6901 | Location ref, |
| 6902 | Register obj, |
| 6903 | const Address& src, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6904 | bool needs_null_check) { |
| 6905 | DCHECK(kEmitCompilerReadBarrier); |
| 6906 | DCHECK(kUseBakerReadBarrier); |
| 6907 | |
| 6908 | // In slow path based read barriers, the read barrier call is |
| 6909 | // inserted after the original load. However, in fast path based |
| 6910 | // Baker's read barriers, we need to perform the load of |
| 6911 | // mirror::Object::monitor_ *before* the original reference load. |
| 6912 | // This load-load ordering is required by the read barrier. |
| 6913 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6914 | // |
| 6915 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6916 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6917 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6918 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6919 | // if (is_gray) { |
| 6920 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6921 | // } |
| 6922 | // |
| 6923 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6924 | // slightly more complex as: |
| 6925 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6926 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6927 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6928 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6929 | // - it performs additional checks that we do not do here for |
| 6930 | // performance reasons. |
| 6931 | |
| 6932 | Register ref_reg = ref.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6933 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6934 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6935 | // Given the numeric representation, it's enough to check the low bit of the rb_state. |
| 6936 | static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0"); |
| 6937 | static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1"); |
| 6938 | static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2"); |
| 6939 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 6940 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 6941 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 6942 | |
| 6943 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6944 | // ref = ReadBarrier::Mark(ref); |
| 6945 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 6946 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6947 | if (needs_null_check) { |
| 6948 | MaybeRecordImplicitNullCheck(instruction); |
| 6949 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6950 | |
| 6951 | // Load fence to prevent load-load reordering. |
| 6952 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6953 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6954 | |
| 6955 | // The actual reference load. |
| 6956 | // /* HeapReference<Object> */ ref = *src |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6957 | __ movl(ref_reg, src); // Flags are unaffected. |
| 6958 | |
| 6959 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. |
| 6960 | // Slow path marking the object `ref` when it is gray. |
| 6961 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86( |
| 6962 | instruction, ref, /* unpoison */ true); |
| 6963 | AddSlowPath(slow_path); |
| 6964 | |
| 6965 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 6966 | __ j(kNotZero, slow_path->GetEntryLabel()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6967 | |
| 6968 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6969 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6970 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6971 | __ Bind(slow_path->GetExitLabel()); |
| 6972 | } |
| 6973 | |
| 6974 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6975 | Location out, |
| 6976 | Location ref, |
| 6977 | Location obj, |
| 6978 | uint32_t offset, |
| 6979 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6980 | DCHECK(kEmitCompilerReadBarrier); |
| 6981 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6982 | // Insert a slow path based read barrier *after* the reference load. |
| 6983 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6984 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6985 | // reference will be carried out by the runtime within the slow |
| 6986 | // path. |
| 6987 | // |
| 6988 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6989 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6990 | // not used by the artReadBarrierSlow entry point. |
| 6991 | // |
| 6992 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6993 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6994 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6995 | AddSlowPath(slow_path); |
| 6996 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6997 | __ jmp(slow_path->GetEntryLabel()); |
| 6998 | __ Bind(slow_path->GetExitLabel()); |
| 6999 | } |
| 7000 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7001 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7002 | Location out, |
| 7003 | Location ref, |
| 7004 | Location obj, |
| 7005 | uint32_t offset, |
| 7006 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7007 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7008 | // Baker's read barriers shall be handled by the fast path |
| 7009 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7010 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7011 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7012 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7013 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7014 | } else if (kPoisonHeapReferences) { |
| 7015 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7016 | } |
| 7017 | } |
| 7018 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7019 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7020 | Location out, |
| 7021 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7022 | DCHECK(kEmitCompilerReadBarrier); |
| 7023 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7024 | // Insert a slow path based read barrier *after* the GC root load. |
| 7025 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7026 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7027 | // not need to do anything special for this here. |
| 7028 | SlowPathCode* slow_path = |
| 7029 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7030 | AddSlowPath(slow_path); |
| 7031 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7032 | __ jmp(slow_path->GetEntryLabel()); |
| 7033 | __ Bind(slow_path->GetExitLabel()); |
| 7034 | } |
| 7035 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7036 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7037 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7038 | LOG(FATAL) << "Unreachable"; |
| 7039 | } |
| 7040 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7041 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7042 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7043 | LOG(FATAL) << "Unreachable"; |
| 7044 | } |
| 7045 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7046 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7047 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7048 | LocationSummary* locations = |
| 7049 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7051 | } |
| 7052 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7053 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7054 | int32_t lower_bound, |
| 7055 | uint32_t num_entries, |
| 7056 | HBasicBlock* switch_block, |
| 7057 | HBasicBlock* default_block) { |
| 7058 | // Figure out the correct compare values and jump conditions. |
| 7059 | // Handle the first compare/branch as a special case because it might |
| 7060 | // jump to the default case. |
| 7061 | DCHECK_GT(num_entries, 2u); |
| 7062 | Condition first_condition; |
| 7063 | uint32_t index; |
| 7064 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7065 | if (lower_bound != 0) { |
| 7066 | first_condition = kLess; |
| 7067 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7068 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7069 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7070 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7071 | index = 1; |
| 7072 | } else { |
| 7073 | // Handle all the compare/jumps below. |
| 7074 | first_condition = kBelow; |
| 7075 | index = 0; |
| 7076 | } |
| 7077 | |
| 7078 | // Handle the rest of the compare/jumps. |
| 7079 | for (; index + 1 < num_entries; index += 2) { |
| 7080 | int32_t compare_to_value = lower_bound + index + 1; |
| 7081 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7082 | // Jump to successors[index] if value < case_value[index]. |
| 7083 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7084 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7085 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7086 | } |
| 7087 | |
| 7088 | if (index != num_entries) { |
| 7089 | // There are an odd number of entries. Handle the last one. |
| 7090 | DCHECK_EQ(index + 1, num_entries); |
| 7091 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7092 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7093 | } |
| 7094 | |
| 7095 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7096 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7097 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7098 | } |
| 7099 | } |
| 7100 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7101 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7102 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7103 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7104 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7105 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7106 | |
| 7107 | GenPackedSwitchWithCompares(value_reg, |
| 7108 | lower_bound, |
| 7109 | num_entries, |
| 7110 | switch_instr->GetBlock(), |
| 7111 | switch_instr->GetDefaultBlock()); |
| 7112 | } |
| 7113 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7114 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7115 | LocationSummary* locations = |
| 7116 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7117 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7118 | |
| 7119 | // Constant area pointer. |
| 7120 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7121 | |
| 7122 | // And the temporary we need. |
| 7123 | locations->AddTemp(Location::RequiresRegister()); |
| 7124 | } |
| 7125 | |
| 7126 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7127 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7128 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7129 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7130 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7131 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7132 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7133 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7134 | GenPackedSwitchWithCompares(value_reg, |
| 7135 | lower_bound, |
| 7136 | num_entries, |
| 7137 | switch_instr->GetBlock(), |
| 7138 | default_block); |
| 7139 | return; |
| 7140 | } |
| 7141 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7142 | // Optimizing has a jump area. |
| 7143 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7144 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7145 | |
| 7146 | // Remove the bias, if needed. |
| 7147 | if (lower_bound != 0) { |
| 7148 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7149 | value_reg = temp_reg; |
| 7150 | } |
| 7151 | |
| 7152 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7153 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7154 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7155 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7156 | |
| 7157 | // We are in the range of the table. |
| 7158 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7159 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7160 | |
| 7161 | // Compute the actual target address by adding in constant_area. |
| 7162 | __ addl(temp_reg, constant_area); |
| 7163 | |
| 7164 | // And jump. |
| 7165 | __ jmp(temp_reg); |
| 7166 | } |
| 7167 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7168 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7169 | HX86ComputeBaseMethodAddress* insn) { |
| 7170 | LocationSummary* locations = |
| 7171 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7172 | locations->SetOut(Location::RequiresRegister()); |
| 7173 | } |
| 7174 | |
| 7175 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7176 | HX86ComputeBaseMethodAddress* insn) { |
| 7177 | LocationSummary* locations = insn->GetLocations(); |
| 7178 | Register reg = locations->Out().AsRegister<Register>(); |
| 7179 | |
| 7180 | // Generate call to next instruction. |
| 7181 | Label next_instruction; |
| 7182 | __ call(&next_instruction); |
| 7183 | __ Bind(&next_instruction); |
| 7184 | |
| 7185 | // Remember this offset for later use with constant area. |
| 7186 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7187 | |
| 7188 | // Grab the return address off the stack. |
| 7189 | __ popl(reg); |
| 7190 | } |
| 7191 | |
| 7192 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7193 | HX86LoadFromConstantTable* insn) { |
| 7194 | LocationSummary* locations = |
| 7195 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7196 | |
| 7197 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7198 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7199 | |
| 7200 | // 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] | 7201 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7202 | return; |
| 7203 | } |
| 7204 | |
| 7205 | switch (insn->GetType()) { |
| 7206 | case Primitive::kPrimFloat: |
| 7207 | case Primitive::kPrimDouble: |
| 7208 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7209 | break; |
| 7210 | |
| 7211 | case Primitive::kPrimInt: |
| 7212 | locations->SetOut(Location::RequiresRegister()); |
| 7213 | break; |
| 7214 | |
| 7215 | default: |
| 7216 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7217 | } |
| 7218 | } |
| 7219 | |
| 7220 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7221 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7222 | return; |
| 7223 | } |
| 7224 | |
| 7225 | LocationSummary* locations = insn->GetLocations(); |
| 7226 | Location out = locations->Out(); |
| 7227 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7228 | HConstant *value = insn->GetConstant(); |
| 7229 | |
| 7230 | switch (insn->GetType()) { |
| 7231 | case Primitive::kPrimFloat: |
| 7232 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7233 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7234 | break; |
| 7235 | |
| 7236 | case Primitive::kPrimDouble: |
| 7237 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7238 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7239 | break; |
| 7240 | |
| 7241 | case Primitive::kPrimInt: |
| 7242 | __ movl(out.AsRegister<Register>(), |
| 7243 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7244 | break; |
| 7245 | |
| 7246 | default: |
| 7247 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7248 | } |
| 7249 | } |
| 7250 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7251 | /** |
| 7252 | * Class to handle late fixup of offsets into constant area. |
| 7253 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7254 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7255 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7256 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7257 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7258 | |
| 7259 | protected: |
| 7260 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7261 | |
| 7262 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7263 | |
| 7264 | private: |
| 7265 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7266 | // Patch the correct offset for the instruction. The place to patch is the |
| 7267 | // last 4 bytes of the instruction. |
| 7268 | // The value to patch is the distance from the offset in the constant area |
| 7269 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7270 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7271 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7272 | |
| 7273 | // Patch in the right value. |
| 7274 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7275 | } |
| 7276 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7277 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7278 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7279 | }; |
| 7280 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7281 | /** |
| 7282 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7283 | * constant area. |
| 7284 | */ |
| 7285 | class JumpTableRIPFixup : public RIPFixup { |
| 7286 | public: |
| 7287 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7288 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7289 | |
| 7290 | void CreateJumpTable() { |
| 7291 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7292 | |
| 7293 | // Ensure that the reference to the jump table has the correct offset. |
| 7294 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7295 | SetOffset(offset_in_constant_table); |
| 7296 | |
| 7297 | // The label values in the jump table are computed relative to the |
| 7298 | // instruction addressing the constant area. |
| 7299 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7300 | |
| 7301 | // Populate the jump table with the correct values for the jump table. |
| 7302 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7303 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7304 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7305 | // The value that we want is the target offset - the position of the table. |
| 7306 | for (int32_t i = 0; i < num_entries; i++) { |
| 7307 | HBasicBlock* b = successors[i]; |
| 7308 | Label* l = codegen_->GetLabelOf(b); |
| 7309 | DCHECK(l->IsBound()); |
| 7310 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7311 | assembler->AppendInt32(offset_to_block); |
| 7312 | } |
| 7313 | } |
| 7314 | |
| 7315 | private: |
| 7316 | const HX86PackedSwitch* switch_instr_; |
| 7317 | }; |
| 7318 | |
| 7319 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7320 | // Generate the constant area if needed. |
| 7321 | X86Assembler* assembler = GetAssembler(); |
| 7322 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7323 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7324 | // byte values. |
| 7325 | assembler->Align(4, 0); |
| 7326 | constant_area_start_ = assembler->CodeSize(); |
| 7327 | |
| 7328 | // Populate any jump tables. |
| 7329 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7330 | jump_table->CreateJumpTable(); |
| 7331 | } |
| 7332 | |
| 7333 | // And now add the constant area to the generated code. |
| 7334 | assembler->AddConstantArea(); |
| 7335 | } |
| 7336 | |
| 7337 | // And finish up. |
| 7338 | CodeGenerator::Finalize(allocator); |
| 7339 | } |
| 7340 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7341 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7342 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7343 | return Address(reg, kDummy32BitOffset, fixup); |
| 7344 | } |
| 7345 | |
| 7346 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7347 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7348 | return Address(reg, kDummy32BitOffset, fixup); |
| 7349 | } |
| 7350 | |
| 7351 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7352 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7353 | return Address(reg, kDummy32BitOffset, fixup); |
| 7354 | } |
| 7355 | |
| 7356 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7357 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7358 | return Address(reg, kDummy32BitOffset, fixup); |
| 7359 | } |
| 7360 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7361 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7362 | if (value == 0) { |
| 7363 | __ xorl(dest, dest); |
| 7364 | } else { |
| 7365 | __ movl(dest, Immediate(value)); |
| 7366 | } |
| 7367 | } |
| 7368 | |
| 7369 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7370 | if (value == 0) { |
| 7371 | __ testl(dest, dest); |
| 7372 | } else { |
| 7373 | __ cmpl(dest, Immediate(value)); |
| 7374 | } |
| 7375 | } |
| 7376 | |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7377 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 7378 | Register lhs_reg = lhs.AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7379 | GenerateIntCompare(lhs_reg, rhs); |
| 7380 | } |
| 7381 | |
| 7382 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7383 | if (rhs.IsConstant()) { |
| 7384 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7385 | Compare32BitValue(lhs, value); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7386 | } else if (rhs.IsStackSlot()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7387 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7388 | } else { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 7389 | __ cmpl(lhs, rhs.AsRegister<Register>()); |
Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7390 | } |
| 7391 | } |
| 7392 | |
| 7393 | Address CodeGeneratorX86::ArrayAddress(Register obj, |
| 7394 | Location index, |
| 7395 | ScaleFactor scale, |
| 7396 | uint32_t data_offset) { |
| 7397 | return index.IsConstant() ? |
| 7398 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : |
| 7399 | Address(obj, index.AsRegister<Register>(), scale, data_offset); |
| 7400 | } |
| 7401 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7402 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7403 | Register reg, |
| 7404 | Register value) { |
| 7405 | // Create a fixup to be used to create and address the jump table. |
| 7406 | JumpTableRIPFixup* table_fixup = |
| 7407 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7408 | |
| 7409 | // We have to populate the jump tables. |
| 7410 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7411 | |
| 7412 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7413 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7414 | } |
| 7415 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7416 | // TODO: target as memory. |
| 7417 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7418 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7419 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7420 | return; |
| 7421 | } |
| 7422 | |
| 7423 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7424 | |
| 7425 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7426 | if (target.Equals(return_loc)) { |
| 7427 | return; |
| 7428 | } |
| 7429 | |
| 7430 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7431 | // with the else branch. |
| 7432 | if (type == Primitive::kPrimLong) { |
| 7433 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7434 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7435 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7436 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7437 | } else { |
| 7438 | // Let the parallel move resolver take care of all of this. |
| 7439 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7440 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7441 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7442 | } |
| 7443 | } |
| 7444 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7445 | #undef __ |
| 7446 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7447 | } // namespace x86 |
| 7448 | } // namespace art |