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 | |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 50 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, 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 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 78 | }; |
| 79 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 80 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 82 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 84 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 87 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 88 | // Live registers will be restored in the catch block if caught. |
| 89 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 90 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 92 | instruction_, |
| 93 | instruction_->GetDexPc(), |
| 94 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 95 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 98 | bool IsFatal() const OVERRIDE { return true; } |
| 99 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 100 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 101 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 104 | }; |
| 105 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 106 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 108 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 109 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 111 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(reg_); |
| 115 | } else { |
| 116 | __ movl(reg_, Immediate(0)); |
| 117 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | __ jmp(GetExitLabel()); |
| 119 | } |
| 120 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 121 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 122 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | private: |
| 124 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | bool is_div_; |
| 126 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 129 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 131 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 133 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 134 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 135 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 136 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 137 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 138 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 139 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 140 | // Live registers will be restored in the catch block if caught. |
| 141 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 142 | } |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 143 | |
| 144 | // Are we using an array length from memory? |
| 145 | HInstruction* array_length = instruction_->InputAt(1); |
| 146 | Location length_loc = locations->InAt(1); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 147 | InvokeRuntimeCallingConvention calling_convention; |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 148 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { |
| 149 | // Load the array length into our temporary. |
| 150 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 151 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 152 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 153 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); |
| 154 | // Check for conflicts with index. |
| 155 | if (length_loc.Equals(locations->InAt(0))) { |
| 156 | // We know we aren't using parameter 2. |
| 157 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); |
| 158 | } |
| 159 | __ movl(length_loc.AsRegister<Register>(), array_len); |
| 160 | } |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 161 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 162 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 163 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 164 | Primitive::kPrimInt, |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 165 | length_loc, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 166 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 167 | Primitive::kPrimInt); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 168 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 169 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 170 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 171 | x86_codegen->InvokeRuntime(entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 172 | instruction_, |
| 173 | instruction_->GetDexPc(), |
| 174 | this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 175 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 176 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 179 | bool IsFatal() const OVERRIDE { return true; } |
| 180 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 181 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 182 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 183 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 184 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 185 | }; |
| 186 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 187 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 189 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 190 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 192 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 193 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 194 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 195 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 196 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 197 | instruction_, |
| 198 | instruction_->GetDexPc(), |
| 199 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 200 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 201 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 202 | if (successor_ == nullptr) { |
| 203 | __ jmp(GetReturnLabel()); |
| 204 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 205 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 206 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 209 | Label* GetReturnLabel() { |
| 210 | DCHECK(successor_ == nullptr); |
| 211 | return &return_label_; |
| 212 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 213 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 214 | HBasicBlock* GetSuccessor() const { |
| 215 | return successor_; |
| 216 | } |
| 217 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 218 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 219 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 220 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 221 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 222 | Label return_label_; |
| 223 | |
| 224 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 225 | }; |
| 226 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 227 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 228 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 229 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 231 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 232 | LocationSummary* locations = instruction_->GetLocations(); |
| 233 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 234 | |
| 235 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 236 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 237 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 238 | |
| 239 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 240 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 241 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 242 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 243 | instruction_, |
| 244 | instruction_->GetDexPc(), |
| 245 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 246 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 247 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 248 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 249 | |
| 250 | __ jmp(GetExitLabel()); |
| 251 | } |
| 252 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 253 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 254 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 255 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 256 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 257 | }; |
| 258 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 259 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 260 | public: |
| 261 | LoadClassSlowPathX86(HLoadClass* cls, |
| 262 | HInstruction* at, |
| 263 | uint32_t dex_pc, |
| 264 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 265 | : 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] | 266 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 267 | } |
| 268 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 269 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | LocationSummary* locations = at_->GetLocations(); |
| 271 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 272 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 273 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | |
| 275 | InvokeRuntimeCallingConvention calling_convention; |
| 276 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 277 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 278 | : QUICK_ENTRY_POINT(pInitializeType), |
| 279 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 280 | if (do_clinit_) { |
| 281 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 282 | } else { |
| 283 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 284 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 285 | |
| 286 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 287 | Location out = locations->Out(); |
| 288 | if (out.IsValid()) { |
| 289 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 290 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 291 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 293 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 294 | __ jmp(GetExitLabel()); |
| 295 | } |
| 296 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 297 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 298 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 299 | private: |
| 300 | // The class this slow path will load. |
| 301 | HLoadClass* const cls_; |
| 302 | |
| 303 | // The instruction where this slow path is happening. |
| 304 | // (Might be the load class or an initialization check). |
| 305 | HInstruction* const at_; |
| 306 | |
| 307 | // The dex PC of `at_`. |
| 308 | const uint32_t dex_pc_; |
| 309 | |
| 310 | // Whether to initialize the class. |
| 311 | const bool do_clinit_; |
| 312 | |
| 313 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 314 | }; |
| 315 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 316 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 318 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 319 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 320 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 321 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 322 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 324 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | DCHECK(instruction_->IsCheckCast() |
| 326 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
| 328 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 329 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 330 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 331 | if (!is_fatal_) { |
| 332 | SaveLiveRegisters(codegen, locations); |
| 333 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 334 | |
| 335 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 336 | // move resolver. |
| 337 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 338 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 339 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 340 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 341 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 342 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 343 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 344 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 346 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 347 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 348 | instruction_, |
| 349 | instruction_->GetDexPc(), |
| 350 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 351 | CheckEntrypointTypes< |
| 352 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | } else { |
| 354 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 355 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 356 | instruction_, |
| 357 | instruction_->GetDexPc(), |
| 358 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 359 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 362 | if (!is_fatal_) { |
| 363 | if (instruction_->IsInstanceOf()) { |
| 364 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 365 | } |
| 366 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 367 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | __ jmp(GetExitLabel()); |
| 369 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 372 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 373 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 374 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 375 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 376 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 377 | |
| 378 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 379 | }; |
| 380 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 381 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 383 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 384 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 387 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 388 | __ Bind(GetEntryLabel()); |
| 389 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 390 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 391 | instruction_, |
| 392 | instruction_->GetDexPc(), |
| 393 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 394 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 397 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 398 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 399 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 400 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 401 | }; |
| 402 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 403 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 404 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 405 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 406 | |
| 407 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 408 | LocationSummary* locations = instruction_->GetLocations(); |
| 409 | __ Bind(GetEntryLabel()); |
| 410 | SaveLiveRegisters(codegen, locations); |
| 411 | |
| 412 | InvokeRuntimeCallingConvention calling_convention; |
| 413 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 414 | parallel_move.AddMove( |
| 415 | locations->InAt(0), |
| 416 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 417 | Primitive::kPrimNot, |
| 418 | nullptr); |
| 419 | parallel_move.AddMove( |
| 420 | locations->InAt(1), |
| 421 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 422 | Primitive::kPrimInt, |
| 423 | nullptr); |
| 424 | parallel_move.AddMove( |
| 425 | locations->InAt(2), |
| 426 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 427 | Primitive::kPrimNot, |
| 428 | nullptr); |
| 429 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 430 | |
| 431 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 432 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 433 | instruction_, |
| 434 | instruction_->GetDexPc(), |
| 435 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 436 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 437 | RestoreLiveRegisters(codegen, locations); |
| 438 | __ jmp(GetExitLabel()); |
| 439 | } |
| 440 | |
| 441 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 442 | |
| 443 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 444 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 445 | }; |
| 446 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 447 | // Slow path marking an object during a read barrier. |
| 448 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 449 | public: |
| 450 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 451 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 452 | DCHECK(kEmitCompilerReadBarrier); |
| 453 | } |
| 454 | |
| 455 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 456 | |
| 457 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 458 | LocationSummary* locations = instruction_->GetLocations(); |
| 459 | Register reg_out = out_.AsRegister<Register>(); |
| 460 | DCHECK(locations->CanCall()); |
| 461 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 462 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 463 | instruction_->IsStaticFieldGet() || |
| 464 | instruction_->IsArrayGet() || |
| 465 | instruction_->IsLoadClass() || |
| 466 | instruction_->IsLoadString() || |
| 467 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 468 | instruction_->IsCheckCast() || |
| 469 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
| 470 | instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 471 | << "Unexpected instruction in read barrier marking slow path: " |
| 472 | << instruction_->DebugName(); |
| 473 | |
| 474 | __ Bind(GetEntryLabel()); |
| 475 | SaveLiveRegisters(codegen, locations); |
| 476 | |
| 477 | InvokeRuntimeCallingConvention calling_convention; |
| 478 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 479 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 480 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 481 | instruction_, |
| 482 | instruction_->GetDexPc(), |
| 483 | this); |
| 484 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 485 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 486 | |
| 487 | RestoreLiveRegisters(codegen, locations); |
| 488 | __ jmp(GetExitLabel()); |
| 489 | } |
| 490 | |
| 491 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 492 | const Location out_; |
| 493 | const Location obj_; |
| 494 | |
| 495 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 496 | }; |
| 497 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 498 | // Slow path generating a read barrier for a heap reference. |
| 499 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 500 | public: |
| 501 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 502 | Location out, |
| 503 | Location ref, |
| 504 | Location obj, |
| 505 | uint32_t offset, |
| 506 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 507 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 508 | out_(out), |
| 509 | ref_(ref), |
| 510 | obj_(obj), |
| 511 | offset_(offset), |
| 512 | index_(index) { |
| 513 | DCHECK(kEmitCompilerReadBarrier); |
| 514 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 515 | // has been overwritten by (or after) the heap object reference load |
| 516 | // to be instrumented, e.g.: |
| 517 | // |
| 518 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 519 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 520 | // |
| 521 | // In that case, we have lost the information about the original |
| 522 | // object, and the emitted read barrier cannot work properly. |
| 523 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 524 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 525 | } |
| 526 | |
| 527 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 528 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 529 | LocationSummary* locations = instruction_->GetLocations(); |
| 530 | Register reg_out = out_.AsRegister<Register>(); |
| 531 | DCHECK(locations->CanCall()); |
| 532 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 533 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 534 | instruction_->IsStaticFieldGet() || |
| 535 | instruction_->IsArrayGet() || |
| 536 | instruction_->IsInstanceOf() || |
| 537 | instruction_->IsCheckCast() || |
| 538 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 539 | instruction_->GetLocations()->Intrinsified())) |
| 540 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 541 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 542 | |
| 543 | __ Bind(GetEntryLabel()); |
| 544 | SaveLiveRegisters(codegen, locations); |
| 545 | |
| 546 | // We may have to change the index's value, but as `index_` is a |
| 547 | // constant member (like other "inputs" of this slow path), |
| 548 | // introduce a copy of it, `index`. |
| 549 | Location index = index_; |
| 550 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 551 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 552 | if (instruction_->IsArrayGet()) { |
| 553 | // Compute the actual memory offset and store it in `index`. |
| 554 | Register index_reg = index_.AsRegister<Register>(); |
| 555 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 556 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 557 | // We are about to change the value of `index_reg` (see the |
| 558 | // calls to art::x86::X86Assembler::shll and |
| 559 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 560 | // not been saved by the previous call to |
| 561 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 562 | // callee-save register -- |
| 563 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 564 | // callee-save registers, as it has been designed with the |
| 565 | // assumption that callee-save registers are supposed to be |
| 566 | // handled by the called function. So, as a callee-save |
| 567 | // register, `index_reg` _would_ eventually be saved onto |
| 568 | // the stack, but it would be too late: we would have |
| 569 | // changed its value earlier. Therefore, we manually save |
| 570 | // it here into another freely available register, |
| 571 | // `free_reg`, chosen of course among the caller-save |
| 572 | // registers (as a callee-save `free_reg` register would |
| 573 | // exhibit the same problem). |
| 574 | // |
| 575 | // Note we could have requested a temporary register from |
| 576 | // the register allocator instead; but we prefer not to, as |
| 577 | // this is a slow path, and we know we can find a |
| 578 | // caller-save register that is available. |
| 579 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 580 | __ movl(free_reg, index_reg); |
| 581 | index_reg = free_reg; |
| 582 | index = Location::RegisterLocation(index_reg); |
| 583 | } else { |
| 584 | // The initial register stored in `index_` has already been |
| 585 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 586 | // (as it is not a callee-save register), so we can freely |
| 587 | // use it. |
| 588 | } |
| 589 | // Shifting the index value contained in `index_reg` by the scale |
| 590 | // factor (2) cannot overflow in practice, as the runtime is |
| 591 | // unable to allocate object arrays with a size larger than |
| 592 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 593 | __ shll(index_reg, Immediate(TIMES_4)); |
| 594 | static_assert( |
| 595 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 596 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 597 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 598 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 599 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 600 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 601 | // (as in the case of ArrayGet), as it is actually an offset |
| 602 | // to an object field within an object. |
| 603 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 604 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 605 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 606 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 607 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 608 | DCHECK_EQ(offset_, 0U); |
| 609 | DCHECK(index_.IsRegisterPair()); |
| 610 | // UnsafeGet's offset location is a register pair, the low |
| 611 | // part contains the correct offset. |
| 612 | index = index_.ToLow(); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | // We're moving two or three locations to locations that could |
| 617 | // overlap, so we need a parallel move resolver. |
| 618 | InvokeRuntimeCallingConvention calling_convention; |
| 619 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 620 | parallel_move.AddMove(ref_, |
| 621 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 622 | Primitive::kPrimNot, |
| 623 | nullptr); |
| 624 | parallel_move.AddMove(obj_, |
| 625 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 626 | Primitive::kPrimNot, |
| 627 | nullptr); |
| 628 | if (index.IsValid()) { |
| 629 | parallel_move.AddMove(index, |
| 630 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 631 | Primitive::kPrimInt, |
| 632 | nullptr); |
| 633 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 634 | } else { |
| 635 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 636 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 637 | } |
| 638 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 639 | instruction_, |
| 640 | instruction_->GetDexPc(), |
| 641 | this); |
| 642 | CheckEntrypointTypes< |
| 643 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 644 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 645 | |
| 646 | RestoreLiveRegisters(codegen, locations); |
| 647 | __ jmp(GetExitLabel()); |
| 648 | } |
| 649 | |
| 650 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 651 | |
| 652 | private: |
| 653 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 654 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 655 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 656 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 657 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 658 | return static_cast<Register>(i); |
| 659 | } |
| 660 | } |
| 661 | // We shall never fail to find a free caller-save register, as |
| 662 | // there are more than two core caller-save registers on x86 |
| 663 | // (meaning it is possible to find one which is different from |
| 664 | // `ref` and `obj`). |
| 665 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 666 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 667 | UNREACHABLE(); |
| 668 | } |
| 669 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 670 | const Location out_; |
| 671 | const Location ref_; |
| 672 | const Location obj_; |
| 673 | const uint32_t offset_; |
| 674 | // An additional location containing an index to an array. |
| 675 | // Only used for HArrayGet and the UnsafeGetObject & |
| 676 | // UnsafeGetObjectVolatile intrinsics. |
| 677 | const Location index_; |
| 678 | |
| 679 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 680 | }; |
| 681 | |
| 682 | // Slow path generating a read barrier for a GC root. |
| 683 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 684 | public: |
| 685 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 686 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 687 | DCHECK(kEmitCompilerReadBarrier); |
| 688 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 689 | |
| 690 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 691 | LocationSummary* locations = instruction_->GetLocations(); |
| 692 | Register reg_out = out_.AsRegister<Register>(); |
| 693 | DCHECK(locations->CanCall()); |
| 694 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 695 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 696 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 697 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 698 | |
| 699 | __ Bind(GetEntryLabel()); |
| 700 | SaveLiveRegisters(codegen, locations); |
| 701 | |
| 702 | InvokeRuntimeCallingConvention calling_convention; |
| 703 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 704 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 705 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 706 | instruction_, |
| 707 | instruction_->GetDexPc(), |
| 708 | this); |
| 709 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 710 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 711 | |
| 712 | RestoreLiveRegisters(codegen, locations); |
| 713 | __ jmp(GetExitLabel()); |
| 714 | } |
| 715 | |
| 716 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 717 | |
| 718 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 719 | const Location out_; |
| 720 | const Location root_; |
| 721 | |
| 722 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 723 | }; |
| 724 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 725 | #undef __ |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 726 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 727 | #define __ down_cast<X86Assembler*>(GetAssembler())-> /* NOLINT */ |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 728 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 729 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 730 | switch (cond) { |
| 731 | case kCondEQ: return kEqual; |
| 732 | case kCondNE: return kNotEqual; |
| 733 | case kCondLT: return kLess; |
| 734 | case kCondLE: return kLessEqual; |
| 735 | case kCondGT: return kGreater; |
| 736 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 737 | case kCondB: return kBelow; |
| 738 | case kCondBE: return kBelowEqual; |
| 739 | case kCondA: return kAbove; |
| 740 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 741 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 742 | LOG(FATAL) << "Unreachable"; |
| 743 | UNREACHABLE(); |
| 744 | } |
| 745 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 746 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 747 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 748 | switch (cond) { |
| 749 | case kCondEQ: return kEqual; |
| 750 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 751 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 752 | case kCondLT: return kBelow; |
| 753 | case kCondLE: return kBelowEqual; |
| 754 | case kCondGT: return kAbove; |
| 755 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 756 | // Unsigned remain unchanged. |
| 757 | case kCondB: return kBelow; |
| 758 | case kCondBE: return kBelowEqual; |
| 759 | case kCondA: return kAbove; |
| 760 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 761 | } |
| 762 | LOG(FATAL) << "Unreachable"; |
| 763 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 766 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 767 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 771 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 772 | } |
| 773 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 774 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 775 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 776 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 777 | } |
| 778 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 779 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 780 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 781 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 784 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 785 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 786 | return GetFloatingPointSpillSlotSize(); |
| 787 | } |
| 788 | |
| 789 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 790 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 791 | return GetFloatingPointSpillSlotSize(); |
| 792 | } |
| 793 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 794 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 795 | HInstruction* instruction, |
| 796 | uint32_t dex_pc, |
| 797 | SlowPathCode* slow_path) { |
| 798 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 799 | instruction, |
| 800 | dex_pc, |
| 801 | slow_path); |
| 802 | } |
| 803 | |
| 804 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 805 | HInstruction* instruction, |
| 806 | uint32_t dex_pc, |
| 807 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 808 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 809 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 810 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 811 | } |
| 812 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 813 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 814 | const X86InstructionSetFeatures& isa_features, |
| 815 | const CompilerOptions& compiler_options, |
| 816 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 817 | : CodeGenerator(graph, |
| 818 | kNumberOfCpuRegisters, |
| 819 | kNumberOfXmmRegisters, |
| 820 | kNumberOfRegisterPairs, |
| 821 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 822 | arraysize(kCoreCalleeSaves)) |
| 823 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 824 | 0, |
| 825 | compiler_options, |
| 826 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 827 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 828 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 829 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 830 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 831 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 832 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 833 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 834 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 835 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 836 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 837 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 838 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 839 | constant_area_start_(-1), |
| 840 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 841 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 842 | // Use a fake return address register to mimic Quick. |
| 843 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 844 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 845 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 846 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 847 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 848 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 849 | |
| 850 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 851 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 852 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 853 | UpdateBlockedPairRegisters(); |
| 854 | } |
| 855 | |
| 856 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 857 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 858 | X86ManagedRegister current = |
| 859 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 860 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 861 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 862 | blocked_register_pairs_[i] = true; |
| 863 | } |
| 864 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 867 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 868 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 869 | assembler_(codegen->GetAssembler()), |
| 870 | codegen_(codegen) {} |
| 871 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 872 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 873 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 874 | } |
| 875 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 876 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 877 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 878 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 879 | bool skip_overflow_check = |
| 880 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 881 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 882 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 883 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 884 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 885 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 886 | } |
| 887 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 888 | if (HasEmptyFrame()) { |
| 889 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 890 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 891 | |
| 892 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 893 | Register reg = kCoreCalleeSaves[i]; |
| 894 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 895 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 896 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 897 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 901 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 902 | __ subl(ESP, Immediate(adjust)); |
| 903 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 904 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 908 | __ cfi().RememberState(); |
| 909 | if (!HasEmptyFrame()) { |
| 910 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 911 | __ addl(ESP, Immediate(adjust)); |
| 912 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 913 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 914 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 915 | Register reg = kCoreCalleeSaves[i]; |
| 916 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 917 | __ popl(reg); |
| 918 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 919 | __ cfi().Restore(DWARFReg(reg)); |
| 920 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 921 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 922 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 923 | __ ret(); |
| 924 | __ cfi().RestoreState(); |
| 925 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 928 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 929 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 932 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 933 | switch (type) { |
| 934 | case Primitive::kPrimBoolean: |
| 935 | case Primitive::kPrimByte: |
| 936 | case Primitive::kPrimChar: |
| 937 | case Primitive::kPrimShort: |
| 938 | case Primitive::kPrimInt: |
| 939 | case Primitive::kPrimNot: |
| 940 | return Location::RegisterLocation(EAX); |
| 941 | |
| 942 | case Primitive::kPrimLong: |
| 943 | return Location::RegisterPairLocation(EAX, EDX); |
| 944 | |
| 945 | case Primitive::kPrimVoid: |
| 946 | return Location::NoLocation(); |
| 947 | |
| 948 | case Primitive::kPrimDouble: |
| 949 | case Primitive::kPrimFloat: |
| 950 | return Location::FpuRegisterLocation(XMM0); |
| 951 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 952 | |
| 953 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 957 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 958 | } |
| 959 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 960 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 961 | switch (type) { |
| 962 | case Primitive::kPrimBoolean: |
| 963 | case Primitive::kPrimByte: |
| 964 | case Primitive::kPrimChar: |
| 965 | case Primitive::kPrimShort: |
| 966 | case Primitive::kPrimInt: |
| 967 | case Primitive::kPrimNot: { |
| 968 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 969 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 970 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 971 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 972 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 973 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 974 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 975 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 976 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 977 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 978 | uint32_t index = gp_index_; |
| 979 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 980 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 981 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 982 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 983 | calling_convention.GetRegisterPairAt(index)); |
| 984 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 985 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 986 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 991 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 992 | stack_index_++; |
| 993 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 994 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 995 | } else { |
| 996 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1001 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1002 | stack_index_ += 2; |
| 1003 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1004 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1005 | } else { |
| 1006 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1010 | case Primitive::kPrimVoid: |
| 1011 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1012 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1013 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1014 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1015 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1016 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1017 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1018 | if (source.Equals(destination)) { |
| 1019 | return; |
| 1020 | } |
| 1021 | if (destination.IsRegister()) { |
| 1022 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1023 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1024 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1025 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1026 | } else { |
| 1027 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1028 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1029 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1030 | } else if (destination.IsFpuRegister()) { |
| 1031 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1032 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1033 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1034 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1035 | } else { |
| 1036 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1037 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1038 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1039 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1040 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1041 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1042 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1043 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1044 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1045 | } else if (source.IsConstant()) { |
| 1046 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1047 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1048 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1049 | } else { |
| 1050 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1051 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1052 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1058 | if (source.Equals(destination)) { |
| 1059 | return; |
| 1060 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1061 | if (destination.IsRegisterPair()) { |
| 1062 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1063 | EmitParallelMoves( |
| 1064 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1065 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1066 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1067 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1068 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1069 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1070 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1071 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1072 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1073 | __ psrlq(src_reg, Immediate(32)); |
| 1074 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1075 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1076 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1077 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1078 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1079 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1080 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1081 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1082 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1083 | if (source.IsFpuRegister()) { |
| 1084 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1085 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1086 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1087 | } else if (source.IsRegisterPair()) { |
| 1088 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1089 | // Create stack space for 2 elements. |
| 1090 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1091 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1092 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1093 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1094 | // And remove the temporary stack space we allocated. |
| 1095 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1096 | } else { |
| 1097 | LOG(FATAL) << "Unimplemented"; |
| 1098 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1099 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1100 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1101 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1102 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1103 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1104 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1105 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1106 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1107 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1108 | } else if (source.IsConstant()) { |
| 1109 | HConstant* constant = source.GetConstant(); |
| 1110 | int64_t value; |
| 1111 | if (constant->IsLongConstant()) { |
| 1112 | value = constant->AsLongConstant()->GetValue(); |
| 1113 | } else { |
| 1114 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1115 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1116 | } |
| 1117 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1118 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1119 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1120 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1121 | EmitParallelMoves( |
| 1122 | Location::StackSlot(source.GetStackIndex()), |
| 1123 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1124 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1125 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1126 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1127 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1132 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1133 | DCHECK(location.IsRegister()); |
| 1134 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1135 | } |
| 1136 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1137 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1138 | HParallelMove move(GetGraph()->GetArena()); |
| 1139 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1140 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1141 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1142 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1143 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1144 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1145 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1149 | if (location.IsRegister()) { |
| 1150 | locations->AddTemp(location); |
| 1151 | } else if (location.IsRegisterPair()) { |
| 1152 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1153 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1154 | } else { |
| 1155 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1156 | } |
| 1157 | } |
| 1158 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1159 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1160 | DCHECK(!successor->IsExitBlock()); |
| 1161 | |
| 1162 | HBasicBlock* block = got->GetBlock(); |
| 1163 | HInstruction* previous = got->GetPrevious(); |
| 1164 | |
| 1165 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1166 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1167 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1172 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1173 | } |
| 1174 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1175 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1179 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1180 | got->SetLocations(nullptr); |
| 1181 | } |
| 1182 | |
| 1183 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1184 | HandleGoto(got, got->GetSuccessor()); |
| 1185 | } |
| 1186 | |
| 1187 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1188 | try_boundary->SetLocations(nullptr); |
| 1189 | } |
| 1190 | |
| 1191 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1192 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1193 | if (!successor->IsExitBlock()) { |
| 1194 | HandleGoto(try_boundary, successor); |
| 1195 | } |
| 1196 | } |
| 1197 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1198 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1199 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1202 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1205 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1206 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1207 | LabelType* true_label, |
| 1208 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1209 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1210 | __ j(kUnordered, true_label); |
| 1211 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1212 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1213 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1214 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1215 | } |
| 1216 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1217 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1218 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1219 | LabelType* true_label, |
| 1220 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1221 | LocationSummary* locations = cond->GetLocations(); |
| 1222 | Location left = locations->InAt(0); |
| 1223 | Location right = locations->InAt(1); |
| 1224 | IfCondition if_cond = cond->GetCondition(); |
| 1225 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1226 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1227 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1228 | IfCondition true_high_cond = if_cond; |
| 1229 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1230 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1231 | |
| 1232 | // Set the conditions for the test, remembering that == needs to be |
| 1233 | // decided using the low words. |
| 1234 | switch (if_cond) { |
| 1235 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1236 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1237 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1238 | break; |
| 1239 | case kCondLT: |
| 1240 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1241 | break; |
| 1242 | case kCondLE: |
| 1243 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1244 | break; |
| 1245 | case kCondGT: |
| 1246 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1247 | break; |
| 1248 | case kCondGE: |
| 1249 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1250 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1251 | case kCondB: |
| 1252 | false_high_cond = kCondA; |
| 1253 | break; |
| 1254 | case kCondBE: |
| 1255 | true_high_cond = kCondB; |
| 1256 | break; |
| 1257 | case kCondA: |
| 1258 | false_high_cond = kCondB; |
| 1259 | break; |
| 1260 | case kCondAE: |
| 1261 | true_high_cond = kCondA; |
| 1262 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | if (right.IsConstant()) { |
| 1266 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1267 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1268 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1270 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1271 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1272 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1273 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1274 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1276 | __ j(X86Condition(true_high_cond), true_label); |
| 1277 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1278 | } |
| 1279 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1280 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1281 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1282 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1283 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1284 | |
| 1285 | __ cmpl(left_high, right_high); |
| 1286 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1287 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1289 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1291 | __ j(X86Condition(true_high_cond), true_label); |
| 1292 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | } |
| 1294 | // Must be equal high, so compare the lows. |
| 1295 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1296 | } else { |
| 1297 | DCHECK(right.IsDoubleStackSlot()); |
| 1298 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1299 | if (if_cond == kCondNE) { |
| 1300 | __ j(X86Condition(true_high_cond), true_label); |
| 1301 | } else if (if_cond == kCondEQ) { |
| 1302 | __ j(X86Condition(false_high_cond), false_label); |
| 1303 | } else { |
| 1304 | __ j(X86Condition(true_high_cond), true_label); |
| 1305 | __ j(X86Condition(false_high_cond), false_label); |
| 1306 | } |
| 1307 | // Must be equal high, so compare the lows. |
| 1308 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1309 | } |
| 1310 | // The last comparison might be unsigned. |
| 1311 | __ j(final_condition, true_label); |
| 1312 | } |
| 1313 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1314 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1315 | Location rhs, |
| 1316 | HInstruction* insn, |
| 1317 | bool is_double) { |
| 1318 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1319 | if (is_double) { |
| 1320 | if (rhs.IsFpuRegister()) { |
| 1321 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1322 | } else if (const_area != nullptr) { |
| 1323 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1324 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1325 | codegen_->LiteralDoubleAddress( |
| 1326 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1327 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1328 | } else { |
| 1329 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1330 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1331 | } |
| 1332 | } else { |
| 1333 | if (rhs.IsFpuRegister()) { |
| 1334 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1335 | } else if (const_area != nullptr) { |
| 1336 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1337 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1338 | codegen_->LiteralFloatAddress( |
| 1339 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1340 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1341 | } else { |
| 1342 | DCHECK(rhs.IsStackSlot()); |
| 1343 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1348 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1349 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1350 | LabelType* true_target_in, |
| 1351 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1352 | // Generated branching requires both targets to be explicit. If either of the |
| 1353 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1354 | LabelType fallthrough_target; |
| 1355 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1356 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1357 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1358 | LocationSummary* locations = condition->GetLocations(); |
| 1359 | Location left = locations->InAt(0); |
| 1360 | Location right = locations->InAt(1); |
| 1361 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1363 | switch (type) { |
| 1364 | case Primitive::kPrimLong: |
| 1365 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1366 | break; |
| 1367 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1368 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1369 | GenerateFPJumps(condition, true_target, false_target); |
| 1370 | break; |
| 1371 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1372 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1373 | GenerateFPJumps(condition, true_target, false_target); |
| 1374 | break; |
| 1375 | default: |
| 1376 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1377 | } |
| 1378 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1379 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1380 | __ jmp(false_target); |
| 1381 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1382 | |
| 1383 | if (fallthrough_target.IsLinked()) { |
| 1384 | __ Bind(&fallthrough_target); |
| 1385 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1386 | } |
| 1387 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1388 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1389 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1390 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1391 | // conditions if they are materialized due to the complex branching. |
| 1392 | return cond->IsCondition() && |
| 1393 | cond->GetNext() == branch && |
| 1394 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1395 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1396 | } |
| 1397 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1398 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1399 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1401 | LabelType* true_target, |
| 1402 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1403 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1404 | |
| 1405 | if (true_target == nullptr && false_target == nullptr) { |
| 1406 | // Nothing to do. The code always falls through. |
| 1407 | return; |
| 1408 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1409 | // Constant condition, statically compared against "true" (integer value 1). |
| 1410 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1411 | if (true_target != nullptr) { |
| 1412 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1413 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1414 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1415 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1416 | if (false_target != nullptr) { |
| 1417 | __ jmp(false_target); |
| 1418 | } |
| 1419 | } |
| 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | // The following code generates these patterns: |
| 1424 | // (1) true_target == nullptr && false_target != nullptr |
| 1425 | // - opposite condition true => branch to false_target |
| 1426 | // (2) true_target != nullptr && false_target == nullptr |
| 1427 | // - condition true => branch to true_target |
| 1428 | // (3) true_target != nullptr && false_target != nullptr |
| 1429 | // - condition true => branch to true_target |
| 1430 | // - branch to false_target |
| 1431 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1432 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1433 | if (true_target == nullptr) { |
| 1434 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1435 | } else { |
| 1436 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1437 | } |
| 1438 | } else { |
| 1439 | // Materialized condition, compare against 0. |
| 1440 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1441 | if (lhs.IsRegister()) { |
| 1442 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1443 | } else { |
| 1444 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1445 | } |
| 1446 | if (true_target == nullptr) { |
| 1447 | __ j(kEqual, false_target); |
| 1448 | } else { |
| 1449 | __ j(kNotEqual, true_target); |
| 1450 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1453 | // Condition has not been materialized, use its inputs as the comparison and |
| 1454 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1455 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1456 | |
| 1457 | // If this is a long or FP comparison that has been folded into |
| 1458 | // the HCondition, generate the comparison directly. |
| 1459 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1460 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1461 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1462 | return; |
| 1463 | } |
| 1464 | |
| 1465 | Location lhs = condition->GetLocations()->InAt(0); |
| 1466 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1467 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1468 | if (rhs.IsRegister()) { |
| 1469 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1470 | } else if (rhs.IsConstant()) { |
| 1471 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1472 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1473 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1474 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1475 | } |
| 1476 | if (true_target == nullptr) { |
| 1477 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1478 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1479 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1480 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1481 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1482 | |
| 1483 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1484 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1485 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1486 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1490 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1491 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1492 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1493 | locations->SetInAt(0, Location::Any()); |
| 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1498 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1499 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1500 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1501 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1502 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1503 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1504 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1508 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1509 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1510 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1511 | locations->SetInAt(0, Location::Any()); |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1516 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1517 | GenerateTestAndBranch<Label>(deoptimize, |
| 1518 | /* condition_input_index */ 0, |
| 1519 | slow_path->GetEntryLabel(), |
| 1520 | /* false_target */ nullptr); |
| 1521 | } |
| 1522 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1523 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1524 | // There are no conditional move instructions for XMMs. |
| 1525 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1526 | return false; |
| 1527 | } |
| 1528 | |
| 1529 | // A FP condition doesn't generate the single CC that we need. |
| 1530 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1531 | HInstruction* condition = select->GetCondition(); |
| 1532 | if (condition->IsCondition()) { |
| 1533 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1534 | if (compare_type == Primitive::kPrimLong || |
| 1535 | Primitive::IsFloatingPointType(compare_type)) { |
| 1536 | return false; |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | // We can generate a CMOV for this Select. |
| 1541 | return true; |
| 1542 | } |
| 1543 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1544 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1545 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1546 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1547 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1548 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1549 | } else { |
| 1550 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1551 | if (SelectCanUseCMOV(select)) { |
| 1552 | if (select->InputAt(1)->IsConstant()) { |
| 1553 | // Cmov can't handle a constant value. |
| 1554 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1555 | } else { |
| 1556 | locations->SetInAt(1, Location::Any()); |
| 1557 | } |
| 1558 | } else { |
| 1559 | locations->SetInAt(1, Location::Any()); |
| 1560 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1561 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1562 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1563 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1564 | } |
| 1565 | locations->SetOut(Location::SameAsFirstInput()); |
| 1566 | } |
| 1567 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1568 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1569 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1570 | if (rhs.IsConstant()) { |
| 1571 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1572 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1573 | } else if (rhs.IsStackSlot()) { |
| 1574 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1575 | } else { |
| 1576 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1577 | } |
| 1578 | } |
| 1579 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1580 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1581 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1582 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1583 | if (SelectCanUseCMOV(select)) { |
| 1584 | // If both the condition and the source types are integer, we can generate |
| 1585 | // a CMOV to implement Select. |
| 1586 | |
| 1587 | HInstruction* select_condition = select->GetCondition(); |
| 1588 | Condition cond = kNotEqual; |
| 1589 | |
| 1590 | // Figure out how to test the 'condition'. |
| 1591 | if (select_condition->IsCondition()) { |
| 1592 | HCondition* condition = select_condition->AsCondition(); |
| 1593 | if (!condition->IsEmittedAtUseSite()) { |
| 1594 | // This was a previously materialized condition. |
| 1595 | // Can we use the existing condition code? |
| 1596 | if (AreEflagsSetFrom(condition, select)) { |
| 1597 | // Materialization was the previous instruction. Condition codes are right. |
| 1598 | cond = X86Condition(condition->GetCondition()); |
| 1599 | } else { |
| 1600 | // No, we have to recreate the condition code. |
| 1601 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1602 | __ testl(cond_reg, cond_reg); |
| 1603 | } |
| 1604 | } else { |
| 1605 | // We can't handle FP or long here. |
| 1606 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1607 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1608 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1609 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1610 | cond = X86Condition(condition->GetCondition()); |
| 1611 | } |
| 1612 | } else { |
| 1613 | // Must be a boolean condition, which needs to be compared to 0. |
| 1614 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1615 | __ testl(cond_reg, cond_reg); |
| 1616 | } |
| 1617 | |
| 1618 | // If the condition is true, overwrite the output, which already contains false. |
| 1619 | Location false_loc = locations->InAt(0); |
| 1620 | Location true_loc = locations->InAt(1); |
| 1621 | if (select->GetType() == Primitive::kPrimLong) { |
| 1622 | // 64 bit conditional move. |
| 1623 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1624 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1625 | if (true_loc.IsRegisterPair()) { |
| 1626 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1627 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1628 | } else { |
| 1629 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1630 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1631 | } |
| 1632 | } else { |
| 1633 | // 32 bit conditional move. |
| 1634 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1635 | if (true_loc.IsRegister()) { |
| 1636 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1637 | } else { |
| 1638 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1639 | } |
| 1640 | } |
| 1641 | } else { |
| 1642 | NearLabel false_target; |
| 1643 | GenerateTestAndBranch<NearLabel>( |
| 1644 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1645 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1646 | __ Bind(&false_target); |
| 1647 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1650 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1651 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1652 | } |
| 1653 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1654 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1655 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | void CodeGeneratorX86::GenerateNop() { |
| 1659 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1662 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1663 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1664 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1665 | // Handle the long/FP comparisons made in instruction simplification. |
| 1666 | switch (cond->InputAt(0)->GetType()) { |
| 1667 | case Primitive::kPrimLong: { |
| 1668 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1669 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1670 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | locations->SetOut(Location::RequiresRegister()); |
| 1672 | } |
| 1673 | break; |
| 1674 | } |
| 1675 | case Primitive::kPrimFloat: |
| 1676 | case Primitive::kPrimDouble: { |
| 1677 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1678 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1679 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1680 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1681 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1682 | } else { |
| 1683 | locations->SetInAt(1, Location::Any()); |
| 1684 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1685 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1686 | locations->SetOut(Location::RequiresRegister()); |
| 1687 | } |
| 1688 | break; |
| 1689 | } |
| 1690 | default: |
| 1691 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1692 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1693 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1694 | // We need a byte register. |
| 1695 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1696 | } |
| 1697 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1698 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1701 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1702 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1703 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1704 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1705 | |
| 1706 | LocationSummary* locations = cond->GetLocations(); |
| 1707 | Location lhs = locations->InAt(0); |
| 1708 | Location rhs = locations->InAt(1); |
| 1709 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1710 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1711 | |
| 1712 | switch (cond->InputAt(0)->GetType()) { |
| 1713 | default: { |
| 1714 | // Integer case. |
| 1715 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1716 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1717 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1718 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1719 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1720 | return; |
| 1721 | } |
| 1722 | case Primitive::kPrimLong: |
| 1723 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1724 | break; |
| 1725 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1726 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1727 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1728 | break; |
| 1729 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1730 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1731 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1732 | break; |
| 1733 | } |
| 1734 | |
| 1735 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1736 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1737 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1738 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1739 | __ Bind(&false_label); |
| 1740 | __ xorl(reg, reg); |
| 1741 | __ jmp(&done_label); |
| 1742 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1743 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1744 | __ Bind(&true_label); |
| 1745 | __ movl(reg, Immediate(1)); |
| 1746 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1754 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1797 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1826 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1829 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* 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 | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1835 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1836 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1839 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* 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::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1846 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1849 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1850 | LocationSummary* locations = |
| 1851 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1852 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1855 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1856 | // Will be generated at use site. |
| 1857 | } |
| 1858 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1859 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1860 | LocationSummary* locations = |
| 1861 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1862 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1863 | } |
| 1864 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1865 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1866 | // Will be generated at use site. |
| 1867 | } |
| 1868 | |
| 1869 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1870 | LocationSummary* locations = |
| 1871 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1872 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1873 | } |
| 1874 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1875 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1876 | // Will be generated at use site. |
| 1877 | } |
| 1878 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1879 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1880 | memory_barrier->SetLocations(nullptr); |
| 1881 | } |
| 1882 | |
| 1883 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1884 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1885 | } |
| 1886 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1887 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1888 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1891 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1892 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1895 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1896 | LocationSummary* locations = |
| 1897 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1898 | switch (ret->InputAt(0)->GetType()) { |
| 1899 | case Primitive::kPrimBoolean: |
| 1900 | case Primitive::kPrimByte: |
| 1901 | case Primitive::kPrimChar: |
| 1902 | case Primitive::kPrimShort: |
| 1903 | case Primitive::kPrimInt: |
| 1904 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1905 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1906 | break; |
| 1907 | |
| 1908 | case Primitive::kPrimLong: |
| 1909 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1910 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1911 | break; |
| 1912 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1913 | case Primitive::kPrimFloat: |
| 1914 | case Primitive::kPrimDouble: |
| 1915 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1916 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1917 | break; |
| 1918 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1919 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1920 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1921 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1924 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1925 | if (kIsDebugBuild) { |
| 1926 | switch (ret->InputAt(0)->GetType()) { |
| 1927 | case Primitive::kPrimBoolean: |
| 1928 | case Primitive::kPrimByte: |
| 1929 | case Primitive::kPrimChar: |
| 1930 | case Primitive::kPrimShort: |
| 1931 | case Primitive::kPrimInt: |
| 1932 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1933 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1934 | break; |
| 1935 | |
| 1936 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1937 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1938 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1939 | break; |
| 1940 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1941 | case Primitive::kPrimFloat: |
| 1942 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1943 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1944 | break; |
| 1945 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1946 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1947 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1948 | } |
| 1949 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1950 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1953 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1954 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1955 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1956 | // the method_idx. |
| 1957 | HandleInvoke(invoke); |
| 1958 | } |
| 1959 | |
| 1960 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1961 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1962 | } |
| 1963 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1964 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1965 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1966 | // art::PrepareForRegisterAllocation. |
| 1967 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1968 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1969 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1970 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1971 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1972 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1973 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1974 | return; |
| 1975 | } |
| 1976 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1977 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1978 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1979 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1980 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1981 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1982 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1983 | } |
| 1984 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1985 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1986 | if (invoke->GetLocations()->Intrinsified()) { |
| 1987 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1988 | intrinsic.Dispatch(invoke); |
| 1989 | return true; |
| 1990 | } |
| 1991 | return false; |
| 1992 | } |
| 1993 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1994 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1995 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1996 | // art::PrepareForRegisterAllocation. |
| 1997 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1998 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1999 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2000 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2001 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2002 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2003 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2004 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2005 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2006 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2010 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2011 | if (intrinsic.TryDispatch(invoke)) { |
| 2012 | return; |
| 2013 | } |
| 2014 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2015 | HandleInvoke(invoke); |
| 2016 | } |
| 2017 | |
| 2018 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2019 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2020 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2023 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2024 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2025 | return; |
| 2026 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2027 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2028 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2029 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2030 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2033 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2034 | // This call to HandleInvoke allocates a temporary (core) register |
| 2035 | // which is also used to transfer the hidden argument from FP to |
| 2036 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2037 | HandleInvoke(invoke); |
| 2038 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2039 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2043 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2044 | LocationSummary* locations = invoke->GetLocations(); |
| 2045 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2046 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2047 | Location receiver = locations->InAt(0); |
| 2048 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2049 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2050 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2051 | // won't be modified thereafter, before the `call` instruction. |
| 2052 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2053 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2054 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2055 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2056 | if (receiver.IsStackSlot()) { |
| 2057 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2058 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2059 | __ movl(temp, Address(temp, class_offset)); |
| 2060 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2061 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2062 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2063 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2064 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2065 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2066 | // emit a read barrier for the previous class reference load. |
| 2067 | // However this is not required in practice, as this is an |
| 2068 | // intermediate/temporary reference and because the current |
| 2069 | // concurrent copying collector keeps the from-space memory |
| 2070 | // intact/accessible until the end of the marking phase (the |
| 2071 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2072 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2073 | // temp = temp->GetAddressOfIMT() |
| 2074 | __ movl(temp, |
| 2075 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2076 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2077 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 2078 | invoke->GetImtIndex() % ImTable::kSize, kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2079 | __ movl(temp, Address(temp, method_offset)); |
| 2080 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2081 | __ call(Address(temp, |
| 2082 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2083 | |
| 2084 | DCHECK(!codegen_->IsLeafMethod()); |
| 2085 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2086 | } |
| 2087 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2088 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2089 | LocationSummary* locations = |
| 2090 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2091 | switch (neg->GetResultType()) { |
| 2092 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2093 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2094 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2095 | locations->SetOut(Location::SameAsFirstInput()); |
| 2096 | break; |
| 2097 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2098 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2099 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2100 | locations->SetOut(Location::SameAsFirstInput()); |
| 2101 | locations->AddTemp(Location::RequiresRegister()); |
| 2102 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2103 | break; |
| 2104 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2105 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2106 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2107 | locations->SetOut(Location::SameAsFirstInput()); |
| 2108 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2109 | break; |
| 2110 | |
| 2111 | default: |
| 2112 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2117 | LocationSummary* locations = neg->GetLocations(); |
| 2118 | Location out = locations->Out(); |
| 2119 | Location in = locations->InAt(0); |
| 2120 | switch (neg->GetResultType()) { |
| 2121 | case Primitive::kPrimInt: |
| 2122 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2123 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2124 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2125 | break; |
| 2126 | |
| 2127 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2128 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2129 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2130 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2131 | // Negation is similar to subtraction from zero. The least |
| 2132 | // significant byte triggers a borrow when it is different from |
| 2133 | // zero; to take it into account, add 1 to the most significant |
| 2134 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2135 | // operation. |
| 2136 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2137 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2138 | break; |
| 2139 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2140 | case Primitive::kPrimFloat: { |
| 2141 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2142 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2143 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2144 | // Implement float negation with an exclusive or with value |
| 2145 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2146 | // single-precision floating-point number). |
| 2147 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2148 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2149 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2150 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2151 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2152 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2153 | case Primitive::kPrimDouble: { |
| 2154 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2155 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2156 | // Implement double negation with an exclusive or with value |
| 2157 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2158 | // a double-precision floating-point number). |
| 2159 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2160 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2161 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2162 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2163 | |
| 2164 | default: |
| 2165 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2166 | } |
| 2167 | } |
| 2168 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2169 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2170 | LocationSummary* locations = |
| 2171 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2172 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2173 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2174 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2175 | locations->SetOut(Location::SameAsFirstInput()); |
| 2176 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2177 | } |
| 2178 | |
| 2179 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2180 | LocationSummary* locations = neg->GetLocations(); |
| 2181 | Location out = locations->Out(); |
| 2182 | DCHECK(locations->InAt(0).Equals(out)); |
| 2183 | |
| 2184 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2185 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2186 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2187 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2188 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2189 | } else { |
| 2190 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2191 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2192 | } |
| 2193 | } |
| 2194 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2195 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2196 | Primitive::Type result_type = conversion->GetResultType(); |
| 2197 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2198 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2199 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2200 | // The float-to-long and double-to-long type conversions rely on a |
| 2201 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2202 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2203 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2204 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2205 | ? LocationSummary::kCall |
| 2206 | : LocationSummary::kNoCall; |
| 2207 | LocationSummary* locations = |
| 2208 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2209 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2210 | // The Java language does not allow treating boolean as an integral type but |
| 2211 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2212 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2213 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2214 | case Primitive::kPrimByte: |
| 2215 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2216 | case Primitive::kPrimLong: { |
| 2217 | // Type conversion from long to byte is a result of code transformations. |
| 2218 | HInstruction* input = conversion->InputAt(0); |
| 2219 | Location input_location = input->IsConstant() |
| 2220 | ? Location::ConstantLocation(input->AsConstant()) |
| 2221 | : Location::RegisterPairLocation(EAX, EDX); |
| 2222 | locations->SetInAt(0, input_location); |
| 2223 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2224 | // the validation of the linear scan implementation |
| 2225 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2226 | break; |
| 2227 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2228 | case Primitive::kPrimBoolean: |
| 2229 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimShort: |
| 2231 | case Primitive::kPrimInt: |
| 2232 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2233 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2234 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2235 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2236 | // the validation of the linear scan implementation |
| 2237 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2238 | break; |
| 2239 | |
| 2240 | default: |
| 2241 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2242 | << " to " << result_type; |
| 2243 | } |
| 2244 | break; |
| 2245 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimShort: |
| 2247 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimLong: |
| 2249 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimBoolean: |
| 2251 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2252 | case Primitive::kPrimByte: |
| 2253 | case Primitive::kPrimInt: |
| 2254 | case Primitive::kPrimChar: |
| 2255 | // Processing a Dex `int-to-short' instruction. |
| 2256 | locations->SetInAt(0, Location::Any()); |
| 2257 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2258 | break; |
| 2259 | |
| 2260 | default: |
| 2261 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2262 | << " to " << result_type; |
| 2263 | } |
| 2264 | break; |
| 2265 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimInt: |
| 2267 | switch (input_type) { |
| 2268 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2269 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2270 | locations->SetInAt(0, Location::Any()); |
| 2271 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2272 | break; |
| 2273 | |
| 2274 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2275 | // Processing a Dex `float-to-int' instruction. |
| 2276 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2277 | locations->SetOut(Location::RequiresRegister()); |
| 2278 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2279 | break; |
| 2280 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2282 | // Processing a Dex `double-to-int' instruction. |
| 2283 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2284 | locations->SetOut(Location::RequiresRegister()); |
| 2285 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2286 | break; |
| 2287 | |
| 2288 | default: |
| 2289 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2290 | << " to " << result_type; |
| 2291 | } |
| 2292 | break; |
| 2293 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2294 | case Primitive::kPrimLong: |
| 2295 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2296 | case Primitive::kPrimBoolean: |
| 2297 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2298 | case Primitive::kPrimByte: |
| 2299 | case Primitive::kPrimShort: |
| 2300 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2301 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2302 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2303 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2304 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2305 | break; |
| 2306 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2307 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2308 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2309 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2310 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2311 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2312 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2313 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2314 | // The runtime helper puts the result in EAX, EDX. |
| 2315 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2316 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2317 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2318 | |
| 2319 | default: |
| 2320 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2321 | << " to " << result_type; |
| 2322 | } |
| 2323 | break; |
| 2324 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2325 | case Primitive::kPrimChar: |
| 2326 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimLong: |
| 2328 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimBoolean: |
| 2330 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimByte: |
| 2332 | case Primitive::kPrimShort: |
| 2333 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2334 | // Processing a Dex `int-to-char' instruction. |
| 2335 | locations->SetInAt(0, Location::Any()); |
| 2336 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2337 | break; |
| 2338 | |
| 2339 | default: |
| 2340 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2341 | << " to " << result_type; |
| 2342 | } |
| 2343 | break; |
| 2344 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2346 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimBoolean: |
| 2348 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimByte: |
| 2350 | case Primitive::kPrimShort: |
| 2351 | case Primitive::kPrimInt: |
| 2352 | case Primitive::kPrimChar: |
| 2353 | // Processing a Dex `int-to-float' instruction. |
| 2354 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2355 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2356 | break; |
| 2357 | |
| 2358 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2359 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2360 | locations->SetInAt(0, Location::Any()); |
| 2361 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2365 | // Processing a Dex `double-to-float' instruction. |
| 2366 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2367 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2368 | break; |
| 2369 | |
| 2370 | default: |
| 2371 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2372 | << " to " << result_type; |
| 2373 | }; |
| 2374 | break; |
| 2375 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2377 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimBoolean: |
| 2379 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimByte: |
| 2381 | case Primitive::kPrimShort: |
| 2382 | case Primitive::kPrimInt: |
| 2383 | case Primitive::kPrimChar: |
| 2384 | // Processing a Dex `int-to-double' instruction. |
| 2385 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2386 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2387 | break; |
| 2388 | |
| 2389 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2390 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2391 | locations->SetInAt(0, Location::Any()); |
| 2392 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2393 | break; |
| 2394 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2396 | // Processing a Dex `float-to-double' instruction. |
| 2397 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2398 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2399 | break; |
| 2400 | |
| 2401 | default: |
| 2402 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2403 | << " to " << result_type; |
| 2404 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | break; |
| 2406 | |
| 2407 | default: |
| 2408 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2409 | << " to " << result_type; |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2414 | LocationSummary* locations = conversion->GetLocations(); |
| 2415 | Location out = locations->Out(); |
| 2416 | Location in = locations->InAt(0); |
| 2417 | Primitive::Type result_type = conversion->GetResultType(); |
| 2418 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2419 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2420 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2421 | case Primitive::kPrimByte: |
| 2422 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2423 | case Primitive::kPrimLong: |
| 2424 | // Type conversion from long to byte is a result of code transformations. |
| 2425 | if (in.IsRegisterPair()) { |
| 2426 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2427 | } else { |
| 2428 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2429 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2430 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2431 | } |
| 2432 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimBoolean: |
| 2434 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2435 | case Primitive::kPrimShort: |
| 2436 | case Primitive::kPrimInt: |
| 2437 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2438 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2439 | if (in.IsRegister()) { |
| 2440 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2441 | } else { |
| 2442 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2443 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2444 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2445 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2446 | break; |
| 2447 | |
| 2448 | default: |
| 2449 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2450 | << " to " << result_type; |
| 2451 | } |
| 2452 | break; |
| 2453 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2454 | case Primitive::kPrimShort: |
| 2455 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2456 | case Primitive::kPrimLong: |
| 2457 | // Type conversion from long to short is a result of code transformations. |
| 2458 | if (in.IsRegisterPair()) { |
| 2459 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2460 | } else if (in.IsDoubleStackSlot()) { |
| 2461 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2462 | } else { |
| 2463 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2464 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2465 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2466 | } |
| 2467 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimBoolean: |
| 2469 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimByte: |
| 2471 | case Primitive::kPrimInt: |
| 2472 | case Primitive::kPrimChar: |
| 2473 | // Processing a Dex `int-to-short' instruction. |
| 2474 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2475 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2476 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2477 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2478 | } else { |
| 2479 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2480 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2481 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2482 | } |
| 2483 | break; |
| 2484 | |
| 2485 | default: |
| 2486 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2487 | << " to " << result_type; |
| 2488 | } |
| 2489 | break; |
| 2490 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimInt: |
| 2492 | switch (input_type) { |
| 2493 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2494 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2495 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2496 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2497 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2498 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2499 | } else { |
| 2500 | DCHECK(in.IsConstant()); |
| 2501 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2502 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2504 | } |
| 2505 | break; |
| 2506 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2507 | case Primitive::kPrimFloat: { |
| 2508 | // Processing a Dex `float-to-int' instruction. |
| 2509 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2510 | Register output = out.AsRegister<Register>(); |
| 2511 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2512 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2513 | |
| 2514 | __ movl(output, Immediate(kPrimIntMax)); |
| 2515 | // temp = int-to-float(output) |
| 2516 | __ cvtsi2ss(temp, output); |
| 2517 | // if input >= temp goto done |
| 2518 | __ comiss(input, temp); |
| 2519 | __ j(kAboveEqual, &done); |
| 2520 | // if input == NaN goto nan |
| 2521 | __ j(kUnordered, &nan); |
| 2522 | // output = float-to-int-truncate(input) |
| 2523 | __ cvttss2si(output, input); |
| 2524 | __ jmp(&done); |
| 2525 | __ Bind(&nan); |
| 2526 | // output = 0 |
| 2527 | __ xorl(output, output); |
| 2528 | __ Bind(&done); |
| 2529 | break; |
| 2530 | } |
| 2531 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimDouble: { |
| 2533 | // Processing a Dex `double-to-int' instruction. |
| 2534 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2535 | Register output = out.AsRegister<Register>(); |
| 2536 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2537 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2538 | |
| 2539 | __ movl(output, Immediate(kPrimIntMax)); |
| 2540 | // temp = int-to-double(output) |
| 2541 | __ cvtsi2sd(temp, output); |
| 2542 | // if input >= temp goto done |
| 2543 | __ comisd(input, temp); |
| 2544 | __ j(kAboveEqual, &done); |
| 2545 | // if input == NaN goto nan |
| 2546 | __ j(kUnordered, &nan); |
| 2547 | // output = double-to-int-truncate(input) |
| 2548 | __ cvttsd2si(output, input); |
| 2549 | __ jmp(&done); |
| 2550 | __ Bind(&nan); |
| 2551 | // output = 0 |
| 2552 | __ xorl(output, output); |
| 2553 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2554 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2555 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2556 | |
| 2557 | default: |
| 2558 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2559 | << " to " << result_type; |
| 2560 | } |
| 2561 | break; |
| 2562 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimLong: |
| 2564 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimBoolean: |
| 2566 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimByte: |
| 2568 | case Primitive::kPrimShort: |
| 2569 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2570 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2571 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2572 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2573 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2574 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2575 | __ cdq(); |
| 2576 | break; |
| 2577 | |
| 2578 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2579 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2580 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2581 | conversion, |
| 2582 | conversion->GetDexPc(), |
| 2583 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2584 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2588 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2589 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2590 | conversion, |
| 2591 | conversion->GetDexPc(), |
| 2592 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2593 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2594 | break; |
| 2595 | |
| 2596 | default: |
| 2597 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2598 | << " to " << result_type; |
| 2599 | } |
| 2600 | break; |
| 2601 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimChar: |
| 2603 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimLong: |
| 2605 | // Type conversion from long to short is a result of code transformations. |
| 2606 | if (in.IsRegisterPair()) { |
| 2607 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2608 | } else if (in.IsDoubleStackSlot()) { |
| 2609 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2610 | } else { |
| 2611 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2612 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2613 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2614 | } |
| 2615 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimBoolean: |
| 2617 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2618 | case Primitive::kPrimByte: |
| 2619 | case Primitive::kPrimShort: |
| 2620 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2621 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2622 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2623 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2624 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2625 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2626 | } else { |
| 2627 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2628 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2629 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2630 | } |
| 2631 | break; |
| 2632 | |
| 2633 | default: |
| 2634 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2635 | << " to " << result_type; |
| 2636 | } |
| 2637 | break; |
| 2638 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2639 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2640 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2641 | case Primitive::kPrimBoolean: |
| 2642 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimByte: |
| 2644 | case Primitive::kPrimShort: |
| 2645 | case Primitive::kPrimInt: |
| 2646 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2647 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2648 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2649 | break; |
| 2650 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2651 | case Primitive::kPrimLong: { |
| 2652 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2653 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2654 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2655 | // Create stack space for the call to |
| 2656 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2657 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2658 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2659 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2660 | __ subl(ESP, Immediate(adjustment)); |
| 2661 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2662 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2663 | // Load the value to the FP stack, using temporaries if needed. |
| 2664 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2665 | |
| 2666 | if (out.IsStackSlot()) { |
| 2667 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2668 | } else { |
| 2669 | __ fstps(Address(ESP, 0)); |
| 2670 | Location stack_temp = Location::StackSlot(0); |
| 2671 | codegen_->Move32(out, stack_temp); |
| 2672 | } |
| 2673 | |
| 2674 | // Remove the temporary stack space we allocated. |
| 2675 | if (adjustment != 0) { |
| 2676 | __ addl(ESP, Immediate(adjustment)); |
| 2677 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2678 | break; |
| 2679 | } |
| 2680 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2681 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2682 | // Processing a Dex `double-to-float' instruction. |
| 2683 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2684 | break; |
| 2685 | |
| 2686 | default: |
| 2687 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2688 | << " to " << result_type; |
| 2689 | }; |
| 2690 | break; |
| 2691 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2692 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2693 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2694 | case Primitive::kPrimBoolean: |
| 2695 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2696 | case Primitive::kPrimByte: |
| 2697 | case Primitive::kPrimShort: |
| 2698 | case Primitive::kPrimInt: |
| 2699 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2700 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2701 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2702 | break; |
| 2703 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2704 | case Primitive::kPrimLong: { |
| 2705 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2706 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2707 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2708 | // Create stack space for the call to |
| 2709 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2710 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2711 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2712 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2713 | __ subl(ESP, Immediate(adjustment)); |
| 2714 | } |
| 2715 | |
| 2716 | // Load the value to the FP stack, using temporaries if needed. |
| 2717 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2718 | |
| 2719 | if (out.IsDoubleStackSlot()) { |
| 2720 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2721 | } else { |
| 2722 | __ fstpl(Address(ESP, 0)); |
| 2723 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2724 | codegen_->Move64(out, stack_temp); |
| 2725 | } |
| 2726 | |
| 2727 | // Remove the temporary stack space we allocated. |
| 2728 | if (adjustment != 0) { |
| 2729 | __ addl(ESP, Immediate(adjustment)); |
| 2730 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2731 | break; |
| 2732 | } |
| 2733 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2734 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2735 | // Processing a Dex `float-to-double' instruction. |
| 2736 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2737 | break; |
| 2738 | |
| 2739 | default: |
| 2740 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2741 | << " to " << result_type; |
| 2742 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2743 | break; |
| 2744 | |
| 2745 | default: |
| 2746 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2747 | << " to " << result_type; |
| 2748 | } |
| 2749 | } |
| 2750 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2751 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2752 | LocationSummary* locations = |
| 2753 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2754 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2755 | case Primitive::kPrimInt: { |
| 2756 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2757 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2759 | break; |
| 2760 | } |
| 2761 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2762 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2763 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2764 | locations->SetInAt(1, Location::Any()); |
| 2765 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2766 | break; |
| 2767 | } |
| 2768 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2769 | case Primitive::kPrimFloat: |
| 2770 | case Primitive::kPrimDouble: { |
| 2771 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2772 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2773 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2774 | } else if (add->InputAt(1)->IsConstant()) { |
| 2775 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2776 | } else { |
| 2777 | locations->SetInAt(1, Location::Any()); |
| 2778 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2779 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2780 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2781 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2782 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2783 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2784 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2785 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2786 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2790 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2791 | Location first = locations->InAt(0); |
| 2792 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2793 | Location out = locations->Out(); |
| 2794 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2795 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2796 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2797 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2798 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2799 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2800 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2801 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2802 | } else { |
| 2803 | __ leal(out.AsRegister<Register>(), Address( |
| 2804 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2805 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2806 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2807 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2808 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2809 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2810 | } else { |
| 2811 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2812 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2813 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2814 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2815 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2816 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2817 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2821 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2822 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2823 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2824 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2825 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2826 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2827 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2828 | } else { |
| 2829 | DCHECK(second.IsConstant()) << second; |
| 2830 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2831 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2832 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2833 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2834 | break; |
| 2835 | } |
| 2836 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2837 | case Primitive::kPrimFloat: { |
| 2838 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2839 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2840 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2841 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2842 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2843 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2844 | codegen_->LiteralFloatAddress( |
| 2845 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2846 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2847 | } else { |
| 2848 | DCHECK(second.IsStackSlot()); |
| 2849 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2850 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2851 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | case Primitive::kPrimDouble: { |
| 2855 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2856 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2857 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2858 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2859 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2860 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2861 | codegen_->LiteralDoubleAddress( |
| 2862 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2863 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2864 | } else { |
| 2865 | DCHECK(second.IsDoubleStackSlot()); |
| 2866 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2867 | } |
| 2868 | break; |
| 2869 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2870 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2871 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2872 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2873 | } |
| 2874 | } |
| 2875 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2876 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2877 | LocationSummary* locations = |
| 2878 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2879 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2880 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2881 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2882 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2883 | locations->SetInAt(1, Location::Any()); |
| 2884 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2885 | break; |
| 2886 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2887 | case Primitive::kPrimFloat: |
| 2888 | case Primitive::kPrimDouble: { |
| 2889 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2890 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2891 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2892 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2893 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2894 | } else { |
| 2895 | locations->SetInAt(1, Location::Any()); |
| 2896 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2897 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2898 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2899 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2900 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2901 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2902 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2903 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2907 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2908 | Location first = locations->InAt(0); |
| 2909 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2910 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2911 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2912 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2913 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2914 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2915 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2916 | __ subl(first.AsRegister<Register>(), |
| 2917 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2918 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2919 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2920 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2921 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2925 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2926 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2927 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2928 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2929 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2930 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2931 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2932 | } else { |
| 2933 | DCHECK(second.IsConstant()) << second; |
| 2934 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2935 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2936 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2937 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2938 | break; |
| 2939 | } |
| 2940 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2941 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2942 | if (second.IsFpuRegister()) { |
| 2943 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2944 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2945 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2946 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2947 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2948 | codegen_->LiteralFloatAddress( |
| 2949 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2950 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2951 | } else { |
| 2952 | DCHECK(second.IsStackSlot()); |
| 2953 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2954 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2955 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2959 | if (second.IsFpuRegister()) { |
| 2960 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2961 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2962 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2963 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2964 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2965 | codegen_->LiteralDoubleAddress( |
| 2966 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2967 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2968 | } else { |
| 2969 | DCHECK(second.IsDoubleStackSlot()); |
| 2970 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2971 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2972 | break; |
| 2973 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2974 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2975 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2976 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2977 | } |
| 2978 | } |
| 2979 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2980 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2981 | LocationSummary* locations = |
| 2982 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2983 | switch (mul->GetResultType()) { |
| 2984 | case Primitive::kPrimInt: |
| 2985 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2986 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2987 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2988 | // Can use 3 operand multiply. |
| 2989 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2990 | } else { |
| 2991 | locations->SetOut(Location::SameAsFirstInput()); |
| 2992 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2993 | break; |
| 2994 | case Primitive::kPrimLong: { |
| 2995 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2996 | locations->SetInAt(1, Location::Any()); |
| 2997 | locations->SetOut(Location::SameAsFirstInput()); |
| 2998 | // Needed for imul on 32bits with 64bits output. |
| 2999 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3000 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3001 | break; |
| 3002 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3003 | case Primitive::kPrimFloat: |
| 3004 | case Primitive::kPrimDouble: { |
| 3005 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3006 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3007 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3008 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3009 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3010 | } else { |
| 3011 | locations->SetInAt(1, Location::Any()); |
| 3012 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3013 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3014 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3015 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3016 | |
| 3017 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3018 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3019 | } |
| 3020 | } |
| 3021 | |
| 3022 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3023 | LocationSummary* locations = mul->GetLocations(); |
| 3024 | Location first = locations->InAt(0); |
| 3025 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3026 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3027 | |
| 3028 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3029 | case Primitive::kPrimInt: |
| 3030 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3031 | // problems where the output may not be the same as the first operand. |
| 3032 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3033 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3034 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3035 | } else if (second.IsRegister()) { |
| 3036 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3037 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3038 | } else { |
| 3039 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3040 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3041 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3042 | } |
| 3043 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3044 | |
| 3045 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3046 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3047 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3048 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3049 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3050 | |
| 3051 | DCHECK_EQ(EAX, eax); |
| 3052 | DCHECK_EQ(EDX, edx); |
| 3053 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3054 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3055 | // output: in1 |
| 3056 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3057 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3058 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3059 | if (second.IsConstant()) { |
| 3060 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3061 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3062 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3063 | int32_t low_value = Low32Bits(value); |
| 3064 | int32_t high_value = High32Bits(value); |
| 3065 | Immediate low(low_value); |
| 3066 | Immediate high(high_value); |
| 3067 | |
| 3068 | __ movl(eax, high); |
| 3069 | // eax <- in1.lo * in2.hi |
| 3070 | __ imull(eax, in1_lo); |
| 3071 | // in1.hi <- in1.hi * in2.lo |
| 3072 | __ imull(in1_hi, low); |
| 3073 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3074 | __ addl(in1_hi, eax); |
| 3075 | // move in2_lo to eax to prepare for double precision |
| 3076 | __ movl(eax, low); |
| 3077 | // edx:eax <- in1.lo * in2.lo |
| 3078 | __ mull(in1_lo); |
| 3079 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3080 | __ addl(in1_hi, edx); |
| 3081 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3082 | __ movl(in1_lo, eax); |
| 3083 | } else if (second.IsRegisterPair()) { |
| 3084 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3085 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3086 | |
| 3087 | __ movl(eax, in2_hi); |
| 3088 | // eax <- in1.lo * in2.hi |
| 3089 | __ imull(eax, in1_lo); |
| 3090 | // in1.hi <- in1.hi * in2.lo |
| 3091 | __ imull(in1_hi, in2_lo); |
| 3092 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3093 | __ addl(in1_hi, eax); |
| 3094 | // move in1_lo to eax to prepare for double precision |
| 3095 | __ movl(eax, in1_lo); |
| 3096 | // edx:eax <- in1.lo * in2.lo |
| 3097 | __ mull(in2_lo); |
| 3098 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3099 | __ addl(in1_hi, edx); |
| 3100 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3101 | __ movl(in1_lo, eax); |
| 3102 | } else { |
| 3103 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3104 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3105 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3106 | |
| 3107 | __ movl(eax, in2_hi); |
| 3108 | // eax <- in1.lo * in2.hi |
| 3109 | __ imull(eax, in1_lo); |
| 3110 | // in1.hi <- in1.hi * in2.lo |
| 3111 | __ imull(in1_hi, in2_lo); |
| 3112 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3113 | __ addl(in1_hi, eax); |
| 3114 | // move in1_lo to eax to prepare for double precision |
| 3115 | __ movl(eax, in1_lo); |
| 3116 | // edx:eax <- in1.lo * in2.lo |
| 3117 | __ mull(in2_lo); |
| 3118 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3119 | __ addl(in1_hi, edx); |
| 3120 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3121 | __ movl(in1_lo, eax); |
| 3122 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3123 | |
| 3124 | break; |
| 3125 | } |
| 3126 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3127 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3128 | DCHECK(first.Equals(locations->Out())); |
| 3129 | if (second.IsFpuRegister()) { |
| 3130 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3131 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3132 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3133 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3134 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3135 | codegen_->LiteralFloatAddress( |
| 3136 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3137 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3138 | } else { |
| 3139 | DCHECK(second.IsStackSlot()); |
| 3140 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3141 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3142 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3146 | DCHECK(first.Equals(locations->Out())); |
| 3147 | if (second.IsFpuRegister()) { |
| 3148 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3149 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3150 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3151 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3152 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3153 | codegen_->LiteralDoubleAddress( |
| 3154 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3155 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3156 | } else { |
| 3157 | DCHECK(second.IsDoubleStackSlot()); |
| 3158 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3159 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3160 | break; |
| 3161 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3162 | |
| 3163 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3164 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3165 | } |
| 3166 | } |
| 3167 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3168 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3169 | uint32_t temp_offset, |
| 3170 | uint32_t stack_adjustment, |
| 3171 | bool is_fp, |
| 3172 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3173 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3174 | DCHECK(!is_wide); |
| 3175 | if (is_fp) { |
| 3176 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3177 | } else { |
| 3178 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3179 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3180 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3181 | DCHECK(is_wide); |
| 3182 | if (is_fp) { |
| 3183 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3184 | } else { |
| 3185 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3186 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3187 | } else { |
| 3188 | // 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] | 3189 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3190 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3191 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3192 | if (is_fp) { |
| 3193 | __ flds(Address(ESP, temp_offset)); |
| 3194 | } else { |
| 3195 | __ filds(Address(ESP, temp_offset)); |
| 3196 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3197 | } else { |
| 3198 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3199 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3200 | if (is_fp) { |
| 3201 | __ fldl(Address(ESP, temp_offset)); |
| 3202 | } else { |
| 3203 | __ fildl(Address(ESP, temp_offset)); |
| 3204 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3210 | Primitive::Type type = rem->GetResultType(); |
| 3211 | bool is_float = type == Primitive::kPrimFloat; |
| 3212 | size_t elem_size = Primitive::ComponentSize(type); |
| 3213 | LocationSummary* locations = rem->GetLocations(); |
| 3214 | Location first = locations->InAt(0); |
| 3215 | Location second = locations->InAt(1); |
| 3216 | Location out = locations->Out(); |
| 3217 | |
| 3218 | // Create stack space for 2 elements. |
| 3219 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3220 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3221 | |
| 3222 | // 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] | 3223 | const bool is_wide = !is_float; |
| 3224 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3225 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3226 | |
| 3227 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3228 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3229 | __ Bind(&retry); |
| 3230 | __ fprem(); |
| 3231 | |
| 3232 | // Move FP status to AX. |
| 3233 | __ fstsw(); |
| 3234 | |
| 3235 | // And see if the argument reduction is complete. This is signaled by the |
| 3236 | // C2 FPU flag bit set to 0. |
| 3237 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3238 | __ j(kNotEqual, &retry); |
| 3239 | |
| 3240 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3241 | // Store FP top of stack to real stack. |
| 3242 | if (is_float) { |
| 3243 | __ fsts(Address(ESP, 0)); |
| 3244 | } else { |
| 3245 | __ fstl(Address(ESP, 0)); |
| 3246 | } |
| 3247 | |
| 3248 | // Pop the 2 items from the FP stack. |
| 3249 | __ fucompp(); |
| 3250 | |
| 3251 | // Load the value from the stack into an XMM register. |
| 3252 | DCHECK(out.IsFpuRegister()) << out; |
| 3253 | if (is_float) { |
| 3254 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3255 | } else { |
| 3256 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3257 | } |
| 3258 | |
| 3259 | // And remove the temporary stack space we allocated. |
| 3260 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3261 | } |
| 3262 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3263 | |
| 3264 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3265 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3266 | |
| 3267 | LocationSummary* locations = instruction->GetLocations(); |
| 3268 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3269 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3270 | |
| 3271 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3272 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3273 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3274 | |
| 3275 | DCHECK(imm == 1 || imm == -1); |
| 3276 | |
| 3277 | if (instruction->IsRem()) { |
| 3278 | __ xorl(out_register, out_register); |
| 3279 | } else { |
| 3280 | __ movl(out_register, input_register); |
| 3281 | if (imm == -1) { |
| 3282 | __ negl(out_register); |
| 3283 | } |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3288 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3289 | LocationSummary* locations = instruction->GetLocations(); |
| 3290 | |
| 3291 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3292 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3293 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3294 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3295 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3296 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3297 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3298 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3299 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3300 | __ testl(input_register, input_register); |
| 3301 | __ cmovl(kGreaterEqual, num, input_register); |
| 3302 | int shift = CTZ(imm); |
| 3303 | __ sarl(num, Immediate(shift)); |
| 3304 | |
| 3305 | if (imm < 0) { |
| 3306 | __ negl(num); |
| 3307 | } |
| 3308 | |
| 3309 | __ movl(out_register, num); |
| 3310 | } |
| 3311 | |
| 3312 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3313 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3314 | |
| 3315 | LocationSummary* locations = instruction->GetLocations(); |
| 3316 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3317 | |
| 3318 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3319 | Register out = locations->Out().AsRegister<Register>(); |
| 3320 | Register num; |
| 3321 | Register edx; |
| 3322 | |
| 3323 | if (instruction->IsDiv()) { |
| 3324 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3325 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3326 | } else { |
| 3327 | edx = locations->Out().AsRegister<Register>(); |
| 3328 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3329 | } |
| 3330 | |
| 3331 | DCHECK_EQ(EAX, eax); |
| 3332 | DCHECK_EQ(EDX, edx); |
| 3333 | if (instruction->IsDiv()) { |
| 3334 | DCHECK_EQ(EAX, out); |
| 3335 | } else { |
| 3336 | DCHECK_EQ(EDX, out); |
| 3337 | } |
| 3338 | |
| 3339 | int64_t magic; |
| 3340 | int shift; |
| 3341 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3342 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3343 | // Save the numerator. |
| 3344 | __ movl(num, eax); |
| 3345 | |
| 3346 | // EAX = magic |
| 3347 | __ movl(eax, Immediate(magic)); |
| 3348 | |
| 3349 | // EDX:EAX = magic * numerator |
| 3350 | __ imull(num); |
| 3351 | |
| 3352 | if (imm > 0 && magic < 0) { |
| 3353 | // EDX += num |
| 3354 | __ addl(edx, num); |
| 3355 | } else if (imm < 0 && magic > 0) { |
| 3356 | __ subl(edx, num); |
| 3357 | } |
| 3358 | |
| 3359 | // Shift if needed. |
| 3360 | if (shift != 0) { |
| 3361 | __ sarl(edx, Immediate(shift)); |
| 3362 | } |
| 3363 | |
| 3364 | // EDX += 1 if EDX < 0 |
| 3365 | __ movl(eax, edx); |
| 3366 | __ shrl(edx, Immediate(31)); |
| 3367 | __ addl(edx, eax); |
| 3368 | |
| 3369 | if (instruction->IsRem()) { |
| 3370 | __ movl(eax, num); |
| 3371 | __ imull(edx, Immediate(imm)); |
| 3372 | __ subl(eax, edx); |
| 3373 | __ movl(edx, eax); |
| 3374 | } else { |
| 3375 | __ movl(eax, edx); |
| 3376 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3377 | } |
| 3378 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3379 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3380 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3381 | |
| 3382 | LocationSummary* locations = instruction->GetLocations(); |
| 3383 | Location out = locations->Out(); |
| 3384 | Location first = locations->InAt(0); |
| 3385 | Location second = locations->InAt(1); |
| 3386 | bool is_div = instruction->IsDiv(); |
| 3387 | |
| 3388 | switch (instruction->GetResultType()) { |
| 3389 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3390 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3391 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3392 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3393 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3394 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3395 | |
| 3396 | if (imm == 0) { |
| 3397 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3398 | } else if (imm == 1 || imm == -1) { |
| 3399 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3400 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3401 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3402 | } else { |
| 3403 | DCHECK(imm <= -2 || imm >= 2); |
| 3404 | GenerateDivRemWithAnyConstant(instruction); |
| 3405 | } |
| 3406 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3407 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3408 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3409 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3410 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3411 | Register second_reg = second.AsRegister<Register>(); |
| 3412 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3413 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3414 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3415 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3416 | __ cmpl(second_reg, Immediate(-1)); |
| 3417 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3418 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3419 | // edx:eax <- sign-extended of eax |
| 3420 | __ cdq(); |
| 3421 | // eax = quotient, edx = remainder |
| 3422 | __ idivl(second_reg); |
| 3423 | __ Bind(slow_path->GetExitLabel()); |
| 3424 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3425 | break; |
| 3426 | } |
| 3427 | |
| 3428 | case Primitive::kPrimLong: { |
| 3429 | InvokeRuntimeCallingConvention calling_convention; |
| 3430 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3431 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3432 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3433 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3434 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3435 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3436 | |
| 3437 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3438 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3439 | instruction, |
| 3440 | instruction->GetDexPc(), |
| 3441 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3442 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3443 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3444 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3445 | instruction, |
| 3446 | instruction->GetDexPc(), |
| 3447 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3448 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3449 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3450 | break; |
| 3451 | } |
| 3452 | |
| 3453 | default: |
| 3454 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3455 | } |
| 3456 | } |
| 3457 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3458 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3459 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3460 | ? LocationSummary::kCall |
| 3461 | : LocationSummary::kNoCall; |
| 3462 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3463 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3464 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3465 | case Primitive::kPrimInt: { |
| 3466 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3467 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3468 | locations->SetOut(Location::SameAsFirstInput()); |
| 3469 | // Intel uses edx:eax as the dividend. |
| 3470 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3471 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3472 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3473 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3474 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3475 | locations->AddTemp(Location::RequiresRegister()); |
| 3476 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3477 | break; |
| 3478 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3479 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3480 | InvokeRuntimeCallingConvention calling_convention; |
| 3481 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3482 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3483 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3484 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3485 | // Runtime helper puts the result in EAX, EDX. |
| 3486 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3487 | break; |
| 3488 | } |
| 3489 | case Primitive::kPrimFloat: |
| 3490 | case Primitive::kPrimDouble: { |
| 3491 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3492 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3493 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3494 | } else if (div->InputAt(1)->IsConstant()) { |
| 3495 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3496 | } else { |
| 3497 | locations->SetInAt(1, Location::Any()); |
| 3498 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3499 | locations->SetOut(Location::SameAsFirstInput()); |
| 3500 | break; |
| 3501 | } |
| 3502 | |
| 3503 | default: |
| 3504 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3505 | } |
| 3506 | } |
| 3507 | |
| 3508 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3509 | LocationSummary* locations = div->GetLocations(); |
| 3510 | Location first = locations->InAt(0); |
| 3511 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3512 | |
| 3513 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3514 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3515 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3516 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3517 | break; |
| 3518 | } |
| 3519 | |
| 3520 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3521 | if (second.IsFpuRegister()) { |
| 3522 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3523 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3524 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3525 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3526 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3527 | codegen_->LiteralFloatAddress( |
| 3528 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3529 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3530 | } else { |
| 3531 | DCHECK(second.IsStackSlot()); |
| 3532 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3533 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3534 | break; |
| 3535 | } |
| 3536 | |
| 3537 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3538 | if (second.IsFpuRegister()) { |
| 3539 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3540 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3541 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3542 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3543 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3544 | codegen_->LiteralDoubleAddress( |
| 3545 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3546 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3547 | } else { |
| 3548 | DCHECK(second.IsDoubleStackSlot()); |
| 3549 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3550 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3551 | break; |
| 3552 | } |
| 3553 | |
| 3554 | default: |
| 3555 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3556 | } |
| 3557 | } |
| 3558 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3559 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3560 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3561 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3562 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3563 | ? LocationSummary::kCall |
| 3564 | : LocationSummary::kNoCall; |
| 3565 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3566 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3567 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3568 | case Primitive::kPrimInt: { |
| 3569 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3570 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3571 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3573 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3574 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3575 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3576 | locations->AddTemp(Location::RequiresRegister()); |
| 3577 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3578 | break; |
| 3579 | } |
| 3580 | case Primitive::kPrimLong: { |
| 3581 | InvokeRuntimeCallingConvention calling_convention; |
| 3582 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3583 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3584 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3585 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3586 | // Runtime helper puts the result in EAX, EDX. |
| 3587 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3588 | break; |
| 3589 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3590 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3591 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3592 | locations->SetInAt(0, Location::Any()); |
| 3593 | locations->SetInAt(1, Location::Any()); |
| 3594 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3595 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3596 | break; |
| 3597 | } |
| 3598 | |
| 3599 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3600 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3605 | Primitive::Type type = rem->GetResultType(); |
| 3606 | switch (type) { |
| 3607 | case Primitive::kPrimInt: |
| 3608 | case Primitive::kPrimLong: { |
| 3609 | GenerateDivRemIntegral(rem); |
| 3610 | break; |
| 3611 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3612 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3614 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | } |
| 3617 | default: |
| 3618 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3619 | } |
| 3620 | } |
| 3621 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3622 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3623 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3624 | ? LocationSummary::kCallOnSlowPath |
| 3625 | : LocationSummary::kNoCall; |
| 3626 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3627 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3628 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3629 | case Primitive::kPrimByte: |
| 3630 | case Primitive::kPrimChar: |
| 3631 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3632 | case Primitive::kPrimInt: { |
| 3633 | locations->SetInAt(0, Location::Any()); |
| 3634 | break; |
| 3635 | } |
| 3636 | case Primitive::kPrimLong: { |
| 3637 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3638 | if (!instruction->IsConstant()) { |
| 3639 | locations->AddTemp(Location::RequiresRegister()); |
| 3640 | } |
| 3641 | break; |
| 3642 | } |
| 3643 | default: |
| 3644 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3645 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3646 | if (instruction->HasUses()) { |
| 3647 | locations->SetOut(Location::SameAsFirstInput()); |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3652 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3653 | codegen_->AddSlowPath(slow_path); |
| 3654 | |
| 3655 | LocationSummary* locations = instruction->GetLocations(); |
| 3656 | Location value = locations->InAt(0); |
| 3657 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3658 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3659 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3660 | case Primitive::kPrimByte: |
| 3661 | case Primitive::kPrimChar: |
| 3662 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3663 | case Primitive::kPrimInt: { |
| 3664 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3665 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3666 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3667 | } else if (value.IsStackSlot()) { |
| 3668 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3669 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3670 | } else { |
| 3671 | DCHECK(value.IsConstant()) << value; |
| 3672 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3673 | __ jmp(slow_path->GetEntryLabel()); |
| 3674 | } |
| 3675 | } |
| 3676 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3677 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3678 | case Primitive::kPrimLong: { |
| 3679 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3680 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3681 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3682 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3683 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3684 | } else { |
| 3685 | DCHECK(value.IsConstant()) << value; |
| 3686 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3687 | __ jmp(slow_path->GetEntryLabel()); |
| 3688 | } |
| 3689 | } |
| 3690 | break; |
| 3691 | } |
| 3692 | default: |
| 3693 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3694 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3695 | } |
| 3696 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3697 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3698 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3699 | |
| 3700 | LocationSummary* locations = |
| 3701 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3702 | |
| 3703 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3704 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3705 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3706 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3707 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3708 | // The shift count needs to be in CL or a constant. |
| 3709 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3710 | locations->SetOut(Location::SameAsFirstInput()); |
| 3711 | break; |
| 3712 | } |
| 3713 | default: |
| 3714 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3719 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3720 | |
| 3721 | LocationSummary* locations = op->GetLocations(); |
| 3722 | Location first = locations->InAt(0); |
| 3723 | Location second = locations->InAt(1); |
| 3724 | DCHECK(first.Equals(locations->Out())); |
| 3725 | |
| 3726 | switch (op->GetResultType()) { |
| 3727 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3728 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3729 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3730 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3731 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3732 | DCHECK_EQ(ECX, second_reg); |
| 3733 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3734 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3735 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3736 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3737 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3738 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3739 | } |
| 3740 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3741 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3742 | if (shift == 0) { |
| 3743 | return; |
| 3744 | } |
| 3745 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3746 | if (op->IsShl()) { |
| 3747 | __ shll(first_reg, imm); |
| 3748 | } else if (op->IsShr()) { |
| 3749 | __ sarl(first_reg, imm); |
| 3750 | } else { |
| 3751 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3752 | } |
| 3753 | } |
| 3754 | break; |
| 3755 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3756 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3757 | if (second.IsRegister()) { |
| 3758 | Register second_reg = second.AsRegister<Register>(); |
| 3759 | DCHECK_EQ(ECX, second_reg); |
| 3760 | if (op->IsShl()) { |
| 3761 | GenerateShlLong(first, second_reg); |
| 3762 | } else if (op->IsShr()) { |
| 3763 | GenerateShrLong(first, second_reg); |
| 3764 | } else { |
| 3765 | GenerateUShrLong(first, second_reg); |
| 3766 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3767 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3768 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3769 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3770 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3771 | if (shift != 0) { |
| 3772 | if (op->IsShl()) { |
| 3773 | GenerateShlLong(first, shift); |
| 3774 | } else if (op->IsShr()) { |
| 3775 | GenerateShrLong(first, shift); |
| 3776 | } else { |
| 3777 | GenerateUShrLong(first, shift); |
| 3778 | } |
| 3779 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3780 | } |
| 3781 | break; |
| 3782 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3783 | default: |
| 3784 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3785 | } |
| 3786 | } |
| 3787 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3788 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3789 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3790 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3791 | if (shift == 1) { |
| 3792 | // This is just an addition. |
| 3793 | __ addl(low, low); |
| 3794 | __ adcl(high, high); |
| 3795 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3796 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3797 | codegen_->EmitParallelMoves( |
| 3798 | loc.ToLow(), |
| 3799 | loc.ToHigh(), |
| 3800 | Primitive::kPrimInt, |
| 3801 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3802 | loc.ToLow(), |
| 3803 | Primitive::kPrimInt); |
| 3804 | } else if (shift > 32) { |
| 3805 | // Low part becomes 0. High part is low part << (shift-32). |
| 3806 | __ movl(high, low); |
| 3807 | __ shll(high, Immediate(shift - 32)); |
| 3808 | __ xorl(low, low); |
| 3809 | } else { |
| 3810 | // Between 1 and 31. |
| 3811 | __ shld(high, low, Immediate(shift)); |
| 3812 | __ shll(low, Immediate(shift)); |
| 3813 | } |
| 3814 | } |
| 3815 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3816 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3817 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3818 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3819 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3820 | __ testl(shifter, Immediate(32)); |
| 3821 | __ j(kEqual, &done); |
| 3822 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3823 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3824 | __ Bind(&done); |
| 3825 | } |
| 3826 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3827 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3828 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3829 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3830 | if (shift == 32) { |
| 3831 | // Need to copy the sign. |
| 3832 | DCHECK_NE(low, high); |
| 3833 | __ movl(low, high); |
| 3834 | __ sarl(high, Immediate(31)); |
| 3835 | } else if (shift > 32) { |
| 3836 | DCHECK_NE(low, high); |
| 3837 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3838 | __ movl(low, high); |
| 3839 | __ sarl(high, Immediate(31)); |
| 3840 | __ sarl(low, Immediate(shift - 32)); |
| 3841 | } else { |
| 3842 | // Between 1 and 31. |
| 3843 | __ shrd(low, high, Immediate(shift)); |
| 3844 | __ sarl(high, Immediate(shift)); |
| 3845 | } |
| 3846 | } |
| 3847 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3848 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3849 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3850 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3851 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3852 | __ testl(shifter, Immediate(32)); |
| 3853 | __ j(kEqual, &done); |
| 3854 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3855 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3856 | __ Bind(&done); |
| 3857 | } |
| 3858 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3859 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3860 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3861 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3862 | if (shift == 32) { |
| 3863 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3864 | codegen_->EmitParallelMoves( |
| 3865 | loc.ToHigh(), |
| 3866 | loc.ToLow(), |
| 3867 | Primitive::kPrimInt, |
| 3868 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3869 | loc.ToHigh(), |
| 3870 | Primitive::kPrimInt); |
| 3871 | } else if (shift > 32) { |
| 3872 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3873 | __ movl(low, high); |
| 3874 | __ shrl(low, Immediate(shift - 32)); |
| 3875 | __ xorl(high, high); |
| 3876 | } else { |
| 3877 | // Between 1 and 31. |
| 3878 | __ shrd(low, high, Immediate(shift)); |
| 3879 | __ shrl(high, Immediate(shift)); |
| 3880 | } |
| 3881 | } |
| 3882 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3883 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3884 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3885 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3886 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3887 | __ testl(shifter, Immediate(32)); |
| 3888 | __ j(kEqual, &done); |
| 3889 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3890 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3891 | __ Bind(&done); |
| 3892 | } |
| 3893 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3894 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3895 | LocationSummary* locations = |
| 3896 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3897 | |
| 3898 | switch (ror->GetResultType()) { |
| 3899 | case Primitive::kPrimLong: |
| 3900 | // Add the temporary needed. |
| 3901 | locations->AddTemp(Location::RequiresRegister()); |
| 3902 | FALLTHROUGH_INTENDED; |
| 3903 | case Primitive::kPrimInt: |
| 3904 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3905 | // The shift count needs to be in CL (unless it is a constant). |
| 3906 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3907 | locations->SetOut(Location::SameAsFirstInput()); |
| 3908 | break; |
| 3909 | default: |
| 3910 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3911 | UNREACHABLE(); |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3916 | LocationSummary* locations = ror->GetLocations(); |
| 3917 | Location first = locations->InAt(0); |
| 3918 | Location second = locations->InAt(1); |
| 3919 | |
| 3920 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3921 | Register first_reg = first.AsRegister<Register>(); |
| 3922 | if (second.IsRegister()) { |
| 3923 | Register second_reg = second.AsRegister<Register>(); |
| 3924 | __ rorl(first_reg, second_reg); |
| 3925 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3926 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3927 | __ rorl(first_reg, imm); |
| 3928 | } |
| 3929 | return; |
| 3930 | } |
| 3931 | |
| 3932 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3933 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3934 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3935 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3936 | if (second.IsRegister()) { |
| 3937 | Register second_reg = second.AsRegister<Register>(); |
| 3938 | DCHECK_EQ(second_reg, ECX); |
| 3939 | __ movl(temp_reg, first_reg_hi); |
| 3940 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3941 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3942 | __ movl(temp_reg, first_reg_hi); |
| 3943 | __ testl(second_reg, Immediate(32)); |
| 3944 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3945 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3946 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3947 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3948 | if (shift_amt == 0) { |
| 3949 | // Already fine. |
| 3950 | return; |
| 3951 | } |
| 3952 | if (shift_amt == 32) { |
| 3953 | // Just swap. |
| 3954 | __ movl(temp_reg, first_reg_lo); |
| 3955 | __ movl(first_reg_lo, first_reg_hi); |
| 3956 | __ movl(first_reg_hi, temp_reg); |
| 3957 | return; |
| 3958 | } |
| 3959 | |
| 3960 | Immediate imm(shift_amt); |
| 3961 | // Save the constents of the low value. |
| 3962 | __ movl(temp_reg, first_reg_lo); |
| 3963 | |
| 3964 | // Shift right into low, feeding bits from high. |
| 3965 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3966 | |
| 3967 | // Shift right into high, feeding bits from the original low. |
| 3968 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3969 | |
| 3970 | // Swap if needed. |
| 3971 | if (shift_amt > 32) { |
| 3972 | __ movl(temp_reg, first_reg_lo); |
| 3973 | __ movl(first_reg_lo, first_reg_hi); |
| 3974 | __ movl(first_reg_hi, temp_reg); |
| 3975 | } |
| 3976 | } |
| 3977 | } |
| 3978 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3979 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3980 | HandleShift(shl); |
| 3981 | } |
| 3982 | |
| 3983 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3984 | HandleShift(shl); |
| 3985 | } |
| 3986 | |
| 3987 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3988 | HandleShift(shr); |
| 3989 | } |
| 3990 | |
| 3991 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3992 | HandleShift(shr); |
| 3993 | } |
| 3994 | |
| 3995 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3996 | HandleShift(ushr); |
| 3997 | } |
| 3998 | |
| 3999 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4000 | HandleShift(ushr); |
| 4001 | } |
| 4002 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4003 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4004 | LocationSummary* locations = |
| 4005 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4006 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4007 | if (instruction->IsStringAlloc()) { |
| 4008 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4009 | } else { |
| 4010 | InvokeRuntimeCallingConvention calling_convention; |
| 4011 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4012 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4013 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4017 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4018 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4019 | if (instruction->IsStringAlloc()) { |
| 4020 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4021 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4022 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4023 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4024 | __ call(Address(temp, code_offset.Int32Value())); |
| 4025 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4026 | } else { |
| 4027 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4028 | instruction, |
| 4029 | instruction->GetDexPc(), |
| 4030 | nullptr); |
| 4031 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4032 | DCHECK(!codegen_->IsLeafMethod()); |
| 4033 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4036 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4037 | LocationSummary* locations = |
| 4038 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4039 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4040 | InvokeRuntimeCallingConvention calling_convention; |
| 4041 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4042 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4043 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4047 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4048 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4049 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4050 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4051 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4052 | instruction, |
| 4053 | instruction->GetDexPc(), |
| 4054 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4055 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4056 | DCHECK(!codegen_->IsLeafMethod()); |
| 4057 | } |
| 4058 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4059 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4060 | LocationSummary* locations = |
| 4061 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4062 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4063 | if (location.IsStackSlot()) { |
| 4064 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4065 | } else if (location.IsDoubleStackSlot()) { |
| 4066 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4067 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4068 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4069 | } |
| 4070 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4071 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4072 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4073 | } |
| 4074 | |
| 4075 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4076 | LocationSummary* locations = |
| 4077 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4078 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4079 | } |
| 4080 | |
| 4081 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4082 | } |
| 4083 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4084 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4085 | LocationSummary* locations = |
| 4086 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4088 | locations->SetOut(Location::RequiresRegister()); |
| 4089 | } |
| 4090 | |
| 4091 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4092 | LocationSummary* locations = instruction->GetLocations(); |
| 4093 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4094 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4095 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4096 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4097 | } else { |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4098 | __ movl(locations->InAt(0).AsRegister<Register>(), |
| 4099 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4100 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4101 | // temp = temp->GetImtEntryAt(method_offset); |
| 4102 | method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 4103 | instruction->GetIndex() % ImTable::kSize, kX86PointerSize)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4104 | } |
| 4105 | __ movl(locations->Out().AsRegister<Register>(), |
| 4106 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4107 | } |
| 4108 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4109 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4110 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4111 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4112 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4113 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4116 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4117 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4118 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4119 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4120 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4121 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4122 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4123 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4124 | break; |
| 4125 | |
| 4126 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4127 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4128 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4129 | break; |
| 4130 | |
| 4131 | default: |
| 4132 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4133 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4134 | } |
| 4135 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4136 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4137 | LocationSummary* locations = |
| 4138 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4139 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4140 | locations->SetOut(Location::SameAsFirstInput()); |
| 4141 | } |
| 4142 | |
| 4143 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4144 | LocationSummary* locations = bool_not->GetLocations(); |
| 4145 | Location in = locations->InAt(0); |
| 4146 | Location out = locations->Out(); |
| 4147 | DCHECK(in.Equals(out)); |
| 4148 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4149 | } |
| 4150 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4151 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4152 | LocationSummary* locations = |
| 4153 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4154 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4155 | case Primitive::kPrimBoolean: |
| 4156 | case Primitive::kPrimByte: |
| 4157 | case Primitive::kPrimShort: |
| 4158 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4159 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4160 | case Primitive::kPrimLong: { |
| 4161 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4162 | locations->SetInAt(1, Location::Any()); |
| 4163 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4164 | break; |
| 4165 | } |
| 4166 | case Primitive::kPrimFloat: |
| 4167 | case Primitive::kPrimDouble: { |
| 4168 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4169 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4170 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4171 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4172 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4173 | } else { |
| 4174 | locations->SetInAt(1, Location::Any()); |
| 4175 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4176 | locations->SetOut(Location::RequiresRegister()); |
| 4177 | break; |
| 4178 | } |
| 4179 | default: |
| 4180 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4181 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4185 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4186 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4187 | Location left = locations->InAt(0); |
| 4188 | Location right = locations->InAt(1); |
| 4189 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4190 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4191 | Condition less_cond = kLess; |
| 4192 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4193 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4194 | case Primitive::kPrimBoolean: |
| 4195 | case Primitive::kPrimByte: |
| 4196 | case Primitive::kPrimShort: |
| 4197 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4198 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4199 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4200 | break; |
| 4201 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4202 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4203 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4204 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4205 | int32_t val_low = 0; |
| 4206 | int32_t val_high = 0; |
| 4207 | bool right_is_const = false; |
| 4208 | |
| 4209 | if (right.IsConstant()) { |
| 4210 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4211 | right_is_const = true; |
| 4212 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4213 | val_low = Low32Bits(val); |
| 4214 | val_high = High32Bits(val); |
| 4215 | } |
| 4216 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4217 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4218 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4219 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4220 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4221 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4222 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4223 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4224 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4225 | __ j(kLess, &less); // Signed compare. |
| 4226 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4227 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4228 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4229 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4230 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4231 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4232 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4233 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4234 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4235 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4236 | break; |
| 4237 | } |
| 4238 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4239 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4240 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4241 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4242 | break; |
| 4243 | } |
| 4244 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4245 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4246 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4247 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4248 | break; |
| 4249 | } |
| 4250 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4251 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4252 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4253 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4254 | __ movl(out, Immediate(0)); |
| 4255 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4256 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4257 | |
| 4258 | __ Bind(&greater); |
| 4259 | __ movl(out, Immediate(1)); |
| 4260 | __ jmp(&done); |
| 4261 | |
| 4262 | __ Bind(&less); |
| 4263 | __ movl(out, Immediate(-1)); |
| 4264 | |
| 4265 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4266 | } |
| 4267 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4268 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4269 | LocationSummary* locations = |
| 4270 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4271 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4272 | locations->SetInAt(i, Location::Any()); |
| 4273 | } |
| 4274 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4275 | } |
| 4276 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4277 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4278 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4279 | } |
| 4280 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4281 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | /* |
| 4283 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4284 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4285 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4286 | */ |
| 4287 | switch (kind) { |
| 4288 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4289 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4290 | break; |
| 4291 | } |
| 4292 | case MemBarrierKind::kAnyStore: |
| 4293 | case MemBarrierKind::kLoadAny: |
| 4294 | case MemBarrierKind::kStoreStore: { |
| 4295 | // nop |
| 4296 | break; |
| 4297 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4298 | case MemBarrierKind::kNTStoreStore: |
| 4299 | // Non-Temporal Store/Store needs an explicit fence. |
| 4300 | MemoryFence(/* non-temporal */ true); |
| 4301 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4302 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4305 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4306 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4307 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4308 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4309 | |
| 4310 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4311 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4312 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4313 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4314 | if (GetGraph()->HasIrreducibleLoops() && |
| 4315 | (dispatch_info.method_load_kind == |
| 4316 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4317 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4318 | } |
| 4319 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4320 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4321 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4322 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4323 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4324 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4325 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4326 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4327 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4328 | 0u |
| 4329 | }; |
| 4330 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4331 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4332 | } |
| 4333 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4334 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4335 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4336 | Register temp) { |
| 4337 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4338 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4339 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4340 | return location.AsRegister<Register>(); |
| 4341 | } |
| 4342 | // For intrinsics we allow any location, so it may be on the stack. |
| 4343 | if (!location.IsRegister()) { |
| 4344 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4345 | return temp; |
| 4346 | } |
| 4347 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4348 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4349 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4350 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4351 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4352 | if (slow_path != nullptr) { |
| 4353 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4354 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4355 | __ movl(temp, Address(ESP, stack_offset)); |
| 4356 | return temp; |
| 4357 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4358 | } |
| 4359 | return location.AsRegister<Register>(); |
| 4360 | } |
| 4361 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4362 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4363 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4364 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4365 | switch (invoke->GetMethodLoadKind()) { |
| 4366 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4367 | // temp = thread->string_init_entrypoint |
| 4368 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4369 | break; |
| 4370 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4371 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4372 | break; |
| 4373 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4374 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4375 | break; |
| 4376 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4377 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4378 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4379 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4380 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4381 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4382 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4383 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4384 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4385 | // Bind a new fixup label at the end of the "movl" insn. |
| 4386 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4387 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4388 | break; |
| 4389 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4390 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4391 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4392 | Register method_reg; |
| 4393 | Register reg = temp.AsRegister<Register>(); |
| 4394 | if (current_method.IsRegister()) { |
| 4395 | method_reg = current_method.AsRegister<Register>(); |
| 4396 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4397 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4398 | DCHECK(!current_method.IsValid()); |
| 4399 | method_reg = reg; |
| 4400 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4401 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4402 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4403 | __ movl(reg, Address(method_reg, |
| 4404 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4405 | // temp = temp[index_in_cache]; |
| 4406 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4407 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4408 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4409 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4410 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4411 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4412 | return callee_method; |
| 4413 | } |
| 4414 | |
| 4415 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4416 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4417 | |
| 4418 | switch (invoke->GetCodePtrLocation()) { |
| 4419 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4420 | __ call(GetFrameEntryLabel()); |
| 4421 | break; |
| 4422 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4423 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4424 | Label* label = &relative_call_patches_.back().label; |
| 4425 | __ call(label); // Bind to the patch label, override at link time. |
| 4426 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4427 | break; |
| 4428 | } |
| 4429 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4430 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4431 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4432 | LOG(FATAL) << "Unsupported"; |
| 4433 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4434 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4435 | // (callee_method + offset_of_quick_compiled_code)() |
| 4436 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4437 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4438 | kX86WordSize).Int32Value())); |
| 4439 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4440 | } |
| 4441 | |
| 4442 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4443 | } |
| 4444 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4445 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4446 | Register temp = temp_in.AsRegister<Register>(); |
| 4447 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4448 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4449 | |
| 4450 | // Use the calling convention instead of the location of the receiver, as |
| 4451 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4452 | // slow path, the arguments have been moved to the right place, so here we are |
| 4453 | // guaranteed that the receiver is the first register of the calling convention. |
| 4454 | InvokeDexCallingConvention calling_convention; |
| 4455 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4456 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4457 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4458 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4459 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4460 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4461 | // emit a read barrier for the previous class reference load. |
| 4462 | // However this is not required in practice, as this is an |
| 4463 | // intermediate/temporary reference and because the current |
| 4464 | // concurrent copying collector keeps the from-space memory |
| 4465 | // intact/accessible until the end of the marking phase (the |
| 4466 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4467 | __ MaybeUnpoisonHeapReference(temp); |
| 4468 | // temp = temp->GetMethodAt(method_offset); |
| 4469 | __ movl(temp, Address(temp, method_offset)); |
| 4470 | // call temp->GetEntryPoint(); |
| 4471 | __ call(Address( |
| 4472 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4473 | } |
| 4474 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4475 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4476 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4477 | simple_patches_.emplace_back(); |
| 4478 | __ Bind(&simple_patches_.back()); |
| 4479 | } |
| 4480 | } |
| 4481 | |
| 4482 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4483 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4484 | __ Bind(&string_patches_.back().label); |
| 4485 | } |
| 4486 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4487 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4488 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4489 | __ Bind(&type_patches_.back().label); |
| 4490 | } |
| 4491 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4492 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4493 | uint32_t element_offset) { |
| 4494 | // Add the patch entry and bind its label at the end of the instruction. |
| 4495 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4496 | return &pc_relative_dex_cache_patches_.back().label; |
| 4497 | } |
| 4498 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4499 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4500 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4501 | size_t size = |
| 4502 | method_patches_.size() + |
| 4503 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4504 | pc_relative_dex_cache_patches_.size() + |
| 4505 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4506 | string_patches_.size() + |
| 4507 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4508 | linker_patches->reserve(size); |
| 4509 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4510 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4511 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4512 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4513 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4514 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4515 | info.target_method.dex_file, |
| 4516 | info.target_method.dex_method_index)); |
| 4517 | } |
| 4518 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4519 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4520 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4521 | info.target_method.dex_file, |
| 4522 | info.target_method.dex_method_index)); |
| 4523 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4524 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4525 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4526 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4527 | &info.target_dex_file, |
| 4528 | GetMethodAddressOffset(), |
| 4529 | info.element_offset)); |
| 4530 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4531 | for (const Label& label : simple_patches_) { |
| 4532 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4533 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4534 | } |
| 4535 | if (GetCompilerOptions().GetCompilePic()) { |
| 4536 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4537 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4538 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4539 | &info.dex_file, |
| 4540 | GetMethodAddressOffset(), |
| 4541 | info.string_index)); |
| 4542 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4543 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4544 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4545 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 4546 | &info.dex_file, |
| 4547 | GetMethodAddressOffset(), |
| 4548 | info.type_index)); |
| 4549 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4550 | } else { |
| 4551 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4552 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4553 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4554 | &info.dex_file, |
| 4555 | info.string_index)); |
| 4556 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4557 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4558 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4559 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 4560 | &info.dex_file, |
| 4561 | info.type_index)); |
| 4562 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4563 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4566 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4567 | Register card, |
| 4568 | Register object, |
| 4569 | Register value, |
| 4570 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4571 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4572 | if (value_can_be_null) { |
| 4573 | __ testl(value, value); |
| 4574 | __ j(kEqual, &is_null); |
| 4575 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4576 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4577 | __ movl(temp, object); |
| 4578 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4579 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4580 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4581 | if (value_can_be_null) { |
| 4582 | __ Bind(&is_null); |
| 4583 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4584 | } |
| 4585 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4586 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4587 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4588 | |
| 4589 | bool object_field_get_with_read_barrier = |
| 4590 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4591 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4592 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4593 | kEmitCompilerReadBarrier ? |
| 4594 | LocationSummary::kCallOnSlowPath : |
| 4595 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4596 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4597 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4598 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4599 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4600 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4601 | // The output overlaps in case of long: we don't want the low move |
| 4602 | // to overwrite the object's location. Likewise, in the case of |
| 4603 | // an object field get with read barriers enabled, we do not want |
| 4604 | // the move to overwrite the object's location, as we need it to emit |
| 4605 | // the read barrier. |
| 4606 | locations->SetOut( |
| 4607 | Location::RequiresRegister(), |
| 4608 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4609 | Location::kOutputOverlap : |
| 4610 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4611 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | |
| 4613 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4614 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4615 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4616 | // load the temp into the XMM and then copy the XMM into the |
| 4617 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4618 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4619 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4620 | // We need a temporary register for the read barrier marking slow |
| 4621 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4622 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4623 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4624 | } |
| 4625 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4626 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4627 | const FieldInfo& field_info) { |
| 4628 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4629 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4630 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4631 | Location base_loc = locations->InAt(0); |
| 4632 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | Location out = locations->Out(); |
| 4634 | bool is_volatile = field_info.IsVolatile(); |
| 4635 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4636 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4637 | |
| 4638 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4639 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4640 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4641 | break; |
| 4642 | } |
| 4643 | |
| 4644 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4645 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4646 | break; |
| 4647 | } |
| 4648 | |
| 4649 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4650 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4651 | break; |
| 4652 | } |
| 4653 | |
| 4654 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4655 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4656 | break; |
| 4657 | } |
| 4658 | |
| 4659 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4660 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4661 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4662 | |
| 4663 | case Primitive::kPrimNot: { |
| 4664 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4665 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4666 | Location temp_loc = locations->GetTemp(0); |
| 4667 | // Note that a potential implicit null check is handled in this |
| 4668 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4669 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4670 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4671 | if (is_volatile) { |
| 4672 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4673 | } |
| 4674 | } else { |
| 4675 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4676 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4677 | if (is_volatile) { |
| 4678 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4679 | } |
| 4680 | // If read barriers are enabled, emit read barriers other than |
| 4681 | // Baker's using a slow path (and also unpoison the loaded |
| 4682 | // reference, if heap poisoning is enabled). |
| 4683 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4684 | } |
| 4685 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4689 | if (is_volatile) { |
| 4690 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4691 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4692 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4693 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4694 | __ psrlq(temp, Immediate(32)); |
| 4695 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4696 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4697 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4698 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4699 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4700 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4701 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4702 | break; |
| 4703 | } |
| 4704 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4705 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4706 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4707 | break; |
| 4708 | } |
| 4709 | |
| 4710 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4711 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4712 | break; |
| 4713 | } |
| 4714 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4715 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4716 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4717 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4718 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4720 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4721 | // Potential implicit null checks, in the case of reference or |
| 4722 | // long fields, are handled in the previous switch statement. |
| 4723 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4724 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4725 | } |
| 4726 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4727 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4728 | if (field_type == Primitive::kPrimNot) { |
| 4729 | // Memory barriers, in the case of references, are also handled |
| 4730 | // in the previous switch statement. |
| 4731 | } else { |
| 4732 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4733 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4734 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4738 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4739 | |
| 4740 | LocationSummary* locations = |
| 4741 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4742 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4743 | bool is_volatile = field_info.IsVolatile(); |
| 4744 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4745 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4746 | || (field_type == Primitive::kPrimByte); |
| 4747 | |
| 4748 | // The register allocator does not support multiple |
| 4749 | // inputs that die at entry with one in a specific register. |
| 4750 | if (is_byte_type) { |
| 4751 | // Ensure the value is in a byte register. |
| 4752 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4753 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4754 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4755 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4756 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4757 | } else { |
| 4758 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4759 | } |
| 4760 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4761 | // 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] | 4762 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4763 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4764 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4765 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4766 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4767 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4768 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4769 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4770 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4771 | } else { |
| 4772 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4773 | |
| 4774 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4775 | // Temporary registers for the write barrier. |
| 4776 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4777 | // Ensure the card is in a byte register. |
| 4778 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4779 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4784 | const FieldInfo& field_info, |
| 4785 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4786 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4787 | |
| 4788 | LocationSummary* locations = instruction->GetLocations(); |
| 4789 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4790 | Location value = locations->InAt(1); |
| 4791 | bool is_volatile = field_info.IsVolatile(); |
| 4792 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4793 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4794 | bool needs_write_barrier = |
| 4795 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4796 | |
| 4797 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4798 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4799 | } |
| 4800 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4801 | bool maybe_record_implicit_null_check_done = false; |
| 4802 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4803 | switch (field_type) { |
| 4804 | case Primitive::kPrimBoolean: |
| 4805 | case Primitive::kPrimByte: { |
| 4806 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4807 | break; |
| 4808 | } |
| 4809 | |
| 4810 | case Primitive::kPrimShort: |
| 4811 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4812 | if (value.IsConstant()) { |
| 4813 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4814 | __ movw(Address(base, offset), Immediate(v)); |
| 4815 | } else { |
| 4816 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4817 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4818 | break; |
| 4819 | } |
| 4820 | |
| 4821 | case Primitive::kPrimInt: |
| 4822 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4823 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4824 | // Note that in the case where `value` is a null reference, |
| 4825 | // we do not enter this block, as the reference does not |
| 4826 | // need poisoning. |
| 4827 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4828 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4829 | __ movl(temp, value.AsRegister<Register>()); |
| 4830 | __ PoisonHeapReference(temp); |
| 4831 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4832 | } else if (value.IsConstant()) { |
| 4833 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4834 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4835 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4836 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4837 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4838 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | break; |
| 4840 | } |
| 4841 | |
| 4842 | case Primitive::kPrimLong: { |
| 4843 | if (is_volatile) { |
| 4844 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4845 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4846 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4847 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4848 | __ punpckldq(temp1, temp2); |
| 4849 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4850 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4851 | } else if (value.IsConstant()) { |
| 4852 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4853 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4854 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4855 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4856 | } else { |
| 4857 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4858 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4859 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4860 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4861 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4862 | break; |
| 4863 | } |
| 4864 | |
| 4865 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4866 | if (value.IsConstant()) { |
| 4867 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4868 | __ movl(Address(base, offset), Immediate(v)); |
| 4869 | } else { |
| 4870 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4871 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4872 | break; |
| 4873 | } |
| 4874 | |
| 4875 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4876 | if (value.IsConstant()) { |
| 4877 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4878 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4879 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4880 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4881 | maybe_record_implicit_null_check_done = true; |
| 4882 | } else { |
| 4883 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4884 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4885 | break; |
| 4886 | } |
| 4887 | |
| 4888 | case Primitive::kPrimVoid: |
| 4889 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4890 | UNREACHABLE(); |
| 4891 | } |
| 4892 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4893 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4894 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4895 | } |
| 4896 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4897 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4898 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4899 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4900 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4901 | } |
| 4902 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4903 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4904 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | |
| 4908 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4909 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4910 | } |
| 4911 | |
| 4912 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4913 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4914 | } |
| 4915 | |
| 4916 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4917 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4918 | } |
| 4919 | |
| 4920 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4921 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4925 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4926 | } |
| 4927 | |
| 4928 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4929 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4933 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4934 | } |
| 4935 | |
| 4936 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4937 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4938 | } |
| 4939 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4940 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4941 | HUnresolvedInstanceFieldGet* instruction) { |
| 4942 | FieldAccessCallingConventionX86 calling_convention; |
| 4943 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4944 | instruction, instruction->GetFieldType(), calling_convention); |
| 4945 | } |
| 4946 | |
| 4947 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4948 | HUnresolvedInstanceFieldGet* instruction) { |
| 4949 | FieldAccessCallingConventionX86 calling_convention; |
| 4950 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4951 | instruction->GetFieldType(), |
| 4952 | instruction->GetFieldIndex(), |
| 4953 | instruction->GetDexPc(), |
| 4954 | calling_convention); |
| 4955 | } |
| 4956 | |
| 4957 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4958 | HUnresolvedInstanceFieldSet* instruction) { |
| 4959 | FieldAccessCallingConventionX86 calling_convention; |
| 4960 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4961 | instruction, instruction->GetFieldType(), calling_convention); |
| 4962 | } |
| 4963 | |
| 4964 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4965 | HUnresolvedInstanceFieldSet* instruction) { |
| 4966 | FieldAccessCallingConventionX86 calling_convention; |
| 4967 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4968 | instruction->GetFieldType(), |
| 4969 | instruction->GetFieldIndex(), |
| 4970 | instruction->GetDexPc(), |
| 4971 | calling_convention); |
| 4972 | } |
| 4973 | |
| 4974 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4975 | HUnresolvedStaticFieldGet* instruction) { |
| 4976 | FieldAccessCallingConventionX86 calling_convention; |
| 4977 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4978 | instruction, instruction->GetFieldType(), calling_convention); |
| 4979 | } |
| 4980 | |
| 4981 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4982 | HUnresolvedStaticFieldGet* instruction) { |
| 4983 | FieldAccessCallingConventionX86 calling_convention; |
| 4984 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4985 | instruction->GetFieldType(), |
| 4986 | instruction->GetFieldIndex(), |
| 4987 | instruction->GetDexPc(), |
| 4988 | calling_convention); |
| 4989 | } |
| 4990 | |
| 4991 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4992 | HUnresolvedStaticFieldSet* instruction) { |
| 4993 | FieldAccessCallingConventionX86 calling_convention; |
| 4994 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4995 | instruction, instruction->GetFieldType(), calling_convention); |
| 4996 | } |
| 4997 | |
| 4998 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4999 | HUnresolvedStaticFieldSet* instruction) { |
| 5000 | FieldAccessCallingConventionX86 calling_convention; |
| 5001 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 5002 | instruction->GetFieldType(), |
| 5003 | instruction->GetFieldIndex(), |
| 5004 | instruction->GetDexPc(), |
| 5005 | calling_convention); |
| 5006 | } |
| 5007 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5008 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5009 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5010 | ? LocationSummary::kCallOnSlowPath |
| 5011 | : LocationSummary::kNoCall; |
| 5012 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 5013 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5014 | ? Location::RequiresRegister() |
| 5015 | : Location::Any(); |
| 5016 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5017 | if (instruction->HasUses()) { |
| 5018 | locations->SetOut(Location::SameAsFirstInput()); |
| 5019 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5020 | } |
| 5021 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5022 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5023 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5024 | return; |
| 5025 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5026 | LocationSummary* locations = instruction->GetLocations(); |
| 5027 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5028 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5029 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5030 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5031 | } |
| 5032 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5033 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5034 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5035 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5036 | |
| 5037 | LocationSummary* locations = instruction->GetLocations(); |
| 5038 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5039 | |
| 5040 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5041 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5042 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5043 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5044 | } else { |
| 5045 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5046 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5047 | __ jmp(slow_path->GetEntryLabel()); |
| 5048 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5049 | } |
| 5050 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5051 | } |
| 5052 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5053 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5054 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5055 | } |
| 5056 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5057 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5058 | bool object_array_get_with_read_barrier = |
| 5059 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5060 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5061 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5062 | object_array_get_with_read_barrier ? |
| 5063 | LocationSummary::kCallOnSlowPath : |
| 5064 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5065 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5066 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5067 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5068 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5069 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5070 | // The output overlaps in case of long: we don't want the low move |
| 5071 | // to overwrite the array's location. Likewise, in the case of an |
| 5072 | // object array get with read barriers enabled, we do not want the |
| 5073 | // move to overwrite the array's location, as we need it to emit |
| 5074 | // the read barrier. |
| 5075 | locations->SetOut( |
| 5076 | Location::RequiresRegister(), |
| 5077 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5078 | Location::kOutputOverlap : |
| 5079 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5080 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5081 | // We need a temporary register for the read barrier marking slow |
| 5082 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5083 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5084 | locations->AddTemp(Location::RequiresRegister()); |
| 5085 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5089 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5090 | Location obj_loc = locations->InAt(0); |
| 5091 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5093 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5094 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5095 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5096 | Primitive::Type type = instruction->GetType(); |
| 5097 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5098 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5099 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5100 | if (index.IsConstant()) { |
| 5101 | __ movzxb(out, Address(obj, |
| 5102 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5103 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5104 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5105 | } |
| 5106 | break; |
| 5107 | } |
| 5108 | |
| 5109 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5110 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | if (index.IsConstant()) { |
| 5112 | __ movsxb(out, Address(obj, |
| 5113 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5114 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5115 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5116 | } |
| 5117 | break; |
| 5118 | } |
| 5119 | |
| 5120 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5121 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5122 | if (index.IsConstant()) { |
| 5123 | __ movsxw(out, Address(obj, |
| 5124 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5125 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5126 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | } |
| 5128 | break; |
| 5129 | } |
| 5130 | |
| 5131 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5132 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | if (index.IsConstant()) { |
| 5134 | __ movzxw(out, Address(obj, |
| 5135 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5136 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5137 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5138 | } |
| 5139 | break; |
| 5140 | } |
| 5141 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5142 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5143 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | if (index.IsConstant()) { |
| 5145 | __ movl(out, Address(obj, |
| 5146 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5147 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5148 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5149 | } |
| 5150 | break; |
| 5151 | } |
| 5152 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5153 | case Primitive::kPrimNot: { |
| 5154 | static_assert( |
| 5155 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5156 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5157 | // /* HeapReference<Object> */ out = |
| 5158 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5159 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5160 | Location temp = locations->GetTemp(0); |
| 5161 | // Note that a potential implicit null check is handled in this |
| 5162 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5163 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5164 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5165 | } else { |
| 5166 | Register out = out_loc.AsRegister<Register>(); |
| 5167 | if (index.IsConstant()) { |
| 5168 | uint32_t offset = |
| 5169 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5170 | __ movl(out, Address(obj, offset)); |
| 5171 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5172 | // If read barriers are enabled, emit read barriers other than |
| 5173 | // Baker's using a slow path (and also unpoison the loaded |
| 5174 | // reference, if heap poisoning is enabled). |
| 5175 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5176 | } else { |
| 5177 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5178 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5179 | // If read barriers are enabled, emit read barriers other than |
| 5180 | // Baker's using a slow path (and also unpoison the loaded |
| 5181 | // reference, if heap poisoning is enabled). |
| 5182 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5183 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5184 | } |
| 5185 | } |
| 5186 | break; |
| 5187 | } |
| 5188 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5189 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5190 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5191 | if (index.IsConstant()) { |
| 5192 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5193 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5194 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5195 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5197 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5198 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5199 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5200 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5201 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5202 | } |
| 5203 | break; |
| 5204 | } |
| 5205 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5206 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5207 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5208 | if (index.IsConstant()) { |
| 5209 | __ movss(out, Address(obj, |
| 5210 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5211 | } else { |
| 5212 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5213 | } |
| 5214 | break; |
| 5215 | } |
| 5216 | |
| 5217 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5218 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5219 | if (index.IsConstant()) { |
| 5220 | __ movsd(out, Address(obj, |
| 5221 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5222 | } else { |
| 5223 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5224 | } |
| 5225 | break; |
| 5226 | } |
| 5227 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5228 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5229 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5230 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5231 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5232 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5233 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5234 | // Potential implicit null checks, in the case of reference or |
| 5235 | // long arrays, are handled in the previous switch statement. |
| 5236 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5237 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5238 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5242 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5243 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5244 | bool needs_write_barrier = |
| 5245 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5246 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5247 | bool object_array_set_with_read_barrier = |
| 5248 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5249 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5250 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5251 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5252 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5253 | LocationSummary::kCallOnSlowPath : |
| 5254 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5255 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5256 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5257 | || (value_type == Primitive::kPrimByte); |
| 5258 | // We need the inputs to be different than the output in case of long operation. |
| 5259 | // In case of a byte operation, the register allocator does not support multiple |
| 5260 | // inputs that die at entry with one in a specific register. |
| 5261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5262 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5263 | if (is_byte_type) { |
| 5264 | // Ensure the value is in a byte register. |
| 5265 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5266 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5267 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5268 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5270 | } |
| 5271 | if (needs_write_barrier) { |
| 5272 | // Temporary registers for the write barrier. |
| 5273 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5274 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5275 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5276 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5280 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5281 | Location array_loc = locations->InAt(0); |
| 5282 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5283 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5284 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5285 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5286 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5287 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5288 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5289 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5290 | bool needs_write_barrier = |
| 5291 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5292 | |
| 5293 | switch (value_type) { |
| 5294 | case Primitive::kPrimBoolean: |
| 5295 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5296 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5297 | Address address = index.IsConstant() |
| 5298 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5299 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5300 | if (value.IsRegister()) { |
| 5301 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5303 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5304 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | break; |
| 5307 | } |
| 5308 | |
| 5309 | case Primitive::kPrimShort: |
| 5310 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5311 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5312 | Address address = index.IsConstant() |
| 5313 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5314 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5315 | if (value.IsRegister()) { |
| 5316 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5317 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5318 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5319 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5320 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | break; |
| 5322 | } |
| 5323 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5324 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5325 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5326 | Address address = index.IsConstant() |
| 5327 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5328 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5329 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5330 | if (!value.IsRegister()) { |
| 5331 | // Just setting null. |
| 5332 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5333 | DCHECK(value.IsConstant()) << value; |
| 5334 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5335 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5336 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5337 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5338 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5339 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5340 | |
| 5341 | DCHECK(needs_write_barrier); |
| 5342 | Register register_value = value.AsRegister<Register>(); |
| 5343 | NearLabel done, not_null, do_put; |
| 5344 | SlowPathCode* slow_path = nullptr; |
| 5345 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5346 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5347 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5348 | codegen_->AddSlowPath(slow_path); |
| 5349 | if (instruction->GetValueCanBeNull()) { |
| 5350 | __ testl(register_value, register_value); |
| 5351 | __ j(kNotEqual, ¬_null); |
| 5352 | __ movl(address, Immediate(0)); |
| 5353 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5354 | __ jmp(&done); |
| 5355 | __ Bind(¬_null); |
| 5356 | } |
| 5357 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5358 | if (kEmitCompilerReadBarrier) { |
| 5359 | // When read barriers are enabled, the type checking |
| 5360 | // instrumentation requires two read barriers: |
| 5361 | // |
| 5362 | // __ movl(temp2, temp); |
| 5363 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5364 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5365 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5366 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5367 | // |
| 5368 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5369 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5370 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5371 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5372 | // |
| 5373 | // __ cmpl(temp, temp2); |
| 5374 | // |
| 5375 | // However, the second read barrier may trash `temp`, as it |
| 5376 | // is a temporary register, and as such would not be saved |
| 5377 | // along with live registers before calling the runtime (nor |
| 5378 | // restored afterwards). So in this case, we bail out and |
| 5379 | // delegate the work to the array set slow path. |
| 5380 | // |
| 5381 | // TODO: Extend the register allocator to support a new |
| 5382 | // "(locally) live temp" location so as to avoid always |
| 5383 | // going into the slow path when read barriers are enabled. |
| 5384 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5385 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5386 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5387 | __ movl(temp, Address(array, class_offset)); |
| 5388 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5389 | __ MaybeUnpoisonHeapReference(temp); |
| 5390 | |
| 5391 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5392 | __ movl(temp, Address(temp, component_offset)); |
| 5393 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5394 | // nor the object reference in `register_value->klass`, as |
| 5395 | // we are comparing two poisoned references. |
| 5396 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5397 | |
| 5398 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5399 | __ j(kEqual, &do_put); |
| 5400 | // If heap poisoning is enabled, the `temp` reference has |
| 5401 | // not been unpoisoned yet; unpoison it now. |
| 5402 | __ MaybeUnpoisonHeapReference(temp); |
| 5403 | |
| 5404 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5405 | __ movl(temp, Address(temp, super_offset)); |
| 5406 | // If heap poisoning is enabled, no need to unpoison |
| 5407 | // `temp`, as we are comparing against null below. |
| 5408 | __ testl(temp, temp); |
| 5409 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5410 | __ Bind(&do_put); |
| 5411 | } else { |
| 5412 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5413 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | if (kPoisonHeapReferences) { |
| 5418 | __ movl(temp, register_value); |
| 5419 | __ PoisonHeapReference(temp); |
| 5420 | __ movl(address, temp); |
| 5421 | } else { |
| 5422 | __ movl(address, register_value); |
| 5423 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5424 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5425 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5426 | } |
| 5427 | |
| 5428 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5429 | codegen_->MarkGCCard( |
| 5430 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5431 | __ Bind(&done); |
| 5432 | |
| 5433 | if (slow_path != nullptr) { |
| 5434 | __ Bind(slow_path->GetExitLabel()); |
| 5435 | } |
| 5436 | |
| 5437 | break; |
| 5438 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5439 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5440 | case Primitive::kPrimInt: { |
| 5441 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5442 | Address address = index.IsConstant() |
| 5443 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5444 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5445 | if (value.IsRegister()) { |
| 5446 | __ movl(address, value.AsRegister<Register>()); |
| 5447 | } else { |
| 5448 | DCHECK(value.IsConstant()) << value; |
| 5449 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5450 | __ movl(address, Immediate(v)); |
| 5451 | } |
| 5452 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5453 | break; |
| 5454 | } |
| 5455 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5456 | case Primitive::kPrimLong: { |
| 5457 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5458 | if (index.IsConstant()) { |
| 5459 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5460 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5461 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5462 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5463 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5464 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5465 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5466 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5467 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5468 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5469 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5470 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5471 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5472 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5473 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5474 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5475 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5476 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5477 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5478 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5479 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5480 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5481 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5482 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5483 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5484 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5485 | Immediate(High32Bits(val))); |
| 5486 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5487 | } |
| 5488 | break; |
| 5489 | } |
| 5490 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5491 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5492 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5493 | Address address = index.IsConstant() |
| 5494 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5495 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5496 | if (value.IsFpuRegister()) { |
| 5497 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5498 | } else { |
| 5499 | DCHECK(value.IsConstant()); |
| 5500 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5501 | __ movl(address, Immediate(v)); |
| 5502 | } |
| 5503 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5504 | break; |
| 5505 | } |
| 5506 | |
| 5507 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5508 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5509 | Address address = index.IsConstant() |
| 5510 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5511 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5512 | if (value.IsFpuRegister()) { |
| 5513 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5514 | } else { |
| 5515 | DCHECK(value.IsConstant()); |
| 5516 | Address address_hi = index.IsConstant() ? |
| 5517 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5518 | offset + kX86WordSize) : |
| 5519 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5520 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5521 | __ movl(address, Immediate(Low32Bits(v))); |
| 5522 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5523 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5524 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5525 | break; |
| 5526 | } |
| 5527 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5528 | case Primitive::kPrimVoid: |
| 5529 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5530 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | |
| 5534 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5535 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5536 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 5537 | if (!instruction->IsEmittedAtUseSite()) { |
| 5538 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 5539 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 5543 | if (instruction->IsEmittedAtUseSite()) { |
| 5544 | return; |
| 5545 | } |
| 5546 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5547 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5548 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5549 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5550 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5551 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5552 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5556 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5557 | ? LocationSummary::kCallOnSlowPath |
| 5558 | : LocationSummary::kNoCall; |
| 5559 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5560 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 5561 | HInstruction* length = instruction->InputAt(1); |
| 5562 | if (!length->IsEmittedAtUseSite()) { |
| 5563 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5564 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5565 | if (instruction->HasUses()) { |
| 5566 | locations->SetOut(Location::SameAsFirstInput()); |
| 5567 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5571 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5572 | Location index_loc = locations->InAt(0); |
| 5573 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5574 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5575 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5576 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5577 | if (length_loc.IsConstant()) { |
| 5578 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5579 | if (index_loc.IsConstant()) { |
| 5580 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5581 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5582 | if (index < 0 || index >= length) { |
| 5583 | codegen_->AddSlowPath(slow_path); |
| 5584 | __ jmp(slow_path->GetEntryLabel()); |
| 5585 | } else { |
| 5586 | // Some optimization after BCE may have generated this, and we should not |
| 5587 | // generate a bounds check if it is a valid range. |
| 5588 | } |
| 5589 | return; |
| 5590 | } |
| 5591 | |
| 5592 | // We have to reverse the jump condition because the length is the constant. |
| 5593 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5594 | __ cmpl(index_reg, Immediate(length)); |
| 5595 | codegen_->AddSlowPath(slow_path); |
| 5596 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5597 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 5598 | HInstruction* array_length = instruction->InputAt(1); |
| 5599 | if (array_length->IsEmittedAtUseSite()) { |
| 5600 | // Address the length field in the array. |
| 5601 | DCHECK(array_length->IsArrayLength()); |
| 5602 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); |
| 5603 | Location array_loc = array_length->GetLocations()->InAt(0); |
| 5604 | Address array_len(array_loc.AsRegister<Register>(), len_offset); |
| 5605 | if (index_loc.IsConstant()) { |
| 5606 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5607 | __ cmpl(array_len, Immediate(value)); |
| 5608 | } else { |
| 5609 | __ cmpl(array_len, index_loc.AsRegister<Register>()); |
| 5610 | } |
| 5611 | codegen_->MaybeRecordImplicitNullCheck(array_length); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5612 | } else { |
Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame^] | 5613 | Register length = length_loc.AsRegister<Register>(); |
| 5614 | if (index_loc.IsConstant()) { |
| 5615 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5616 | __ cmpl(length, Immediate(value)); |
| 5617 | } else { |
| 5618 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5619 | } |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5620 | } |
| 5621 | codegen_->AddSlowPath(slow_path); |
| 5622 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5623 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5626 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5627 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5631 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5632 | } |
| 5633 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5634 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5635 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5636 | } |
| 5637 | |
| 5638 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5639 | HBasicBlock* block = instruction->GetBlock(); |
| 5640 | if (block->GetLoopInformation() != nullptr) { |
| 5641 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5642 | // The back edge will generate the suspend check. |
| 5643 | return; |
| 5644 | } |
| 5645 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5646 | // The goto will generate the suspend check. |
| 5647 | return; |
| 5648 | } |
| 5649 | GenerateSuspendCheck(instruction, nullptr); |
| 5650 | } |
| 5651 | |
| 5652 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5653 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5654 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5655 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5656 | if (slow_path == nullptr) { |
| 5657 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5658 | instruction->SetSlowPath(slow_path); |
| 5659 | codegen_->AddSlowPath(slow_path); |
| 5660 | if (successor != nullptr) { |
| 5661 | DCHECK(successor->IsLoopHeader()); |
| 5662 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5663 | } |
| 5664 | } else { |
| 5665 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5666 | } |
| 5667 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5668 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5669 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5670 | if (successor == nullptr) { |
| 5671 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5672 | __ Bind(slow_path->GetReturnLabel()); |
| 5673 | } else { |
| 5674 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5675 | __ jmp(slow_path->GetEntryLabel()); |
| 5676 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5677 | } |
| 5678 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5679 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5680 | return codegen_->GetAssembler(); |
| 5681 | } |
| 5682 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5683 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5684 | ScratchRegisterScope ensure_scratch( |
| 5685 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5686 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5687 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5688 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5689 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5693 | ScratchRegisterScope ensure_scratch( |
| 5694 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5695 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5696 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5697 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5698 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5699 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5700 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5704 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5705 | Location source = move->GetSource(); |
| 5706 | Location destination = move->GetDestination(); |
| 5707 | |
| 5708 | if (source.IsRegister()) { |
| 5709 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5710 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5711 | } else if (destination.IsFpuRegister()) { |
| 5712 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5713 | } else { |
| 5714 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5715 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5716 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5717 | } else if (source.IsRegisterPair()) { |
| 5718 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5719 | // Create stack space for 2 elements. |
| 5720 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5721 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5722 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5723 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5724 | // And remove the temporary stack space we allocated. |
| 5725 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5726 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5727 | if (destination.IsRegister()) { |
| 5728 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5729 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5730 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5731 | } else if (destination.IsRegisterPair()) { |
| 5732 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5733 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5734 | __ psrlq(src_reg, Immediate(32)); |
| 5735 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5736 | } else if (destination.IsStackSlot()) { |
| 5737 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5738 | } else { |
| 5739 | DCHECK(destination.IsDoubleStackSlot()); |
| 5740 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5741 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5742 | } else if (source.IsStackSlot()) { |
| 5743 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5744 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5745 | } else if (destination.IsFpuRegister()) { |
| 5746 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5747 | } else { |
| 5748 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5749 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5750 | } |
| 5751 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5752 | if (destination.IsRegisterPair()) { |
| 5753 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5754 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5755 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5756 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5757 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5758 | } else { |
| 5759 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5760 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5761 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5762 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5763 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5764 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5765 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5766 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5767 | if (value == 0) { |
| 5768 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5769 | } else { |
| 5770 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5771 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5772 | } else { |
| 5773 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5774 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5775 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5776 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5777 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5778 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5779 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5780 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5781 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5782 | if (value == 0) { |
| 5783 | // Easy handling of 0.0. |
| 5784 | __ xorps(dest, dest); |
| 5785 | } else { |
| 5786 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5787 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5788 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5789 | __ movl(temp, Immediate(value)); |
| 5790 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5791 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5792 | } else { |
| 5793 | DCHECK(destination.IsStackSlot()) << destination; |
| 5794 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5795 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5796 | } else if (constant->IsLongConstant()) { |
| 5797 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5798 | int32_t low_value = Low32Bits(value); |
| 5799 | int32_t high_value = High32Bits(value); |
| 5800 | Immediate low(low_value); |
| 5801 | Immediate high(high_value); |
| 5802 | if (destination.IsDoubleStackSlot()) { |
| 5803 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5804 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5805 | } else { |
| 5806 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5807 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5808 | } |
| 5809 | } else { |
| 5810 | DCHECK(constant->IsDoubleConstant()); |
| 5811 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5812 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5813 | int32_t low_value = Low32Bits(value); |
| 5814 | int32_t high_value = High32Bits(value); |
| 5815 | Immediate low(low_value); |
| 5816 | Immediate high(high_value); |
| 5817 | if (destination.IsFpuRegister()) { |
| 5818 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5819 | if (value == 0) { |
| 5820 | // Easy handling of 0.0. |
| 5821 | __ xorpd(dest, dest); |
| 5822 | } else { |
| 5823 | __ pushl(high); |
| 5824 | __ pushl(low); |
| 5825 | __ movsd(dest, Address(ESP, 0)); |
| 5826 | __ addl(ESP, Immediate(8)); |
| 5827 | } |
| 5828 | } else { |
| 5829 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5830 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5831 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5832 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5833 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5834 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5835 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5836 | } |
| 5837 | } |
| 5838 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5839 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5840 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5841 | ScratchRegisterScope ensure_scratch( |
| 5842 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5843 | |
| 5844 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5845 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5846 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5847 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5848 | } |
| 5849 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5850 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5851 | ScratchRegisterScope ensure_scratch( |
| 5852 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5853 | |
| 5854 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5855 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5856 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5857 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5858 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5859 | } |
| 5860 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5861 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5862 | ScratchRegisterScope ensure_scratch1( |
| 5863 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5864 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5865 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5866 | ScratchRegisterScope ensure_scratch2( |
| 5867 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5868 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5869 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5870 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5871 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5872 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5873 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5874 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5878 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5879 | Location source = move->GetSource(); |
| 5880 | Location destination = move->GetDestination(); |
| 5881 | |
| 5882 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5883 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5884 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5885 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5886 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5887 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5888 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5889 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5890 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5891 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5892 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5893 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5894 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5895 | // Use XOR Swap algorithm to avoid a temporary. |
| 5896 | DCHECK_NE(source.reg(), destination.reg()); |
| 5897 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5898 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5899 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5900 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5901 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5902 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5903 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5904 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5905 | // Take advantage of the 16 bytes in the XMM register. |
| 5906 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5907 | Address stack(ESP, destination.GetStackIndex()); |
| 5908 | // Load the double into the high doubleword. |
| 5909 | __ movhpd(reg, stack); |
| 5910 | |
| 5911 | // Store the low double into the destination. |
| 5912 | __ movsd(stack, reg); |
| 5913 | |
| 5914 | // Move the high double to the low double. |
| 5915 | __ psrldq(reg, Immediate(8)); |
| 5916 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5917 | // Take advantage of the 16 bytes in the XMM register. |
| 5918 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5919 | Address stack(ESP, source.GetStackIndex()); |
| 5920 | // Load the double into the high doubleword. |
| 5921 | __ movhpd(reg, stack); |
| 5922 | |
| 5923 | // Store the low double into the destination. |
| 5924 | __ movsd(stack, reg); |
| 5925 | |
| 5926 | // Move the high double to the low double. |
| 5927 | __ psrldq(reg, Immediate(8)); |
| 5928 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5929 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5930 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5931 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5932 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5937 | __ pushl(static_cast<Register>(reg)); |
| 5938 | } |
| 5939 | |
| 5940 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5941 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5942 | } |
| 5943 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5944 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5945 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5946 | if (kEmitCompilerReadBarrier) { |
| 5947 | switch (desired_class_load_kind) { |
| 5948 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5949 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5950 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5951 | // TODO: Implement for read barrier. |
| 5952 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5953 | default: |
| 5954 | break; |
| 5955 | } |
| 5956 | } |
| 5957 | switch (desired_class_load_kind) { |
| 5958 | case HLoadClass::LoadKind::kReferrersClass: |
| 5959 | break; |
| 5960 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5961 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5962 | break; |
| 5963 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5964 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5965 | FALLTHROUGH_INTENDED; |
| 5966 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5967 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5968 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5969 | // is incompatible with it. |
| 5970 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5971 | // with irreducible loops. |
| 5972 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5973 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5974 | } |
| 5975 | break; |
| 5976 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5977 | break; |
| 5978 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5979 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5980 | break; |
| 5981 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5982 | break; |
| 5983 | } |
| 5984 | return desired_class_load_kind; |
| 5985 | } |
| 5986 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5987 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5988 | if (cls->NeedsAccessCheck()) { |
| 5989 | InvokeRuntimeCallingConvention calling_convention; |
| 5990 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5991 | cls, |
| 5992 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5993 | Location::RegisterLocation(EAX), |
| 5994 | /* code_generator_supports_read_barrier */ true); |
| 5995 | return; |
| 5996 | } |
| 5997 | |
| 5998 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5999 | ? LocationSummary::kCallOnSlowPath |
| 6000 | : LocationSummary::kNoCall; |
| 6001 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 6002 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 6003 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 6004 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 6005 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 6006 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 6007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6008 | } |
| 6009 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6013 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6014 | if (cls->NeedsAccessCheck()) { |
| 6015 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 6016 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 6017 | cls, |
| 6018 | cls->GetDexPc(), |
| 6019 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6020 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6021 | return; |
| 6022 | } |
| 6023 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6024 | Location out_loc = locations->Out(); |
| 6025 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6026 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6027 | bool generate_null_check = false; |
| 6028 | switch (cls->GetLoadKind()) { |
| 6029 | case HLoadClass::LoadKind::kReferrersClass: { |
| 6030 | DCHECK(!cls->CanCallRuntime()); |
| 6031 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 6032 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6033 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6034 | GenerateGcRootFieldLoad( |
| 6035 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6036 | break; |
| 6037 | } |
| 6038 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 6039 | DCHECK(!kEmitCompilerReadBarrier); |
| 6040 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6041 | codegen_->RecordTypePatch(cls); |
| 6042 | break; |
| 6043 | } |
| 6044 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 6045 | DCHECK(!kEmitCompilerReadBarrier); |
| 6046 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6047 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6048 | codegen_->RecordTypePatch(cls); |
| 6049 | break; |
| 6050 | } |
| 6051 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 6052 | DCHECK(!kEmitCompilerReadBarrier); |
| 6053 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6054 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6055 | __ movl(out, Immediate(address)); |
| 6056 | codegen_->RecordSimplePatch(); |
| 6057 | break; |
| 6058 | } |
| 6059 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 6060 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6061 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6062 | // /* GcRoot<mirror::Class> */ out = *address |
| 6063 | GenerateGcRootFieldLoad(cls, out_loc, Address::Absolute(address)); |
| 6064 | generate_null_check = !cls->IsInDexCache(); |
| 6065 | break; |
| 6066 | } |
| 6067 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6068 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6069 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6070 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6071 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
| 6072 | GenerateGcRootFieldLoad( |
| 6073 | cls, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6074 | generate_null_check = !cls->IsInDexCache(); |
| 6075 | break; |
| 6076 | } |
| 6077 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6078 | // /* GcRoot<mirror::Class>[] */ out = |
| 6079 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6080 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6081 | __ movl(out, Address(current_method, |
| 6082 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6083 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 6084 | GenerateGcRootFieldLoad( |
| 6085 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 6086 | generate_null_check = !cls->IsInDexCache(); |
| 6087 | break; |
| 6088 | } |
| 6089 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6090 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6091 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6092 | DCHECK(cls->CanCallRuntime()); |
| 6093 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6094 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6095 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6096 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6097 | if (generate_null_check) { |
| 6098 | __ testl(out, out); |
| 6099 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6100 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6101 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6102 | if (cls->MustGenerateClinitCheck()) { |
| 6103 | GenerateClassInitializationCheck(slow_path, out); |
| 6104 | } else { |
| 6105 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6106 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6107 | } |
| 6108 | } |
| 6109 | |
| 6110 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6111 | LocationSummary* locations = |
| 6112 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6113 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6114 | if (check->HasUses()) { |
| 6115 | locations->SetOut(Location::SameAsFirstInput()); |
| 6116 | } |
| 6117 | } |
| 6118 | |
| 6119 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6120 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6121 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6122 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6123 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6124 | GenerateClassInitializationCheck(slow_path, |
| 6125 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6126 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6127 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6128 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6129 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6130 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6131 | Immediate(mirror::Class::kStatusInitialized)); |
| 6132 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6133 | __ Bind(slow_path->GetExitLabel()); |
| 6134 | // No need for memory fence, thanks to the X86 memory model. |
| 6135 | } |
| 6136 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6137 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6138 | HLoadString::LoadKind desired_string_load_kind) { |
| 6139 | if (kEmitCompilerReadBarrier) { |
| 6140 | switch (desired_string_load_kind) { |
| 6141 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6142 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6143 | case HLoadString::LoadKind::kBootImageAddress: |
| 6144 | // TODO: Implement for read barrier. |
| 6145 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6146 | default: |
| 6147 | break; |
| 6148 | } |
| 6149 | } |
| 6150 | switch (desired_string_load_kind) { |
| 6151 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6152 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6153 | break; |
| 6154 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6155 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6156 | FALLTHROUGH_INTENDED; |
| 6157 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6158 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6159 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6160 | // is incompatible with it. |
| 6161 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6162 | // with irreducible loops. |
| 6163 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6164 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6165 | } |
| 6166 | break; |
| 6167 | case HLoadString::LoadKind::kBootImageAddress: |
| 6168 | break; |
| 6169 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6170 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6171 | break; |
| 6172 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6173 | break; |
| 6174 | } |
| 6175 | return desired_string_load_kind; |
| 6176 | } |
| 6177 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6178 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6179 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6180 | ? LocationSummary::kCallOnSlowPath |
| 6181 | : LocationSummary::kNoCall; |
| 6182 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6183 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6184 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 6185 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 6186 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 6187 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6188 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6189 | locations->SetOut(Location::RequiresRegister()); |
| 6190 | } |
| 6191 | |
| 6192 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6193 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6194 | Location out_loc = locations->Out(); |
| 6195 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6196 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6197 | switch (load->GetLoadKind()) { |
| 6198 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6199 | DCHECK(!kEmitCompilerReadBarrier); |
| 6200 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6201 | codegen_->RecordStringPatch(load); |
| 6202 | return; // No dex cache slow path. |
| 6203 | } |
| 6204 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6205 | DCHECK(!kEmitCompilerReadBarrier); |
| 6206 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6207 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6208 | codegen_->RecordStringPatch(load); |
| 6209 | return; // No dex cache slow path. |
| 6210 | } |
| 6211 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6212 | DCHECK(!kEmitCompilerReadBarrier); |
| 6213 | DCHECK_NE(load->GetAddress(), 0u); |
| 6214 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6215 | __ movl(out, Immediate(address)); |
| 6216 | codegen_->RecordSimplePatch(); |
| 6217 | return; // No dex cache slow path. |
| 6218 | } |
| 6219 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 6220 | DCHECK_NE(load->GetAddress(), 0u); |
| 6221 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6222 | // /* GcRoot<mirror::String> */ out = *address |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6223 | GenerateGcRootFieldLoad(load, out_loc, Address::Absolute(address)); |
| 6224 | break; |
| 6225 | } |
| 6226 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 6227 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6228 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 6229 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6230 | // /* GcRoot<mirror::String> */ out = *(base + offset) /* PC-relative */ |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6231 | GenerateGcRootFieldLoad( |
| 6232 | load, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6233 | break; |
| 6234 | } |
| 6235 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 6236 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6237 | |
| 6238 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6239 | GenerateGcRootFieldLoad( |
| 6240 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6241 | |
| 6242 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 6243 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
| 6244 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 6245 | GenerateGcRootFieldLoad( |
| 6246 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 6247 | break; |
| 6248 | } |
| 6249 | default: |
| 6250 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 6251 | UNREACHABLE(); |
| 6252 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6253 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6254 | if (!load->IsInDexCache()) { |
| 6255 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6256 | codegen_->AddSlowPath(slow_path); |
| 6257 | __ testl(out, out); |
| 6258 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6259 | __ Bind(slow_path->GetExitLabel()); |
| 6260 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6261 | } |
| 6262 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6263 | static Address GetExceptionTlsAddress() { |
| 6264 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6265 | } |
| 6266 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6267 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6268 | LocationSummary* locations = |
| 6269 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6270 | locations->SetOut(Location::RequiresRegister()); |
| 6271 | } |
| 6272 | |
| 6273 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6274 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6275 | } |
| 6276 | |
| 6277 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6278 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6279 | } |
| 6280 | |
| 6281 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6282 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
| 6285 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6286 | LocationSummary* locations = |
| 6287 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6288 | InvokeRuntimeCallingConvention calling_convention; |
| 6289 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6290 | } |
| 6291 | |
| 6292 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6293 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6294 | instruction, |
| 6295 | instruction->GetDexPc(), |
| 6296 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6297 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6298 | } |
| 6299 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6300 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6301 | return kEmitCompilerReadBarrier && |
| 6302 | (kUseBakerReadBarrier || |
| 6303 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6304 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6305 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6306 | } |
| 6307 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6308 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6309 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6310 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6311 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | case TypeCheckKind::kExactCheck: |
| 6313 | case TypeCheckKind::kAbstractClassCheck: |
| 6314 | case TypeCheckKind::kClassHierarchyCheck: |
| 6315 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6316 | call_kind = |
| 6317 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6318 | break; |
| 6319 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6320 | case TypeCheckKind::kUnresolvedCheck: |
| 6321 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6322 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6323 | break; |
| 6324 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6325 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6326 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6327 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6328 | locations->SetInAt(1, Location::Any()); |
| 6329 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6330 | locations->SetOut(Location::RequiresRegister()); |
| 6331 | // When read barriers are enabled, we need a temporary register for |
| 6332 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6333 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6334 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6335 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6338 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6339 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6340 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6341 | Location obj_loc = locations->InAt(0); |
| 6342 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6343 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6344 | Location out_loc = locations->Out(); |
| 6345 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6346 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6347 | locations->GetTemp(0) : |
| 6348 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6349 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6350 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6351 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6352 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6353 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6354 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6355 | |
| 6356 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6357 | // Avoid null check if we know obj is not null. |
| 6358 | if (instruction->MustDoNullCheck()) { |
| 6359 | __ testl(obj, obj); |
| 6360 | __ j(kEqual, &zero); |
| 6361 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6362 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6364 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6366 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6367 | case TypeCheckKind::kExactCheck: { |
| 6368 | if (cls.IsRegister()) { |
| 6369 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6370 | } else { |
| 6371 | DCHECK(cls.IsStackSlot()) << cls; |
| 6372 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6373 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6374 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6375 | // Classes must be equal for the instanceof to succeed. |
| 6376 | __ j(kNotEqual, &zero); |
| 6377 | __ movl(out, Immediate(1)); |
| 6378 | __ jmp(&done); |
| 6379 | break; |
| 6380 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6381 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6382 | case TypeCheckKind::kAbstractClassCheck: { |
| 6383 | // If the class is abstract, we eagerly fetch the super class of the |
| 6384 | // object to avoid doing a comparison we know will fail. |
| 6385 | NearLabel loop; |
| 6386 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6387 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6388 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6389 | __ testl(out, out); |
| 6390 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6391 | __ j(kEqual, &done); |
| 6392 | if (cls.IsRegister()) { |
| 6393 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6394 | } else { |
| 6395 | DCHECK(cls.IsStackSlot()) << cls; |
| 6396 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6397 | } |
| 6398 | __ j(kNotEqual, &loop); |
| 6399 | __ movl(out, Immediate(1)); |
| 6400 | if (zero.IsLinked()) { |
| 6401 | __ jmp(&done); |
| 6402 | } |
| 6403 | break; |
| 6404 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6407 | // Walk over the class hierarchy to find a match. |
| 6408 | NearLabel loop, success; |
| 6409 | __ Bind(&loop); |
| 6410 | if (cls.IsRegister()) { |
| 6411 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6412 | } else { |
| 6413 | DCHECK(cls.IsStackSlot()) << cls; |
| 6414 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6415 | } |
| 6416 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6417 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6418 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6419 | __ testl(out, out); |
| 6420 | __ j(kNotEqual, &loop); |
| 6421 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6422 | __ jmp(&done); |
| 6423 | __ Bind(&success); |
| 6424 | __ movl(out, Immediate(1)); |
| 6425 | if (zero.IsLinked()) { |
| 6426 | __ jmp(&done); |
| 6427 | } |
| 6428 | break; |
| 6429 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6430 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6432 | // Do an exact check. |
| 6433 | NearLabel exact_check; |
| 6434 | if (cls.IsRegister()) { |
| 6435 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6436 | } else { |
| 6437 | DCHECK(cls.IsStackSlot()) << cls; |
| 6438 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6439 | } |
| 6440 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6441 | // 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] | 6442 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6443 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6444 | __ testl(out, out); |
| 6445 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6446 | __ j(kEqual, &done); |
| 6447 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6448 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6449 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6450 | __ movl(out, Immediate(1)); |
| 6451 | __ jmp(&done); |
| 6452 | break; |
| 6453 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6454 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6455 | case TypeCheckKind::kArrayCheck: { |
| 6456 | if (cls.IsRegister()) { |
| 6457 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6458 | } else { |
| 6459 | DCHECK(cls.IsStackSlot()) << cls; |
| 6460 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6461 | } |
| 6462 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6463 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6464 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6465 | codegen_->AddSlowPath(slow_path); |
| 6466 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6467 | __ movl(out, Immediate(1)); |
| 6468 | if (zero.IsLinked()) { |
| 6469 | __ jmp(&done); |
| 6470 | } |
| 6471 | break; |
| 6472 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6473 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6474 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | case TypeCheckKind::kInterfaceCheck: { |
| 6476 | // 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] | 6477 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6478 | // cases. |
| 6479 | // |
| 6480 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6481 | // entry point without resorting to a type checking slow path |
| 6482 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6483 | // require to assign fixed registers for the inputs of this |
| 6484 | // HInstanceOf instruction (following the runtime calling |
| 6485 | // convention), which might be cluttered by the potential first |
| 6486 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6487 | // |
| 6488 | // TODO: Introduce a new runtime entry point taking the object |
| 6489 | // to test (instead of its class) as argument, and let it deal |
| 6490 | // with the read barrier issues. This will let us refactor this |
| 6491 | // case of the `switch` code as it was previously (with a direct |
| 6492 | // call to the runtime not using a type checking slow path). |
| 6493 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6494 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6495 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6496 | /* is_fatal */ false); |
| 6497 | codegen_->AddSlowPath(slow_path); |
| 6498 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6499 | if (zero.IsLinked()) { |
| 6500 | __ jmp(&done); |
| 6501 | } |
| 6502 | break; |
| 6503 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6504 | } |
| 6505 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6506 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6507 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6508 | __ xorl(out, out); |
| 6509 | } |
| 6510 | |
| 6511 | if (done.IsLinked()) { |
| 6512 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6513 | } |
| 6514 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6515 | if (slow_path != nullptr) { |
| 6516 | __ Bind(slow_path->GetExitLabel()); |
| 6517 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6518 | } |
| 6519 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6520 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6521 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6522 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6523 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6524 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6525 | case TypeCheckKind::kExactCheck: |
| 6526 | case TypeCheckKind::kAbstractClassCheck: |
| 6527 | case TypeCheckKind::kClassHierarchyCheck: |
| 6528 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6529 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6530 | LocationSummary::kCallOnSlowPath : |
| 6531 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6532 | break; |
| 6533 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6534 | case TypeCheckKind::kUnresolvedCheck: |
| 6535 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6536 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6537 | break; |
| 6538 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6539 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6541 | locations->SetInAt(1, Location::Any()); |
| 6542 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6543 | locations->AddTemp(Location::RequiresRegister()); |
| 6544 | // When read barriers are enabled, we need an additional temporary |
| 6545 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6546 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6547 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6548 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6552 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6553 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6554 | Location obj_loc = locations->InAt(0); |
| 6555 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6556 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6557 | Location temp_loc = locations->GetTemp(0); |
| 6558 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6559 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6560 | locations->GetTemp(1) : |
| 6561 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6562 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6563 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6564 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6565 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6566 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6567 | bool is_type_check_slow_path_fatal = |
| 6568 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6569 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6570 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6571 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6572 | !instruction->CanThrowIntoCatchBlock(); |
| 6573 | SlowPathCode* type_check_slow_path = |
| 6574 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6575 | is_type_check_slow_path_fatal); |
| 6576 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6577 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6578 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6579 | // Avoid null check if we know obj is not null. |
| 6580 | if (instruction->MustDoNullCheck()) { |
| 6581 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6582 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6583 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6584 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6585 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6586 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6587 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6588 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6589 | case TypeCheckKind::kExactCheck: |
| 6590 | case TypeCheckKind::kArrayCheck: { |
| 6591 | if (cls.IsRegister()) { |
| 6592 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6593 | } else { |
| 6594 | DCHECK(cls.IsStackSlot()) << cls; |
| 6595 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6596 | } |
| 6597 | // Jump to slow path for throwing the exception or doing a |
| 6598 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6599 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6600 | break; |
| 6601 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6602 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6603 | case TypeCheckKind::kAbstractClassCheck: { |
| 6604 | // If the class is abstract, we eagerly fetch the super class of the |
| 6605 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6606 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6607 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6608 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6609 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6610 | |
| 6611 | // If the class reference currently in `temp` is not null, jump |
| 6612 | // to the `compare_classes` label to compare it with the checked |
| 6613 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6614 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6615 | __ j(kNotEqual, &compare_classes); |
| 6616 | // Otherwise, jump to the slow path to throw the exception. |
| 6617 | // |
| 6618 | // But before, move back the object's class into `temp` before |
| 6619 | // going into the slow path, as it has been overwritten in the |
| 6620 | // meantime. |
| 6621 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6622 | GenerateReferenceLoadTwoRegisters( |
| 6623 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6624 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6625 | |
| 6626 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6627 | if (cls.IsRegister()) { |
| 6628 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6629 | } else { |
| 6630 | DCHECK(cls.IsStackSlot()) << cls; |
| 6631 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6632 | } |
| 6633 | __ j(kNotEqual, &loop); |
| 6634 | break; |
| 6635 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6636 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6637 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6638 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6639 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6640 | __ Bind(&loop); |
| 6641 | if (cls.IsRegister()) { |
| 6642 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6643 | } else { |
| 6644 | DCHECK(cls.IsStackSlot()) << cls; |
| 6645 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6646 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6647 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6648 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6649 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6650 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6651 | |
| 6652 | // If the class reference currently in `temp` is not null, jump |
| 6653 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6654 | __ testl(temp, temp); |
| 6655 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6656 | // Otherwise, jump to the slow path to throw the exception. |
| 6657 | // |
| 6658 | // But before, move back the object's class into `temp` before |
| 6659 | // going into the slow path, as it has been overwritten in the |
| 6660 | // meantime. |
| 6661 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6662 | GenerateReferenceLoadTwoRegisters( |
| 6663 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6664 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6665 | break; |
| 6666 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6668 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6669 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6670 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6671 | if (cls.IsRegister()) { |
| 6672 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6673 | } else { |
| 6674 | DCHECK(cls.IsStackSlot()) << cls; |
| 6675 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6676 | } |
| 6677 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6678 | |
| 6679 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6680 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6681 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6682 | |
| 6683 | // If the component type is not null (i.e. the object is indeed |
| 6684 | // an array), jump to label `check_non_primitive_component_type` |
| 6685 | // to further check that this component type is not a primitive |
| 6686 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6687 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6688 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6689 | // Otherwise, jump to the slow path to throw the exception. |
| 6690 | // |
| 6691 | // But before, move back the object's class into `temp` before |
| 6692 | // going into the slow path, as it has been overwritten in the |
| 6693 | // meantime. |
| 6694 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6695 | GenerateReferenceLoadTwoRegisters( |
| 6696 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6697 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6698 | |
| 6699 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6700 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6701 | __ j(kEqual, &done); |
| 6702 | // Same comment as above regarding `temp` and the slow path. |
| 6703 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6704 | GenerateReferenceLoadTwoRegisters( |
| 6705 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6706 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6707 | break; |
| 6708 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6709 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6710 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6711 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6712 | // We always go into the type check slow path for the unresolved |
| 6713 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6714 | // |
| 6715 | // We cannot directly call the CheckCast runtime entry point |
| 6716 | // without resorting to a type checking slow path here (i.e. by |
| 6717 | // calling InvokeRuntime directly), as it would require to |
| 6718 | // assign fixed registers for the inputs of this HInstanceOf |
| 6719 | // instruction (following the runtime calling convention), which |
| 6720 | // might be cluttered by the potential first read barrier |
| 6721 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6722 | // |
| 6723 | // TODO: Introduce a new runtime entry point taking the object |
| 6724 | // to test (instead of its class) as argument, and let it deal |
| 6725 | // with the read barrier issues. This will let us refactor this |
| 6726 | // case of the `switch` code as it was previously (with a direct |
| 6727 | // call to the runtime not using a type checking slow path). |
| 6728 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6729 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6730 | break; |
| 6731 | } |
| 6732 | __ Bind(&done); |
| 6733 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6734 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6735 | } |
| 6736 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6737 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6738 | LocationSummary* locations = |
| 6739 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6740 | InvokeRuntimeCallingConvention calling_convention; |
| 6741 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6742 | } |
| 6743 | |
| 6744 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6745 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6746 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6747 | instruction, |
| 6748 | instruction->GetDexPc(), |
| 6749 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6750 | if (instruction->IsEnter()) { |
| 6751 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6752 | } else { |
| 6753 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6754 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6755 | } |
| 6756 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6757 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6758 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6759 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6760 | |
| 6761 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6762 | LocationSummary* locations = |
| 6763 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6764 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6765 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6766 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6767 | locations->SetInAt(1, Location::Any()); |
| 6768 | locations->SetOut(Location::SameAsFirstInput()); |
| 6769 | } |
| 6770 | |
| 6771 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6772 | HandleBitwiseOperation(instruction); |
| 6773 | } |
| 6774 | |
| 6775 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6776 | HandleBitwiseOperation(instruction); |
| 6777 | } |
| 6778 | |
| 6779 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6780 | HandleBitwiseOperation(instruction); |
| 6781 | } |
| 6782 | |
| 6783 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6784 | LocationSummary* locations = instruction->GetLocations(); |
| 6785 | Location first = locations->InAt(0); |
| 6786 | Location second = locations->InAt(1); |
| 6787 | DCHECK(first.Equals(locations->Out())); |
| 6788 | |
| 6789 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6790 | if (second.IsRegister()) { |
| 6791 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6792 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6793 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6794 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6795 | } else { |
| 6796 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6797 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6798 | } |
| 6799 | } else if (second.IsConstant()) { |
| 6800 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6801 | __ andl(first.AsRegister<Register>(), |
| 6802 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6803 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6804 | __ orl(first.AsRegister<Register>(), |
| 6805 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6806 | } else { |
| 6807 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6808 | __ xorl(first.AsRegister<Register>(), |
| 6809 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6810 | } |
| 6811 | } else { |
| 6812 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6813 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6814 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6815 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6816 | } else { |
| 6817 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6818 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6819 | } |
| 6820 | } |
| 6821 | } else { |
| 6822 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6823 | if (second.IsRegisterPair()) { |
| 6824 | if (instruction->IsAnd()) { |
| 6825 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6826 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6827 | } else if (instruction->IsOr()) { |
| 6828 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6829 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6830 | } else { |
| 6831 | DCHECK(instruction->IsXor()); |
| 6832 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6833 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6834 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6835 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6836 | if (instruction->IsAnd()) { |
| 6837 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6838 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6839 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6840 | } else if (instruction->IsOr()) { |
| 6841 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6842 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6843 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6844 | } else { |
| 6845 | DCHECK(instruction->IsXor()); |
| 6846 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6847 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6848 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6849 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6850 | } else { |
| 6851 | DCHECK(second.IsConstant()) << second; |
| 6852 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6853 | int32_t low_value = Low32Bits(value); |
| 6854 | int32_t high_value = High32Bits(value); |
| 6855 | Immediate low(low_value); |
| 6856 | Immediate high(high_value); |
| 6857 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6858 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6859 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6860 | if (low_value == 0) { |
| 6861 | __ xorl(first_low, first_low); |
| 6862 | } else if (low_value != -1) { |
| 6863 | __ andl(first_low, low); |
| 6864 | } |
| 6865 | if (high_value == 0) { |
| 6866 | __ xorl(first_high, first_high); |
| 6867 | } else if (high_value != -1) { |
| 6868 | __ andl(first_high, high); |
| 6869 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6870 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6871 | if (low_value != 0) { |
| 6872 | __ orl(first_low, low); |
| 6873 | } |
| 6874 | if (high_value != 0) { |
| 6875 | __ orl(first_high, high); |
| 6876 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6877 | } else { |
| 6878 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6879 | if (low_value != 0) { |
| 6880 | __ xorl(first_low, low); |
| 6881 | } |
| 6882 | if (high_value != 0) { |
| 6883 | __ xorl(first_high, high); |
| 6884 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6885 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6886 | } |
| 6887 | } |
| 6888 | } |
| 6889 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6890 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6891 | Location out, |
| 6892 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6893 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6894 | Register out_reg = out.AsRegister<Register>(); |
| 6895 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6896 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6897 | if (kUseBakerReadBarrier) { |
| 6898 | // Load with fast path based Baker's read barrier. |
| 6899 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6900 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6901 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6902 | } else { |
| 6903 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6904 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6905 | // in the following move operation, as we will need it for the |
| 6906 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6907 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6908 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6909 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6910 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6911 | } |
| 6912 | } else { |
| 6913 | // Plain load with no read barrier. |
| 6914 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6915 | __ movl(out_reg, Address(out_reg, offset)); |
| 6916 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6917 | } |
| 6918 | } |
| 6919 | |
| 6920 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6921 | Location out, |
| 6922 | Location obj, |
| 6923 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6924 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6925 | Register out_reg = out.AsRegister<Register>(); |
| 6926 | Register obj_reg = obj.AsRegister<Register>(); |
| 6927 | if (kEmitCompilerReadBarrier) { |
| 6928 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6929 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6930 | // Load with fast path based Baker's read barrier. |
| 6931 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6932 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6933 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6934 | } else { |
| 6935 | // Load with slow path based read barrier. |
| 6936 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6937 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6938 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6939 | } |
| 6940 | } else { |
| 6941 | // Plain load with no read barrier. |
| 6942 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6943 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6944 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6949 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6950 | const Address& address, |
| 6951 | Label* fixup_label) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6952 | Register root_reg = root.AsRegister<Register>(); |
| 6953 | if (kEmitCompilerReadBarrier) { |
| 6954 | if (kUseBakerReadBarrier) { |
| 6955 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6956 | // Baker's read barrier are used: |
| 6957 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6958 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6959 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6960 | // root = ReadBarrier::Mark(root) |
| 6961 | // } |
| 6962 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6963 | // /* GcRoot<mirror::Object> */ root = *address |
| 6964 | __ movl(root_reg, address); |
| 6965 | if (fixup_label != nullptr) { |
| 6966 | __ Bind(fixup_label); |
| 6967 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6968 | static_assert( |
| 6969 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6970 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6971 | "have different sizes."); |
| 6972 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6973 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6974 | "have different sizes."); |
| 6975 | |
| 6976 | // Slow path used to mark the GC root `root`. |
| 6977 | SlowPathCode* slow_path = |
| 6978 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6979 | codegen_->AddSlowPath(slow_path); |
| 6980 | |
| 6981 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6982 | Immediate(0)); |
| 6983 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6984 | __ Bind(slow_path->GetExitLabel()); |
| 6985 | } else { |
| 6986 | // GC root loaded through a slow path for read barriers other |
| 6987 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6988 | // /* GcRoot<mirror::Object>* */ root = address |
| 6989 | __ leal(root_reg, address); |
| 6990 | if (fixup_label != nullptr) { |
| 6991 | __ Bind(fixup_label); |
| 6992 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6993 | // /* mirror::Object* */ root = root->Read() |
| 6994 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6995 | } |
| 6996 | } else { |
| 6997 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6998 | // /* GcRoot<mirror::Object> */ root = *address |
| 6999 | __ movl(root_reg, address); |
| 7000 | if (fixup_label != nullptr) { |
| 7001 | __ Bind(fixup_label); |
| 7002 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7003 | // Note that GC roots are not affected by heap poisoning, thus we |
| 7004 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7009 | Location ref, |
| 7010 | Register obj, |
| 7011 | uint32_t offset, |
| 7012 | Location temp, |
| 7013 | bool needs_null_check) { |
| 7014 | DCHECK(kEmitCompilerReadBarrier); |
| 7015 | DCHECK(kUseBakerReadBarrier); |
| 7016 | |
| 7017 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 7018 | Address src(obj, offset); |
| 7019 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 7020 | } |
| 7021 | |
| 7022 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7023 | Location ref, |
| 7024 | Register obj, |
| 7025 | uint32_t data_offset, |
| 7026 | Location index, |
| 7027 | Location temp, |
| 7028 | bool needs_null_check) { |
| 7029 | DCHECK(kEmitCompilerReadBarrier); |
| 7030 | DCHECK(kUseBakerReadBarrier); |
| 7031 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7032 | static_assert( |
| 7033 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 7034 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7035 | // /* HeapReference<Object> */ ref = |
| 7036 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 7037 | Address src = index.IsConstant() ? |
| 7038 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 7039 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 7040 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 7041 | } |
| 7042 | |
| 7043 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7044 | Location ref, |
| 7045 | Register obj, |
| 7046 | const Address& src, |
| 7047 | Location temp, |
| 7048 | bool needs_null_check) { |
| 7049 | DCHECK(kEmitCompilerReadBarrier); |
| 7050 | DCHECK(kUseBakerReadBarrier); |
| 7051 | |
| 7052 | // In slow path based read barriers, the read barrier call is |
| 7053 | // inserted after the original load. However, in fast path based |
| 7054 | // Baker's read barriers, we need to perform the load of |
| 7055 | // mirror::Object::monitor_ *before* the original reference load. |
| 7056 | // This load-load ordering is required by the read barrier. |
| 7057 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7058 | // |
| 7059 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7060 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7061 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7062 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 7063 | // if (is_gray) { |
| 7064 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7065 | // } |
| 7066 | // |
| 7067 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7068 | // slightly more complex as: |
| 7069 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7070 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7071 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7072 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7073 | // - it performs additional checks that we do not do here for |
| 7074 | // performance reasons. |
| 7075 | |
| 7076 | Register ref_reg = ref.AsRegister<Register>(); |
| 7077 | Register temp_reg = temp.AsRegister<Register>(); |
| 7078 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7079 | |
| 7080 | // /* int32_t */ monitor = obj->monitor_ |
| 7081 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 7082 | if (needs_null_check) { |
| 7083 | MaybeRecordImplicitNullCheck(instruction); |
| 7084 | } |
| 7085 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7086 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7087 | "art::LockWord and int32_t have different sizes."); |
| 7088 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 7089 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 7090 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 7091 | static_assert( |
| 7092 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 7093 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 7094 | |
| 7095 | // Load fence to prevent load-load reordering. |
| 7096 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7097 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7098 | |
| 7099 | // The actual reference load. |
| 7100 | // /* HeapReference<Object> */ ref = *src |
| 7101 | __ movl(ref_reg, src); |
| 7102 | |
| 7103 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7104 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7105 | |
| 7106 | // Slow path used to mark the object `ref` when it is gray. |
| 7107 | SlowPathCode* slow_path = |
| 7108 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 7109 | AddSlowPath(slow_path); |
| 7110 | |
| 7111 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 7112 | // ref = ReadBarrier::Mark(ref); |
| 7113 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 7114 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7115 | __ Bind(slow_path->GetExitLabel()); |
| 7116 | } |
| 7117 | |
| 7118 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7119 | Location out, |
| 7120 | Location ref, |
| 7121 | Location obj, |
| 7122 | uint32_t offset, |
| 7123 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7124 | DCHECK(kEmitCompilerReadBarrier); |
| 7125 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7126 | // Insert a slow path based read barrier *after* the reference load. |
| 7127 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7128 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7129 | // reference will be carried out by the runtime within the slow |
| 7130 | // path. |
| 7131 | // |
| 7132 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7133 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7134 | // not used by the artReadBarrierSlow entry point. |
| 7135 | // |
| 7136 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7137 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7138 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7139 | AddSlowPath(slow_path); |
| 7140 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7141 | __ jmp(slow_path->GetEntryLabel()); |
| 7142 | __ Bind(slow_path->GetExitLabel()); |
| 7143 | } |
| 7144 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7145 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7146 | Location out, |
| 7147 | Location ref, |
| 7148 | Location obj, |
| 7149 | uint32_t offset, |
| 7150 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7151 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7152 | // Baker's read barriers shall be handled by the fast path |
| 7153 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7154 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7155 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7156 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7157 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7158 | } else if (kPoisonHeapReferences) { |
| 7159 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7160 | } |
| 7161 | } |
| 7162 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7163 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7164 | Location out, |
| 7165 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7166 | DCHECK(kEmitCompilerReadBarrier); |
| 7167 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7168 | // Insert a slow path based read barrier *after* the GC root load. |
| 7169 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7170 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7171 | // not need to do anything special for this here. |
| 7172 | SlowPathCode* slow_path = |
| 7173 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7174 | AddSlowPath(slow_path); |
| 7175 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7176 | __ jmp(slow_path->GetEntryLabel()); |
| 7177 | __ Bind(slow_path->GetExitLabel()); |
| 7178 | } |
| 7179 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7180 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7181 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7182 | LOG(FATAL) << "Unreachable"; |
| 7183 | } |
| 7184 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7185 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7186 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7187 | LOG(FATAL) << "Unreachable"; |
| 7188 | } |
| 7189 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7190 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7191 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7192 | LocationSummary* locations = |
| 7193 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7194 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7195 | } |
| 7196 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7197 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7198 | int32_t lower_bound, |
| 7199 | uint32_t num_entries, |
| 7200 | HBasicBlock* switch_block, |
| 7201 | HBasicBlock* default_block) { |
| 7202 | // Figure out the correct compare values and jump conditions. |
| 7203 | // Handle the first compare/branch as a special case because it might |
| 7204 | // jump to the default case. |
| 7205 | DCHECK_GT(num_entries, 2u); |
| 7206 | Condition first_condition; |
| 7207 | uint32_t index; |
| 7208 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7209 | if (lower_bound != 0) { |
| 7210 | first_condition = kLess; |
| 7211 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7212 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7213 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7214 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7215 | index = 1; |
| 7216 | } else { |
| 7217 | // Handle all the compare/jumps below. |
| 7218 | first_condition = kBelow; |
| 7219 | index = 0; |
| 7220 | } |
| 7221 | |
| 7222 | // Handle the rest of the compare/jumps. |
| 7223 | for (; index + 1 < num_entries; index += 2) { |
| 7224 | int32_t compare_to_value = lower_bound + index + 1; |
| 7225 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7226 | // Jump to successors[index] if value < case_value[index]. |
| 7227 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7228 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7229 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7230 | } |
| 7231 | |
| 7232 | if (index != num_entries) { |
| 7233 | // There are an odd number of entries. Handle the last one. |
| 7234 | DCHECK_EQ(index + 1, num_entries); |
| 7235 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7236 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7237 | } |
| 7238 | |
| 7239 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7240 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7241 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7242 | } |
| 7243 | } |
| 7244 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7245 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7246 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7247 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7248 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7249 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7250 | |
| 7251 | GenPackedSwitchWithCompares(value_reg, |
| 7252 | lower_bound, |
| 7253 | num_entries, |
| 7254 | switch_instr->GetBlock(), |
| 7255 | switch_instr->GetDefaultBlock()); |
| 7256 | } |
| 7257 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7258 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7259 | LocationSummary* locations = |
| 7260 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7261 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7262 | |
| 7263 | // Constant area pointer. |
| 7264 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7265 | |
| 7266 | // And the temporary we need. |
| 7267 | locations->AddTemp(Location::RequiresRegister()); |
| 7268 | } |
| 7269 | |
| 7270 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7271 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7272 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7273 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7274 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7275 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7276 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7277 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7278 | GenPackedSwitchWithCompares(value_reg, |
| 7279 | lower_bound, |
| 7280 | num_entries, |
| 7281 | switch_instr->GetBlock(), |
| 7282 | default_block); |
| 7283 | return; |
| 7284 | } |
| 7285 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7286 | // Optimizing has a jump area. |
| 7287 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7288 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7289 | |
| 7290 | // Remove the bias, if needed. |
| 7291 | if (lower_bound != 0) { |
| 7292 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7293 | value_reg = temp_reg; |
| 7294 | } |
| 7295 | |
| 7296 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7297 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7298 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7299 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7300 | |
| 7301 | // We are in the range of the table. |
| 7302 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7303 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7304 | |
| 7305 | // Compute the actual target address by adding in constant_area. |
| 7306 | __ addl(temp_reg, constant_area); |
| 7307 | |
| 7308 | // And jump. |
| 7309 | __ jmp(temp_reg); |
| 7310 | } |
| 7311 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7312 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7313 | HX86ComputeBaseMethodAddress* insn) { |
| 7314 | LocationSummary* locations = |
| 7315 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7316 | locations->SetOut(Location::RequiresRegister()); |
| 7317 | } |
| 7318 | |
| 7319 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7320 | HX86ComputeBaseMethodAddress* insn) { |
| 7321 | LocationSummary* locations = insn->GetLocations(); |
| 7322 | Register reg = locations->Out().AsRegister<Register>(); |
| 7323 | |
| 7324 | // Generate call to next instruction. |
| 7325 | Label next_instruction; |
| 7326 | __ call(&next_instruction); |
| 7327 | __ Bind(&next_instruction); |
| 7328 | |
| 7329 | // Remember this offset for later use with constant area. |
| 7330 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7331 | |
| 7332 | // Grab the return address off the stack. |
| 7333 | __ popl(reg); |
| 7334 | } |
| 7335 | |
| 7336 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7337 | HX86LoadFromConstantTable* insn) { |
| 7338 | LocationSummary* locations = |
| 7339 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7340 | |
| 7341 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7342 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7343 | |
| 7344 | // 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] | 7345 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7346 | return; |
| 7347 | } |
| 7348 | |
| 7349 | switch (insn->GetType()) { |
| 7350 | case Primitive::kPrimFloat: |
| 7351 | case Primitive::kPrimDouble: |
| 7352 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7353 | break; |
| 7354 | |
| 7355 | case Primitive::kPrimInt: |
| 7356 | locations->SetOut(Location::RequiresRegister()); |
| 7357 | break; |
| 7358 | |
| 7359 | default: |
| 7360 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7361 | } |
| 7362 | } |
| 7363 | |
| 7364 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7365 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7366 | return; |
| 7367 | } |
| 7368 | |
| 7369 | LocationSummary* locations = insn->GetLocations(); |
| 7370 | Location out = locations->Out(); |
| 7371 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7372 | HConstant *value = insn->GetConstant(); |
| 7373 | |
| 7374 | switch (insn->GetType()) { |
| 7375 | case Primitive::kPrimFloat: |
| 7376 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7377 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7378 | break; |
| 7379 | |
| 7380 | case Primitive::kPrimDouble: |
| 7381 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7382 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7383 | break; |
| 7384 | |
| 7385 | case Primitive::kPrimInt: |
| 7386 | __ movl(out.AsRegister<Register>(), |
| 7387 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7388 | break; |
| 7389 | |
| 7390 | default: |
| 7391 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7392 | } |
| 7393 | } |
| 7394 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7395 | /** |
| 7396 | * Class to handle late fixup of offsets into constant area. |
| 7397 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7398 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7399 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7400 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7401 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7402 | |
| 7403 | protected: |
| 7404 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7405 | |
| 7406 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7407 | |
| 7408 | private: |
| 7409 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7410 | // Patch the correct offset for the instruction. The place to patch is the |
| 7411 | // last 4 bytes of the instruction. |
| 7412 | // The value to patch is the distance from the offset in the constant area |
| 7413 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7414 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7415 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7416 | |
| 7417 | // Patch in the right value. |
| 7418 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7419 | } |
| 7420 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7421 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7422 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7423 | }; |
| 7424 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7425 | /** |
| 7426 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7427 | * constant area. |
| 7428 | */ |
| 7429 | class JumpTableRIPFixup : public RIPFixup { |
| 7430 | public: |
| 7431 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7432 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7433 | |
| 7434 | void CreateJumpTable() { |
| 7435 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7436 | |
| 7437 | // Ensure that the reference to the jump table has the correct offset. |
| 7438 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7439 | SetOffset(offset_in_constant_table); |
| 7440 | |
| 7441 | // The label values in the jump table are computed relative to the |
| 7442 | // instruction addressing the constant area. |
| 7443 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7444 | |
| 7445 | // Populate the jump table with the correct values for the jump table. |
| 7446 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7447 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7448 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7449 | // The value that we want is the target offset - the position of the table. |
| 7450 | for (int32_t i = 0; i < num_entries; i++) { |
| 7451 | HBasicBlock* b = successors[i]; |
| 7452 | Label* l = codegen_->GetLabelOf(b); |
| 7453 | DCHECK(l->IsBound()); |
| 7454 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7455 | assembler->AppendInt32(offset_to_block); |
| 7456 | } |
| 7457 | } |
| 7458 | |
| 7459 | private: |
| 7460 | const HX86PackedSwitch* switch_instr_; |
| 7461 | }; |
| 7462 | |
| 7463 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7464 | // Generate the constant area if needed. |
| 7465 | X86Assembler* assembler = GetAssembler(); |
| 7466 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7467 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7468 | // byte values. |
| 7469 | assembler->Align(4, 0); |
| 7470 | constant_area_start_ = assembler->CodeSize(); |
| 7471 | |
| 7472 | // Populate any jump tables. |
| 7473 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7474 | jump_table->CreateJumpTable(); |
| 7475 | } |
| 7476 | |
| 7477 | // And now add the constant area to the generated code. |
| 7478 | assembler->AddConstantArea(); |
| 7479 | } |
| 7480 | |
| 7481 | // And finish up. |
| 7482 | CodeGenerator::Finalize(allocator); |
| 7483 | } |
| 7484 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7485 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7486 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7487 | return Address(reg, kDummy32BitOffset, fixup); |
| 7488 | } |
| 7489 | |
| 7490 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7491 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7492 | return Address(reg, kDummy32BitOffset, fixup); |
| 7493 | } |
| 7494 | |
| 7495 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7496 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7497 | return Address(reg, kDummy32BitOffset, fixup); |
| 7498 | } |
| 7499 | |
| 7500 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7501 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7502 | return Address(reg, kDummy32BitOffset, fixup); |
| 7503 | } |
| 7504 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7505 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7506 | if (value == 0) { |
| 7507 | __ xorl(dest, dest); |
| 7508 | } else { |
| 7509 | __ movl(dest, Immediate(value)); |
| 7510 | } |
| 7511 | } |
| 7512 | |
| 7513 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7514 | if (value == 0) { |
| 7515 | __ testl(dest, dest); |
| 7516 | } else { |
| 7517 | __ cmpl(dest, Immediate(value)); |
| 7518 | } |
| 7519 | } |
| 7520 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7521 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7522 | Register reg, |
| 7523 | Register value) { |
| 7524 | // Create a fixup to be used to create and address the jump table. |
| 7525 | JumpTableRIPFixup* table_fixup = |
| 7526 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7527 | |
| 7528 | // We have to populate the jump tables. |
| 7529 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7530 | |
| 7531 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7532 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7533 | } |
| 7534 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7535 | // TODO: target as memory. |
| 7536 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7537 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7538 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7539 | return; |
| 7540 | } |
| 7541 | |
| 7542 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7543 | |
| 7544 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7545 | if (target.Equals(return_loc)) { |
| 7546 | return; |
| 7547 | } |
| 7548 | |
| 7549 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7550 | // with the else branch. |
| 7551 | if (type == Primitive::kPrimLong) { |
| 7552 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7553 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7554 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7555 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7556 | } else { |
| 7557 | // Let the parallel move resolver take care of all of this. |
| 7558 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7559 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7560 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7561 | } |
| 7562 | } |
| 7563 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7564 | #undef __ |
| 7565 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7566 | } // namespace x86 |
| 7567 | } // namespace art |