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 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 144 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 147 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 148 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 149 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 150 | Primitive::kPrimInt); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 151 | uint32_t entry_point_offset = instruction_->AsBoundsCheck()->IsStringCharAt() |
| 152 | ? QUICK_ENTRY_POINT(pThrowStringBounds) |
| 153 | : QUICK_ENTRY_POINT(pThrowArrayBounds); |
| 154 | x86_codegen->InvokeRuntime(entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 155 | instruction_, |
| 156 | instruction_->GetDexPc(), |
| 157 | this); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 158 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 159 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 162 | bool IsFatal() const OVERRIDE { return true; } |
| 163 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 164 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 165 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 166 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 167 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 168 | }; |
| 169 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 170 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 172 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 173 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 174 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 175 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 176 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 177 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 178 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 179 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 180 | instruction_, |
| 181 | instruction_->GetDexPc(), |
| 182 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 183 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 184 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | if (successor_ == nullptr) { |
| 186 | __ jmp(GetReturnLabel()); |
| 187 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 188 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 189 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 192 | Label* GetReturnLabel() { |
| 193 | DCHECK(successor_ == nullptr); |
| 194 | return &return_label_; |
| 195 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 196 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 197 | HBasicBlock* GetSuccessor() const { |
| 198 | return successor_; |
| 199 | } |
| 200 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 201 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 202 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 203 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 204 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | Label return_label_; |
| 206 | |
| 207 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 208 | }; |
| 209 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 210 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 211 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 212 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 213 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 214 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | LocationSummary* locations = instruction_->GetLocations(); |
| 216 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 217 | |
| 218 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 219 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 220 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 221 | |
| 222 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 223 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 224 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 225 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 226 | instruction_, |
| 227 | instruction_->GetDexPc(), |
| 228 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 229 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 231 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 232 | |
| 233 | __ jmp(GetExitLabel()); |
| 234 | } |
| 235 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 236 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 237 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 238 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 239 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 240 | }; |
| 241 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 242 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 243 | public: |
| 244 | LoadClassSlowPathX86(HLoadClass* cls, |
| 245 | HInstruction* at, |
| 246 | uint32_t dex_pc, |
| 247 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 248 | : 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] | 249 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 250 | } |
| 251 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 252 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | LocationSummary* locations = at_->GetLocations(); |
| 254 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 255 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 256 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | |
| 258 | InvokeRuntimeCallingConvention calling_convention; |
| 259 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 260 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 261 | : QUICK_ENTRY_POINT(pInitializeType), |
| 262 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 263 | if (do_clinit_) { |
| 264 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 265 | } else { |
| 266 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 267 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | |
| 269 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | Location out = locations->Out(); |
| 271 | if (out.IsValid()) { |
| 272 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 273 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 275 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 276 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | __ jmp(GetExitLabel()); |
| 278 | } |
| 279 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 280 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 281 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 282 | private: |
| 283 | // The class this slow path will load. |
| 284 | HLoadClass* const cls_; |
| 285 | |
| 286 | // The instruction where this slow path is happening. |
| 287 | // (Might be the load class or an initialization check). |
| 288 | HInstruction* const at_; |
| 289 | |
| 290 | // The dex PC of `at_`. |
| 291 | const uint32_t dex_pc_; |
| 292 | |
| 293 | // Whether to initialize the class. |
| 294 | const bool do_clinit_; |
| 295 | |
| 296 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 297 | }; |
| 298 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 299 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 300 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 301 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 302 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 304 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 306 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 307 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 308 | DCHECK(instruction_->IsCheckCast() |
| 309 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
| 311 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 312 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 313 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 314 | if (!is_fatal_) { |
| 315 | SaveLiveRegisters(codegen, locations); |
| 316 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
| 318 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 319 | // move resolver. |
| 320 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 321 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 322 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 323 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 324 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 325 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 326 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 327 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 330 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 331 | instruction_, |
| 332 | instruction_->GetDexPc(), |
| 333 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 334 | CheckEntrypointTypes< |
| 335 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | } else { |
| 337 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 338 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 339 | instruction_, |
| 340 | instruction_->GetDexPc(), |
| 341 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 342 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 345 | if (!is_fatal_) { |
| 346 | if (instruction_->IsInstanceOf()) { |
| 347 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 348 | } |
| 349 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | __ jmp(GetExitLabel()); |
| 352 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 355 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 356 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 357 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 358 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 359 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 360 | |
| 361 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 362 | }; |
| 363 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 364 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 365 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 366 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 367 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | |
| 369 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 370 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 371 | __ Bind(GetEntryLabel()); |
| 372 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 373 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 374 | instruction_, |
| 375 | instruction_->GetDexPc(), |
| 376 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 377 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 380 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 381 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 384 | }; |
| 385 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 386 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 387 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 388 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 389 | |
| 390 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 391 | LocationSummary* locations = instruction_->GetLocations(); |
| 392 | __ Bind(GetEntryLabel()); |
| 393 | SaveLiveRegisters(codegen, locations); |
| 394 | |
| 395 | InvokeRuntimeCallingConvention calling_convention; |
| 396 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 397 | parallel_move.AddMove( |
| 398 | locations->InAt(0), |
| 399 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 400 | Primitive::kPrimNot, |
| 401 | nullptr); |
| 402 | parallel_move.AddMove( |
| 403 | locations->InAt(1), |
| 404 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 405 | Primitive::kPrimInt, |
| 406 | nullptr); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(2), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 410 | Primitive::kPrimNot, |
| 411 | nullptr); |
| 412 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 413 | |
| 414 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 415 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 416 | instruction_, |
| 417 | instruction_->GetDexPc(), |
| 418 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 419 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 420 | RestoreLiveRegisters(codegen, locations); |
| 421 | __ jmp(GetExitLabel()); |
| 422 | } |
| 423 | |
| 424 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 425 | |
| 426 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 427 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 428 | }; |
| 429 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 430 | // Slow path marking an object during a read barrier. |
| 431 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 432 | public: |
| 433 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 434 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 435 | DCHECK(kEmitCompilerReadBarrier); |
| 436 | } |
| 437 | |
| 438 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 439 | |
| 440 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 441 | LocationSummary* locations = instruction_->GetLocations(); |
| 442 | Register reg_out = out_.AsRegister<Register>(); |
| 443 | DCHECK(locations->CanCall()); |
| 444 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 445 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 446 | instruction_->IsStaticFieldGet() || |
| 447 | instruction_->IsArrayGet() || |
| 448 | instruction_->IsLoadClass() || |
| 449 | instruction_->IsLoadString() || |
| 450 | instruction_->IsInstanceOf() || |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 451 | instruction_->IsCheckCast() || |
| 452 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
| 453 | instruction_->GetLocations()->Intrinsified())) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 454 | << "Unexpected instruction in read barrier marking slow path: " |
| 455 | << instruction_->DebugName(); |
| 456 | |
| 457 | __ Bind(GetEntryLabel()); |
| 458 | SaveLiveRegisters(codegen, locations); |
| 459 | |
| 460 | InvokeRuntimeCallingConvention calling_convention; |
| 461 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 462 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 463 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 464 | instruction_, |
| 465 | instruction_->GetDexPc(), |
| 466 | this); |
| 467 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 468 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 469 | |
| 470 | RestoreLiveRegisters(codegen, locations); |
| 471 | __ jmp(GetExitLabel()); |
| 472 | } |
| 473 | |
| 474 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 475 | const Location out_; |
| 476 | const Location obj_; |
| 477 | |
| 478 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 479 | }; |
| 480 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 481 | // Slow path generating a read barrier for a heap reference. |
| 482 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 483 | public: |
| 484 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 485 | Location out, |
| 486 | Location ref, |
| 487 | Location obj, |
| 488 | uint32_t offset, |
| 489 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 490 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 491 | out_(out), |
| 492 | ref_(ref), |
| 493 | obj_(obj), |
| 494 | offset_(offset), |
| 495 | index_(index) { |
| 496 | DCHECK(kEmitCompilerReadBarrier); |
| 497 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 498 | // has been overwritten by (or after) the heap object reference load |
| 499 | // to be instrumented, e.g.: |
| 500 | // |
| 501 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 502 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 503 | // |
| 504 | // In that case, we have lost the information about the original |
| 505 | // object, and the emitted read barrier cannot work properly. |
| 506 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 507 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 508 | } |
| 509 | |
| 510 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 511 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 512 | LocationSummary* locations = instruction_->GetLocations(); |
| 513 | Register reg_out = out_.AsRegister<Register>(); |
| 514 | DCHECK(locations->CanCall()); |
| 515 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 516 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 517 | instruction_->IsStaticFieldGet() || |
| 518 | instruction_->IsArrayGet() || |
| 519 | instruction_->IsInstanceOf() || |
| 520 | instruction_->IsCheckCast() || |
| 521 | ((instruction_->IsInvokeStaticOrDirect() || instruction_->IsInvokeVirtual()) && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 522 | instruction_->GetLocations()->Intrinsified())) |
| 523 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 524 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 525 | |
| 526 | __ Bind(GetEntryLabel()); |
| 527 | SaveLiveRegisters(codegen, locations); |
| 528 | |
| 529 | // We may have to change the index's value, but as `index_` is a |
| 530 | // constant member (like other "inputs" of this slow path), |
| 531 | // introduce a copy of it, `index`. |
| 532 | Location index = index_; |
| 533 | if (index_.IsValid()) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 534 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 535 | if (instruction_->IsArrayGet()) { |
| 536 | // Compute the actual memory offset and store it in `index`. |
| 537 | Register index_reg = index_.AsRegister<Register>(); |
| 538 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 539 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 540 | // We are about to change the value of `index_reg` (see the |
| 541 | // calls to art::x86::X86Assembler::shll and |
| 542 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 543 | // not been saved by the previous call to |
| 544 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 545 | // callee-save register -- |
| 546 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 547 | // callee-save registers, as it has been designed with the |
| 548 | // assumption that callee-save registers are supposed to be |
| 549 | // handled by the called function. So, as a callee-save |
| 550 | // register, `index_reg` _would_ eventually be saved onto |
| 551 | // the stack, but it would be too late: we would have |
| 552 | // changed its value earlier. Therefore, we manually save |
| 553 | // it here into another freely available register, |
| 554 | // `free_reg`, chosen of course among the caller-save |
| 555 | // registers (as a callee-save `free_reg` register would |
| 556 | // exhibit the same problem). |
| 557 | // |
| 558 | // Note we could have requested a temporary register from |
| 559 | // the register allocator instead; but we prefer not to, as |
| 560 | // this is a slow path, and we know we can find a |
| 561 | // caller-save register that is available. |
| 562 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 563 | __ movl(free_reg, index_reg); |
| 564 | index_reg = free_reg; |
| 565 | index = Location::RegisterLocation(index_reg); |
| 566 | } else { |
| 567 | // The initial register stored in `index_` has already been |
| 568 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 569 | // (as it is not a callee-save register), so we can freely |
| 570 | // use it. |
| 571 | } |
| 572 | // Shifting the index value contained in `index_reg` by the scale |
| 573 | // factor (2) cannot overflow in practice, as the runtime is |
| 574 | // unable to allocate object arrays with a size larger than |
| 575 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 576 | __ shll(index_reg, Immediate(TIMES_4)); |
| 577 | static_assert( |
| 578 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 579 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 580 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 581 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 582 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile |
| 583 | // intrinsics, `index_` is not shifted by a scale factor of 2 |
| 584 | // (as in the case of ArrayGet), as it is actually an offset |
| 585 | // to an object field within an object. |
| 586 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 587 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 588 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 589 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 590 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 591 | DCHECK_EQ(offset_, 0U); |
| 592 | DCHECK(index_.IsRegisterPair()); |
| 593 | // UnsafeGet's offset location is a register pair, the low |
| 594 | // part contains the correct offset. |
| 595 | index = index_.ToLow(); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | // We're moving two or three locations to locations that could |
| 600 | // overlap, so we need a parallel move resolver. |
| 601 | InvokeRuntimeCallingConvention calling_convention; |
| 602 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 603 | parallel_move.AddMove(ref_, |
| 604 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 605 | Primitive::kPrimNot, |
| 606 | nullptr); |
| 607 | parallel_move.AddMove(obj_, |
| 608 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 609 | Primitive::kPrimNot, |
| 610 | nullptr); |
| 611 | if (index.IsValid()) { |
| 612 | parallel_move.AddMove(index, |
| 613 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 614 | Primitive::kPrimInt, |
| 615 | nullptr); |
| 616 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 617 | } else { |
| 618 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 619 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 620 | } |
| 621 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 622 | instruction_, |
| 623 | instruction_->GetDexPc(), |
| 624 | this); |
| 625 | CheckEntrypointTypes< |
| 626 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 627 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 628 | |
| 629 | RestoreLiveRegisters(codegen, locations); |
| 630 | __ jmp(GetExitLabel()); |
| 631 | } |
| 632 | |
| 633 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 634 | |
| 635 | private: |
| 636 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 637 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 638 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 639 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 640 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 641 | return static_cast<Register>(i); |
| 642 | } |
| 643 | } |
| 644 | // We shall never fail to find a free caller-save register, as |
| 645 | // there are more than two core caller-save registers on x86 |
| 646 | // (meaning it is possible to find one which is different from |
| 647 | // `ref` and `obj`). |
| 648 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 649 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 650 | UNREACHABLE(); |
| 651 | } |
| 652 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 653 | const Location out_; |
| 654 | const Location ref_; |
| 655 | const Location obj_; |
| 656 | const uint32_t offset_; |
| 657 | // An additional location containing an index to an array. |
| 658 | // Only used for HArrayGet and the UnsafeGetObject & |
| 659 | // UnsafeGetObjectVolatile intrinsics. |
| 660 | const Location index_; |
| 661 | |
| 662 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 663 | }; |
| 664 | |
| 665 | // Slow path generating a read barrier for a GC root. |
| 666 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 667 | public: |
| 668 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 669 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 670 | DCHECK(kEmitCompilerReadBarrier); |
| 671 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 672 | |
| 673 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 674 | LocationSummary* locations = instruction_->GetLocations(); |
| 675 | Register reg_out = out_.AsRegister<Register>(); |
| 676 | DCHECK(locations->CanCall()); |
| 677 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 678 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 679 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 680 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 681 | |
| 682 | __ Bind(GetEntryLabel()); |
| 683 | SaveLiveRegisters(codegen, locations); |
| 684 | |
| 685 | InvokeRuntimeCallingConvention calling_convention; |
| 686 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 687 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 688 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 689 | instruction_, |
| 690 | instruction_->GetDexPc(), |
| 691 | this); |
| 692 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 693 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 694 | |
| 695 | RestoreLiveRegisters(codegen, locations); |
| 696 | __ jmp(GetExitLabel()); |
| 697 | } |
| 698 | |
| 699 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 700 | |
| 701 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 702 | const Location out_; |
| 703 | const Location root_; |
| 704 | |
| 705 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 706 | }; |
| 707 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 708 | #undef __ |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 709 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 710 | #define __ down_cast<X86Assembler*>(GetAssembler())-> /* NOLINT */ |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 711 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 712 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 713 | switch (cond) { |
| 714 | case kCondEQ: return kEqual; |
| 715 | case kCondNE: return kNotEqual; |
| 716 | case kCondLT: return kLess; |
| 717 | case kCondLE: return kLessEqual; |
| 718 | case kCondGT: return kGreater; |
| 719 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 720 | case kCondB: return kBelow; |
| 721 | case kCondBE: return kBelowEqual; |
| 722 | case kCondA: return kAbove; |
| 723 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 724 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 725 | LOG(FATAL) << "Unreachable"; |
| 726 | UNREACHABLE(); |
| 727 | } |
| 728 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 729 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 730 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 731 | switch (cond) { |
| 732 | case kCondEQ: return kEqual; |
| 733 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 734 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 735 | case kCondLT: return kBelow; |
| 736 | case kCondLE: return kBelowEqual; |
| 737 | case kCondGT: return kAbove; |
| 738 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 739 | // Unsigned remain unchanged. |
| 740 | case kCondB: return kBelow; |
| 741 | case kCondBE: return kBelowEqual; |
| 742 | case kCondA: return kAbove; |
| 743 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 744 | } |
| 745 | LOG(FATAL) << "Unreachable"; |
| 746 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 749 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 750 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 754 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 755 | } |
| 756 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 757 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 758 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 759 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 762 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 763 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 764 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 765 | } |
| 766 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 767 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 768 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 769 | return GetFloatingPointSpillSlotSize(); |
| 770 | } |
| 771 | |
| 772 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 773 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 774 | return GetFloatingPointSpillSlotSize(); |
| 775 | } |
| 776 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 777 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 778 | HInstruction* instruction, |
| 779 | uint32_t dex_pc, |
| 780 | SlowPathCode* slow_path) { |
| 781 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 782 | instruction, |
| 783 | dex_pc, |
| 784 | slow_path); |
| 785 | } |
| 786 | |
| 787 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 788 | HInstruction* instruction, |
| 789 | uint32_t dex_pc, |
| 790 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 791 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 792 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 793 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 794 | } |
| 795 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 796 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 797 | const X86InstructionSetFeatures& isa_features, |
| 798 | const CompilerOptions& compiler_options, |
| 799 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 800 | : CodeGenerator(graph, |
| 801 | kNumberOfCpuRegisters, |
| 802 | kNumberOfXmmRegisters, |
| 803 | kNumberOfRegisterPairs, |
| 804 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 805 | arraysize(kCoreCalleeSaves)) |
| 806 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 807 | 0, |
| 808 | compiler_options, |
| 809 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 810 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 811 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 812 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 813 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 814 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 815 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 816 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 817 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 818 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 819 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 820 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 821 | type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 822 | constant_area_start_(-1), |
| 823 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 824 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 825 | // Use a fake return address register to mimic Quick. |
| 826 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 827 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 828 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 829 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 830 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 831 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 832 | |
| 833 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 834 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 835 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 836 | UpdateBlockedPairRegisters(); |
| 837 | } |
| 838 | |
| 839 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 840 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 841 | X86ManagedRegister current = |
| 842 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 843 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 844 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 845 | blocked_register_pairs_[i] = true; |
| 846 | } |
| 847 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 848 | } |
| 849 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 850 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 851 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 852 | assembler_(codegen->GetAssembler()), |
| 853 | codegen_(codegen) {} |
| 854 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 855 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 856 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 859 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 860 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 861 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 862 | bool skip_overflow_check = |
| 863 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 864 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 865 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 866 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 867 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 868 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 871 | if (HasEmptyFrame()) { |
| 872 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 873 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 874 | |
| 875 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 876 | Register reg = kCoreCalleeSaves[i]; |
| 877 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 878 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 879 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 880 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 884 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 885 | __ subl(ESP, Immediate(adjust)); |
| 886 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 887 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 891 | __ cfi().RememberState(); |
| 892 | if (!HasEmptyFrame()) { |
| 893 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 894 | __ addl(ESP, Immediate(adjust)); |
| 895 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 896 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 897 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 898 | Register reg = kCoreCalleeSaves[i]; |
| 899 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 900 | __ popl(reg); |
| 901 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 902 | __ cfi().Restore(DWARFReg(reg)); |
| 903 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 904 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 905 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 906 | __ ret(); |
| 907 | __ cfi().RestoreState(); |
| 908 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 911 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 912 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 915 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 916 | switch (type) { |
| 917 | case Primitive::kPrimBoolean: |
| 918 | case Primitive::kPrimByte: |
| 919 | case Primitive::kPrimChar: |
| 920 | case Primitive::kPrimShort: |
| 921 | case Primitive::kPrimInt: |
| 922 | case Primitive::kPrimNot: |
| 923 | return Location::RegisterLocation(EAX); |
| 924 | |
| 925 | case Primitive::kPrimLong: |
| 926 | return Location::RegisterPairLocation(EAX, EDX); |
| 927 | |
| 928 | case Primitive::kPrimVoid: |
| 929 | return Location::NoLocation(); |
| 930 | |
| 931 | case Primitive::kPrimDouble: |
| 932 | case Primitive::kPrimFloat: |
| 933 | return Location::FpuRegisterLocation(XMM0); |
| 934 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 935 | |
| 936 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 940 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 941 | } |
| 942 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 943 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 944 | switch (type) { |
| 945 | case Primitive::kPrimBoolean: |
| 946 | case Primitive::kPrimByte: |
| 947 | case Primitive::kPrimChar: |
| 948 | case Primitive::kPrimShort: |
| 949 | case Primitive::kPrimInt: |
| 950 | case Primitive::kPrimNot: { |
| 951 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 952 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 953 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 954 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 955 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 956 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 957 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 958 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 959 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 960 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 961 | uint32_t index = gp_index_; |
| 962 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 963 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 964 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 965 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 966 | calling_convention.GetRegisterPairAt(index)); |
| 967 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 968 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 969 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 974 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 975 | stack_index_++; |
| 976 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 977 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 978 | } else { |
| 979 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 984 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 985 | stack_index_ += 2; |
| 986 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 987 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 988 | } else { |
| 989 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 993 | case Primitive::kPrimVoid: |
| 994 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 995 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 996 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 997 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 998 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 999 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1000 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1001 | if (source.Equals(destination)) { |
| 1002 | return; |
| 1003 | } |
| 1004 | if (destination.IsRegister()) { |
| 1005 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1006 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1007 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1008 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1009 | } else { |
| 1010 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1011 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1012 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1013 | } else if (destination.IsFpuRegister()) { |
| 1014 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1015 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1016 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1017 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1018 | } else { |
| 1019 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1020 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1021 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1023 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1024 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1025 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1026 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1027 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1028 | } else if (source.IsConstant()) { |
| 1029 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1030 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1031 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1032 | } else { |
| 1033 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1034 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1035 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1041 | if (source.Equals(destination)) { |
| 1042 | return; |
| 1043 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1044 | if (destination.IsRegisterPair()) { |
| 1045 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1046 | EmitParallelMoves( |
| 1047 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1048 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1049 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1050 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1051 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1052 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1053 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1054 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1055 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1056 | __ psrlq(src_reg, Immediate(32)); |
| 1057 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1058 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1059 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1060 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1061 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1062 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1063 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1064 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1065 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1066 | if (source.IsFpuRegister()) { |
| 1067 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1068 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1069 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1070 | } else if (source.IsRegisterPair()) { |
| 1071 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1072 | // Create stack space for 2 elements. |
| 1073 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1074 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1075 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1076 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1077 | // And remove the temporary stack space we allocated. |
| 1078 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1079 | } else { |
| 1080 | LOG(FATAL) << "Unimplemented"; |
| 1081 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1082 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1083 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1084 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1085 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1086 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1087 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1088 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1089 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1090 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1091 | } else if (source.IsConstant()) { |
| 1092 | HConstant* constant = source.GetConstant(); |
| 1093 | int64_t value; |
| 1094 | if (constant->IsLongConstant()) { |
| 1095 | value = constant->AsLongConstant()->GetValue(); |
| 1096 | } else { |
| 1097 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1098 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1099 | } |
| 1100 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1101 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1102 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1103 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1104 | EmitParallelMoves( |
| 1105 | Location::StackSlot(source.GetStackIndex()), |
| 1106 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1107 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1108 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1109 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1110 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1115 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1116 | DCHECK(location.IsRegister()); |
| 1117 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1118 | } |
| 1119 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1120 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1121 | HParallelMove move(GetGraph()->GetArena()); |
| 1122 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1123 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1124 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1125 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1126 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1127 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1128 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1132 | if (location.IsRegister()) { |
| 1133 | locations->AddTemp(location); |
| 1134 | } else if (location.IsRegisterPair()) { |
| 1135 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1136 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1137 | } else { |
| 1138 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1139 | } |
| 1140 | } |
| 1141 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1142 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1143 | DCHECK(!successor->IsExitBlock()); |
| 1144 | |
| 1145 | HBasicBlock* block = got->GetBlock(); |
| 1146 | HInstruction* previous = got->GetPrevious(); |
| 1147 | |
| 1148 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1149 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1150 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1151 | return; |
| 1152 | } |
| 1153 | |
| 1154 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1155 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1156 | } |
| 1157 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1158 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1162 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1163 | got->SetLocations(nullptr); |
| 1164 | } |
| 1165 | |
| 1166 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1167 | HandleGoto(got, got->GetSuccessor()); |
| 1168 | } |
| 1169 | |
| 1170 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1171 | try_boundary->SetLocations(nullptr); |
| 1172 | } |
| 1173 | |
| 1174 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1175 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1176 | if (!successor->IsExitBlock()) { |
| 1177 | HandleGoto(try_boundary, successor); |
| 1178 | } |
| 1179 | } |
| 1180 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1181 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1182 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1185 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1188 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1189 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1190 | LabelType* true_label, |
| 1191 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1192 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1193 | __ j(kUnordered, true_label); |
| 1194 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1195 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1196 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1197 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1200 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1201 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1202 | LabelType* true_label, |
| 1203 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | LocationSummary* locations = cond->GetLocations(); |
| 1205 | Location left = locations->InAt(0); |
| 1206 | Location right = locations->InAt(1); |
| 1207 | IfCondition if_cond = cond->GetCondition(); |
| 1208 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1209 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1210 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1211 | IfCondition true_high_cond = if_cond; |
| 1212 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1213 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1214 | |
| 1215 | // Set the conditions for the test, remembering that == needs to be |
| 1216 | // decided using the low words. |
| 1217 | switch (if_cond) { |
| 1218 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1219 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1220 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1221 | break; |
| 1222 | case kCondLT: |
| 1223 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1224 | break; |
| 1225 | case kCondLE: |
| 1226 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1227 | break; |
| 1228 | case kCondGT: |
| 1229 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1230 | break; |
| 1231 | case kCondGE: |
| 1232 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1233 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1234 | case kCondB: |
| 1235 | false_high_cond = kCondA; |
| 1236 | break; |
| 1237 | case kCondBE: |
| 1238 | true_high_cond = kCondB; |
| 1239 | break; |
| 1240 | case kCondA: |
| 1241 | false_high_cond = kCondB; |
| 1242 | break; |
| 1243 | case kCondAE: |
| 1244 | true_high_cond = kCondA; |
| 1245 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | if (right.IsConstant()) { |
| 1249 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1250 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1251 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1252 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1253 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1254 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1255 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1256 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1257 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1258 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1259 | __ j(X86Condition(true_high_cond), true_label); |
| 1260 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1261 | } |
| 1262 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1263 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1264 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1265 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1266 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1267 | |
| 1268 | __ cmpl(left_high, right_high); |
| 1269 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1270 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1271 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1272 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1273 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1274 | __ j(X86Condition(true_high_cond), true_label); |
| 1275 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1276 | } |
| 1277 | // Must be equal high, so compare the lows. |
| 1278 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1279 | } else { |
| 1280 | DCHECK(right.IsDoubleStackSlot()); |
| 1281 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1282 | if (if_cond == kCondNE) { |
| 1283 | __ j(X86Condition(true_high_cond), true_label); |
| 1284 | } else if (if_cond == kCondEQ) { |
| 1285 | __ j(X86Condition(false_high_cond), false_label); |
| 1286 | } else { |
| 1287 | __ j(X86Condition(true_high_cond), true_label); |
| 1288 | __ j(X86Condition(false_high_cond), false_label); |
| 1289 | } |
| 1290 | // Must be equal high, so compare the lows. |
| 1291 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1292 | } |
| 1293 | // The last comparison might be unsigned. |
| 1294 | __ j(final_condition, true_label); |
| 1295 | } |
| 1296 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1297 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1298 | Location rhs, |
| 1299 | HInstruction* insn, |
| 1300 | bool is_double) { |
| 1301 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1302 | if (is_double) { |
| 1303 | if (rhs.IsFpuRegister()) { |
| 1304 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1305 | } else if (const_area != nullptr) { |
| 1306 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1307 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1308 | codegen_->LiteralDoubleAddress( |
| 1309 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1310 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1311 | } else { |
| 1312 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1313 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1314 | } |
| 1315 | } else { |
| 1316 | if (rhs.IsFpuRegister()) { |
| 1317 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1318 | } else if (const_area != nullptr) { |
| 1319 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1320 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1321 | codegen_->LiteralFloatAddress( |
| 1322 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1323 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1324 | } else { |
| 1325 | DCHECK(rhs.IsStackSlot()); |
| 1326 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1331 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1332 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1333 | LabelType* true_target_in, |
| 1334 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1335 | // Generated branching requires both targets to be explicit. If either of the |
| 1336 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1337 | LabelType fallthrough_target; |
| 1338 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1339 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1340 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1341 | LocationSummary* locations = condition->GetLocations(); |
| 1342 | Location left = locations->InAt(0); |
| 1343 | Location right = locations->InAt(1); |
| 1344 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1346 | switch (type) { |
| 1347 | case Primitive::kPrimLong: |
| 1348 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1349 | break; |
| 1350 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1351 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1352 | GenerateFPJumps(condition, true_target, false_target); |
| 1353 | break; |
| 1354 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1355 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1356 | GenerateFPJumps(condition, true_target, false_target); |
| 1357 | break; |
| 1358 | default: |
| 1359 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1360 | } |
| 1361 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1362 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1363 | __ jmp(false_target); |
| 1364 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1365 | |
| 1366 | if (fallthrough_target.IsLinked()) { |
| 1367 | __ Bind(&fallthrough_target); |
| 1368 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1371 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1372 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1373 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1374 | // conditions if they are materialized due to the complex branching. |
| 1375 | return cond->IsCondition() && |
| 1376 | cond->GetNext() == branch && |
| 1377 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1378 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1379 | } |
| 1380 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1381 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1382 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1383 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1384 | LabelType* true_target, |
| 1385 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1386 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1387 | |
| 1388 | if (true_target == nullptr && false_target == nullptr) { |
| 1389 | // Nothing to do. The code always falls through. |
| 1390 | return; |
| 1391 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1392 | // Constant condition, statically compared against "true" (integer value 1). |
| 1393 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1394 | if (true_target != nullptr) { |
| 1395 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1396 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1397 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1398 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1399 | if (false_target != nullptr) { |
| 1400 | __ jmp(false_target); |
| 1401 | } |
| 1402 | } |
| 1403 | return; |
| 1404 | } |
| 1405 | |
| 1406 | // The following code generates these patterns: |
| 1407 | // (1) true_target == nullptr && false_target != nullptr |
| 1408 | // - opposite condition true => branch to false_target |
| 1409 | // (2) true_target != nullptr && false_target == nullptr |
| 1410 | // - condition true => branch to true_target |
| 1411 | // (3) true_target != nullptr && false_target != nullptr |
| 1412 | // - condition true => branch to true_target |
| 1413 | // - branch to false_target |
| 1414 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1415 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1416 | if (true_target == nullptr) { |
| 1417 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1418 | } else { |
| 1419 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1420 | } |
| 1421 | } else { |
| 1422 | // Materialized condition, compare against 0. |
| 1423 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1424 | if (lhs.IsRegister()) { |
| 1425 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1426 | } else { |
| 1427 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1428 | } |
| 1429 | if (true_target == nullptr) { |
| 1430 | __ j(kEqual, false_target); |
| 1431 | } else { |
| 1432 | __ j(kNotEqual, true_target); |
| 1433 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1434 | } |
| 1435 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1436 | // Condition has not been materialized, use its inputs as the comparison and |
| 1437 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1438 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1439 | |
| 1440 | // If this is a long or FP comparison that has been folded into |
| 1441 | // the HCondition, generate the comparison directly. |
| 1442 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1443 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1444 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1445 | return; |
| 1446 | } |
| 1447 | |
| 1448 | Location lhs = condition->GetLocations()->InAt(0); |
| 1449 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1450 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1451 | if (rhs.IsRegister()) { |
| 1452 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1453 | } else if (rhs.IsConstant()) { |
| 1454 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1455 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1456 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1457 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1458 | } |
| 1459 | if (true_target == nullptr) { |
| 1460 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1461 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1462 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1463 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1464 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1465 | |
| 1466 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1467 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1468 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1469 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1473 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1474 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1475 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1476 | locations->SetInAt(0, Location::Any()); |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1481 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1482 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1483 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1484 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1485 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1486 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1487 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1491 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1492 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1493 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1494 | locations->SetInAt(0, Location::Any()); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1499 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1500 | GenerateTestAndBranch<Label>(deoptimize, |
| 1501 | /* condition_input_index */ 0, |
| 1502 | slow_path->GetEntryLabel(), |
| 1503 | /* false_target */ nullptr); |
| 1504 | } |
| 1505 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1506 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1507 | // There are no conditional move instructions for XMMs. |
| 1508 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1509 | return false; |
| 1510 | } |
| 1511 | |
| 1512 | // A FP condition doesn't generate the single CC that we need. |
| 1513 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1514 | HInstruction* condition = select->GetCondition(); |
| 1515 | if (condition->IsCondition()) { |
| 1516 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1517 | if (compare_type == Primitive::kPrimLong || |
| 1518 | Primitive::IsFloatingPointType(compare_type)) { |
| 1519 | return false; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | // We can generate a CMOV for this Select. |
| 1524 | return true; |
| 1525 | } |
| 1526 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1527 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1528 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1529 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1530 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1531 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1532 | } else { |
| 1533 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1534 | if (SelectCanUseCMOV(select)) { |
| 1535 | if (select->InputAt(1)->IsConstant()) { |
| 1536 | // Cmov can't handle a constant value. |
| 1537 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1538 | } else { |
| 1539 | locations->SetInAt(1, Location::Any()); |
| 1540 | } |
| 1541 | } else { |
| 1542 | locations->SetInAt(1, Location::Any()); |
| 1543 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1544 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1545 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1546 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1547 | } |
| 1548 | locations->SetOut(Location::SameAsFirstInput()); |
| 1549 | } |
| 1550 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1551 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1552 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1553 | if (rhs.IsConstant()) { |
| 1554 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1555 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1556 | } else if (rhs.IsStackSlot()) { |
| 1557 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1558 | } else { |
| 1559 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1560 | } |
| 1561 | } |
| 1562 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1563 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1564 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1565 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1566 | if (SelectCanUseCMOV(select)) { |
| 1567 | // If both the condition and the source types are integer, we can generate |
| 1568 | // a CMOV to implement Select. |
| 1569 | |
| 1570 | HInstruction* select_condition = select->GetCondition(); |
| 1571 | Condition cond = kNotEqual; |
| 1572 | |
| 1573 | // Figure out how to test the 'condition'. |
| 1574 | if (select_condition->IsCondition()) { |
| 1575 | HCondition* condition = select_condition->AsCondition(); |
| 1576 | if (!condition->IsEmittedAtUseSite()) { |
| 1577 | // This was a previously materialized condition. |
| 1578 | // Can we use the existing condition code? |
| 1579 | if (AreEflagsSetFrom(condition, select)) { |
| 1580 | // Materialization was the previous instruction. Condition codes are right. |
| 1581 | cond = X86Condition(condition->GetCondition()); |
| 1582 | } else { |
| 1583 | // No, we have to recreate the condition code. |
| 1584 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1585 | __ testl(cond_reg, cond_reg); |
| 1586 | } |
| 1587 | } else { |
| 1588 | // We can't handle FP or long here. |
| 1589 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1590 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1591 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1592 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1593 | cond = X86Condition(condition->GetCondition()); |
| 1594 | } |
| 1595 | } else { |
| 1596 | // Must be a boolean condition, which needs to be compared to 0. |
| 1597 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1598 | __ testl(cond_reg, cond_reg); |
| 1599 | } |
| 1600 | |
| 1601 | // If the condition is true, overwrite the output, which already contains false. |
| 1602 | Location false_loc = locations->InAt(0); |
| 1603 | Location true_loc = locations->InAt(1); |
| 1604 | if (select->GetType() == Primitive::kPrimLong) { |
| 1605 | // 64 bit conditional move. |
| 1606 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1607 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1608 | if (true_loc.IsRegisterPair()) { |
| 1609 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1610 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1611 | } else { |
| 1612 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1613 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1614 | } |
| 1615 | } else { |
| 1616 | // 32 bit conditional move. |
| 1617 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1618 | if (true_loc.IsRegister()) { |
| 1619 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1620 | } else { |
| 1621 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1622 | } |
| 1623 | } |
| 1624 | } else { |
| 1625 | NearLabel false_target; |
| 1626 | GenerateTestAndBranch<NearLabel>( |
| 1627 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1628 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1629 | __ Bind(&false_target); |
| 1630 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1633 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1634 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1635 | } |
| 1636 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1637 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1638 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | void CodeGeneratorX86::GenerateNop() { |
| 1642 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1645 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1646 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1647 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1648 | // Handle the long/FP comparisons made in instruction simplification. |
| 1649 | switch (cond->InputAt(0)->GetType()) { |
| 1650 | case Primitive::kPrimLong: { |
| 1651 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1652 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1653 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1654 | locations->SetOut(Location::RequiresRegister()); |
| 1655 | } |
| 1656 | break; |
| 1657 | } |
| 1658 | case Primitive::kPrimFloat: |
| 1659 | case Primitive::kPrimDouble: { |
| 1660 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1661 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1662 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1663 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1664 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1665 | } else { |
| 1666 | locations->SetInAt(1, Location::Any()); |
| 1667 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1668 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1669 | locations->SetOut(Location::RequiresRegister()); |
| 1670 | } |
| 1671 | break; |
| 1672 | } |
| 1673 | default: |
| 1674 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1675 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1676 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1677 | // We need a byte register. |
| 1678 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1679 | } |
| 1680 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1681 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1684 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
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 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1687 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1688 | |
| 1689 | LocationSummary* locations = cond->GetLocations(); |
| 1690 | Location lhs = locations->InAt(0); |
| 1691 | Location rhs = locations->InAt(1); |
| 1692 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1693 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1694 | |
| 1695 | switch (cond->InputAt(0)->GetType()) { |
| 1696 | default: { |
| 1697 | // Integer case. |
| 1698 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1699 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1700 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1701 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1702 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1703 | return; |
| 1704 | } |
| 1705 | case Primitive::kPrimLong: |
| 1706 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1707 | break; |
| 1708 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1709 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1710 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1711 | break; |
| 1712 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1713 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1714 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1715 | break; |
| 1716 | } |
| 1717 | |
| 1718 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1719 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1720 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1721 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1722 | __ Bind(&false_label); |
| 1723 | __ xorl(reg, reg); |
| 1724 | __ jmp(&done_label); |
| 1725 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1726 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1727 | __ Bind(&true_label); |
| 1728 | __ movl(reg, Immediate(1)); |
| 1729 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1733 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1737 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1741 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1745 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1749 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1753 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1757 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1761 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1765 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1769 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1773 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1777 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1780 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1781 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1797 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1801 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1805 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1809 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1812 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1813 | LocationSummary* locations = |
| 1814 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1815 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1818 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1819 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1822 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1823 | LocationSummary* locations = |
| 1824 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1825 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1826 | } |
| 1827 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1828 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1829 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1832 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1833 | LocationSummary* locations = |
| 1834 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1835 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1836 | } |
| 1837 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1838 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1839 | // Will be generated at use site. |
| 1840 | } |
| 1841 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1842 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1843 | LocationSummary* locations = |
| 1844 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1845 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1846 | } |
| 1847 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1848 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1849 | // Will be generated at use site. |
| 1850 | } |
| 1851 | |
| 1852 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1853 | LocationSummary* locations = |
| 1854 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1855 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1856 | } |
| 1857 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1858 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1859 | // Will be generated at use site. |
| 1860 | } |
| 1861 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1862 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1863 | memory_barrier->SetLocations(nullptr); |
| 1864 | } |
| 1865 | |
| 1866 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1867 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1868 | } |
| 1869 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1870 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1871 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1874 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1875 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1878 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1879 | LocationSummary* locations = |
| 1880 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1881 | switch (ret->InputAt(0)->GetType()) { |
| 1882 | case Primitive::kPrimBoolean: |
| 1883 | case Primitive::kPrimByte: |
| 1884 | case Primitive::kPrimChar: |
| 1885 | case Primitive::kPrimShort: |
| 1886 | case Primitive::kPrimInt: |
| 1887 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1888 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1889 | break; |
| 1890 | |
| 1891 | case Primitive::kPrimLong: |
| 1892 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1893 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1894 | break; |
| 1895 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1896 | case Primitive::kPrimFloat: |
| 1897 | case Primitive::kPrimDouble: |
| 1898 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1899 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1900 | break; |
| 1901 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1902 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1903 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1904 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1907 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1908 | if (kIsDebugBuild) { |
| 1909 | switch (ret->InputAt(0)->GetType()) { |
| 1910 | case Primitive::kPrimBoolean: |
| 1911 | case Primitive::kPrimByte: |
| 1912 | case Primitive::kPrimChar: |
| 1913 | case Primitive::kPrimShort: |
| 1914 | case Primitive::kPrimInt: |
| 1915 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1916 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1917 | break; |
| 1918 | |
| 1919 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1920 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1921 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1922 | break; |
| 1923 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1924 | case Primitive::kPrimFloat: |
| 1925 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1926 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1927 | break; |
| 1928 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1929 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1930 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1931 | } |
| 1932 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1933 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1936 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1937 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1938 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1939 | // the method_idx. |
| 1940 | HandleInvoke(invoke); |
| 1941 | } |
| 1942 | |
| 1943 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1944 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1945 | } |
| 1946 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1947 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1948 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1949 | // art::PrepareForRegisterAllocation. |
| 1950 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1951 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1952 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1953 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1954 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1955 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1956 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1957 | return; |
| 1958 | } |
| 1959 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1960 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1961 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1962 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1963 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1964 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1965 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1966 | } |
| 1967 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1968 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1969 | if (invoke->GetLocations()->Intrinsified()) { |
| 1970 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1971 | intrinsic.Dispatch(invoke); |
| 1972 | return true; |
| 1973 | } |
| 1974 | return false; |
| 1975 | } |
| 1976 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1977 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1978 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1979 | // art::PrepareForRegisterAllocation. |
| 1980 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1981 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1982 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1983 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1984 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1985 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1986 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1987 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1988 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1989 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1993 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1994 | if (intrinsic.TryDispatch(invoke)) { |
| 1995 | return; |
| 1996 | } |
| 1997 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1998 | HandleInvoke(invoke); |
| 1999 | } |
| 2000 | |
| 2001 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2002 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2003 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2006 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2007 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2008 | return; |
| 2009 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2010 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2011 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2012 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2013 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2016 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2017 | // This call to HandleInvoke allocates a temporary (core) register |
| 2018 | // which is also used to transfer the hidden argument from FP to |
| 2019 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2020 | HandleInvoke(invoke); |
| 2021 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2022 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2026 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2027 | LocationSummary* locations = invoke->GetLocations(); |
| 2028 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2029 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2030 | Location receiver = locations->InAt(0); |
| 2031 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2032 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2033 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2034 | // won't be modified thereafter, before the `call` instruction. |
| 2035 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2036 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2037 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2038 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2039 | if (receiver.IsStackSlot()) { |
| 2040 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2041 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2042 | __ movl(temp, Address(temp, class_offset)); |
| 2043 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2044 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2045 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2046 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2047 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2048 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2049 | // emit a read barrier for the previous class reference load. |
| 2050 | // However this is not required in practice, as this is an |
| 2051 | // intermediate/temporary reference and because the current |
| 2052 | // concurrent copying collector keeps the from-space memory |
| 2053 | // intact/accessible until the end of the marking phase (the |
| 2054 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2055 | __ MaybeUnpoisonHeapReference(temp); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2056 | // temp = temp->GetAddressOfIMT() |
| 2057 | __ movl(temp, |
| 2058 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2059 | // temp = temp->GetImtEntryAt(method_offset); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2060 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 2061 | invoke->GetImtIndex() % ImTable::kSize, kX86PointerSize)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2062 | __ movl(temp, Address(temp, method_offset)); |
| 2063 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2064 | __ call(Address(temp, |
| 2065 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2066 | |
| 2067 | DCHECK(!codegen_->IsLeafMethod()); |
| 2068 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2069 | } |
| 2070 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2071 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2072 | LocationSummary* locations = |
| 2073 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2074 | switch (neg->GetResultType()) { |
| 2075 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2076 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2077 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2078 | locations->SetOut(Location::SameAsFirstInput()); |
| 2079 | break; |
| 2080 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2081 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2082 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2083 | locations->SetOut(Location::SameAsFirstInput()); |
| 2084 | locations->AddTemp(Location::RequiresRegister()); |
| 2085 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2086 | break; |
| 2087 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2088 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2089 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2090 | locations->SetOut(Location::SameAsFirstInput()); |
| 2091 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2092 | break; |
| 2093 | |
| 2094 | default: |
| 2095 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2100 | LocationSummary* locations = neg->GetLocations(); |
| 2101 | Location out = locations->Out(); |
| 2102 | Location in = locations->InAt(0); |
| 2103 | switch (neg->GetResultType()) { |
| 2104 | case Primitive::kPrimInt: |
| 2105 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2106 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2107 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2108 | break; |
| 2109 | |
| 2110 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2111 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2112 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2113 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2114 | // Negation is similar to subtraction from zero. The least |
| 2115 | // significant byte triggers a borrow when it is different from |
| 2116 | // zero; to take it into account, add 1 to the most significant |
| 2117 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2118 | // operation. |
| 2119 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2120 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2121 | break; |
| 2122 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2123 | case Primitive::kPrimFloat: { |
| 2124 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2125 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2126 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2127 | // Implement float negation with an exclusive or with value |
| 2128 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2129 | // single-precision floating-point number). |
| 2130 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2131 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2132 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2133 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2134 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2135 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2136 | case Primitive::kPrimDouble: { |
| 2137 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2138 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2139 | // Implement double negation with an exclusive or with value |
| 2140 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2141 | // a double-precision floating-point number). |
| 2142 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2143 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2144 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2145 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2146 | |
| 2147 | default: |
| 2148 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2149 | } |
| 2150 | } |
| 2151 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2152 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2153 | LocationSummary* locations = |
| 2154 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2155 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2156 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2157 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2158 | locations->SetOut(Location::SameAsFirstInput()); |
| 2159 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2160 | } |
| 2161 | |
| 2162 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2163 | LocationSummary* locations = neg->GetLocations(); |
| 2164 | Location out = locations->Out(); |
| 2165 | DCHECK(locations->InAt(0).Equals(out)); |
| 2166 | |
| 2167 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2168 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2169 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2170 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2171 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2172 | } else { |
| 2173 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2174 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2175 | } |
| 2176 | } |
| 2177 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2178 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2179 | Primitive::Type result_type = conversion->GetResultType(); |
| 2180 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2181 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2182 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2183 | // The float-to-long and double-to-long type conversions rely on a |
| 2184 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2185 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2186 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2187 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2188 | ? LocationSummary::kCall |
| 2189 | : LocationSummary::kNoCall; |
| 2190 | LocationSummary* locations = |
| 2191 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2192 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2193 | // The Java language does not allow treating boolean as an integral type but |
| 2194 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2195 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2196 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2197 | case Primitive::kPrimByte: |
| 2198 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2199 | case Primitive::kPrimLong: { |
| 2200 | // Type conversion from long to byte is a result of code transformations. |
| 2201 | HInstruction* input = conversion->InputAt(0); |
| 2202 | Location input_location = input->IsConstant() |
| 2203 | ? Location::ConstantLocation(input->AsConstant()) |
| 2204 | : Location::RegisterPairLocation(EAX, EDX); |
| 2205 | locations->SetInAt(0, input_location); |
| 2206 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2207 | // the validation of the linear scan implementation |
| 2208 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2209 | break; |
| 2210 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2211 | case Primitive::kPrimBoolean: |
| 2212 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimShort: |
| 2214 | case Primitive::kPrimInt: |
| 2215 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2216 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2217 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2218 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2219 | // the validation of the linear scan implementation |
| 2220 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2221 | break; |
| 2222 | |
| 2223 | default: |
| 2224 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2225 | << " to " << result_type; |
| 2226 | } |
| 2227 | break; |
| 2228 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2229 | case Primitive::kPrimShort: |
| 2230 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2231 | case Primitive::kPrimLong: |
| 2232 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimBoolean: |
| 2234 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2235 | case Primitive::kPrimByte: |
| 2236 | case Primitive::kPrimInt: |
| 2237 | case Primitive::kPrimChar: |
| 2238 | // Processing a Dex `int-to-short' instruction. |
| 2239 | locations->SetInAt(0, Location::Any()); |
| 2240 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2241 | break; |
| 2242 | |
| 2243 | default: |
| 2244 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2245 | << " to " << result_type; |
| 2246 | } |
| 2247 | break; |
| 2248 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2249 | case Primitive::kPrimInt: |
| 2250 | switch (input_type) { |
| 2251 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2252 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2253 | locations->SetInAt(0, Location::Any()); |
| 2254 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2255 | break; |
| 2256 | |
| 2257 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2258 | // Processing a Dex `float-to-int' instruction. |
| 2259 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2260 | locations->SetOut(Location::RequiresRegister()); |
| 2261 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2262 | break; |
| 2263 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2264 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2265 | // Processing a Dex `double-to-int' instruction. |
| 2266 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2267 | locations->SetOut(Location::RequiresRegister()); |
| 2268 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2269 | break; |
| 2270 | |
| 2271 | default: |
| 2272 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2273 | << " to " << result_type; |
| 2274 | } |
| 2275 | break; |
| 2276 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2277 | case Primitive::kPrimLong: |
| 2278 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2279 | case Primitive::kPrimBoolean: |
| 2280 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimByte: |
| 2282 | case Primitive::kPrimShort: |
| 2283 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2284 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2285 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2286 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2287 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2288 | break; |
| 2289 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2291 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2292 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2293 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2294 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2295 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2296 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2297 | // The runtime helper puts the result in EAX, EDX. |
| 2298 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2299 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2300 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2301 | |
| 2302 | default: |
| 2303 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2304 | << " to " << result_type; |
| 2305 | } |
| 2306 | break; |
| 2307 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2308 | case Primitive::kPrimChar: |
| 2309 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimLong: |
| 2311 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimBoolean: |
| 2313 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimByte: |
| 2315 | case Primitive::kPrimShort: |
| 2316 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2317 | // Processing a Dex `int-to-char' instruction. |
| 2318 | locations->SetInAt(0, Location::Any()); |
| 2319 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2320 | break; |
| 2321 | |
| 2322 | default: |
| 2323 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2324 | << " to " << result_type; |
| 2325 | } |
| 2326 | break; |
| 2327 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2329 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimBoolean: |
| 2331 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimByte: |
| 2333 | case Primitive::kPrimShort: |
| 2334 | case Primitive::kPrimInt: |
| 2335 | case Primitive::kPrimChar: |
| 2336 | // Processing a Dex `int-to-float' instruction. |
| 2337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2338 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2339 | break; |
| 2340 | |
| 2341 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2342 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2343 | locations->SetInAt(0, Location::Any()); |
| 2344 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2348 | // Processing a Dex `double-to-float' instruction. |
| 2349 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2350 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | |
| 2353 | default: |
| 2354 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2355 | << " to " << result_type; |
| 2356 | }; |
| 2357 | break; |
| 2358 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimBoolean: |
| 2362 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimByte: |
| 2364 | case Primitive::kPrimShort: |
| 2365 | case Primitive::kPrimInt: |
| 2366 | case Primitive::kPrimChar: |
| 2367 | // Processing a Dex `int-to-double' instruction. |
| 2368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2369 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2370 | break; |
| 2371 | |
| 2372 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2373 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2374 | locations->SetInAt(0, Location::Any()); |
| 2375 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2376 | break; |
| 2377 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2379 | // Processing a Dex `float-to-double' instruction. |
| 2380 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2381 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2382 | break; |
| 2383 | |
| 2384 | default: |
| 2385 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2386 | << " to " << result_type; |
| 2387 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | |
| 2390 | default: |
| 2391 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2392 | << " to " << result_type; |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2397 | LocationSummary* locations = conversion->GetLocations(); |
| 2398 | Location out = locations->Out(); |
| 2399 | Location in = locations->InAt(0); |
| 2400 | Primitive::Type result_type = conversion->GetResultType(); |
| 2401 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2402 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2403 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimByte: |
| 2405 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimLong: |
| 2407 | // Type conversion from long to byte is a result of code transformations. |
| 2408 | if (in.IsRegisterPair()) { |
| 2409 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2410 | } else { |
| 2411 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2412 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2413 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2414 | } |
| 2415 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2416 | case Primitive::kPrimBoolean: |
| 2417 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2418 | case Primitive::kPrimShort: |
| 2419 | case Primitive::kPrimInt: |
| 2420 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2421 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2422 | if (in.IsRegister()) { |
| 2423 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2424 | } else { |
| 2425 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2426 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2427 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2428 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2429 | break; |
| 2430 | |
| 2431 | default: |
| 2432 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2433 | << " to " << result_type; |
| 2434 | } |
| 2435 | break; |
| 2436 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2437 | case Primitive::kPrimShort: |
| 2438 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2439 | case Primitive::kPrimLong: |
| 2440 | // Type conversion from long to short is a result of code transformations. |
| 2441 | if (in.IsRegisterPair()) { |
| 2442 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2443 | } else if (in.IsDoubleStackSlot()) { |
| 2444 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2445 | } else { |
| 2446 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2447 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2448 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2449 | } |
| 2450 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2451 | case Primitive::kPrimBoolean: |
| 2452 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2453 | case Primitive::kPrimByte: |
| 2454 | case Primitive::kPrimInt: |
| 2455 | case Primitive::kPrimChar: |
| 2456 | // Processing a Dex `int-to-short' instruction. |
| 2457 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2458 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2459 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2460 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2461 | } else { |
| 2462 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2463 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2464 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2465 | } |
| 2466 | break; |
| 2467 | |
| 2468 | default: |
| 2469 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2470 | << " to " << result_type; |
| 2471 | } |
| 2472 | break; |
| 2473 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2474 | case Primitive::kPrimInt: |
| 2475 | switch (input_type) { |
| 2476 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2477 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2478 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2479 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2480 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2481 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2482 | } else { |
| 2483 | DCHECK(in.IsConstant()); |
| 2484 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2485 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2486 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2487 | } |
| 2488 | break; |
| 2489 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimFloat: { |
| 2491 | // Processing a Dex `float-to-int' instruction. |
| 2492 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2493 | Register output = out.AsRegister<Register>(); |
| 2494 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2495 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2496 | |
| 2497 | __ movl(output, Immediate(kPrimIntMax)); |
| 2498 | // temp = int-to-float(output) |
| 2499 | __ cvtsi2ss(temp, output); |
| 2500 | // if input >= temp goto done |
| 2501 | __ comiss(input, temp); |
| 2502 | __ j(kAboveEqual, &done); |
| 2503 | // if input == NaN goto nan |
| 2504 | __ j(kUnordered, &nan); |
| 2505 | // output = float-to-int-truncate(input) |
| 2506 | __ cvttss2si(output, input); |
| 2507 | __ jmp(&done); |
| 2508 | __ Bind(&nan); |
| 2509 | // output = 0 |
| 2510 | __ xorl(output, output); |
| 2511 | __ Bind(&done); |
| 2512 | break; |
| 2513 | } |
| 2514 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2515 | case Primitive::kPrimDouble: { |
| 2516 | // Processing a Dex `double-to-int' instruction. |
| 2517 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2518 | Register output = out.AsRegister<Register>(); |
| 2519 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2520 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2521 | |
| 2522 | __ movl(output, Immediate(kPrimIntMax)); |
| 2523 | // temp = int-to-double(output) |
| 2524 | __ cvtsi2sd(temp, output); |
| 2525 | // if input >= temp goto done |
| 2526 | __ comisd(input, temp); |
| 2527 | __ j(kAboveEqual, &done); |
| 2528 | // if input == NaN goto nan |
| 2529 | __ j(kUnordered, &nan); |
| 2530 | // output = double-to-int-truncate(input) |
| 2531 | __ cvttsd2si(output, input); |
| 2532 | __ jmp(&done); |
| 2533 | __ Bind(&nan); |
| 2534 | // output = 0 |
| 2535 | __ xorl(output, output); |
| 2536 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2537 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2538 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2539 | |
| 2540 | default: |
| 2541 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2542 | << " to " << result_type; |
| 2543 | } |
| 2544 | break; |
| 2545 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2546 | case Primitive::kPrimLong: |
| 2547 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2548 | case Primitive::kPrimBoolean: |
| 2549 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimByte: |
| 2551 | case Primitive::kPrimShort: |
| 2552 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2553 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2554 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2555 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2556 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2557 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2558 | __ cdq(); |
| 2559 | break; |
| 2560 | |
| 2561 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2562 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2563 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2564 | conversion, |
| 2565 | conversion->GetDexPc(), |
| 2566 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2567 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2568 | break; |
| 2569 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2570 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2571 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2572 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2573 | conversion, |
| 2574 | conversion->GetDexPc(), |
| 2575 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2576 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2577 | break; |
| 2578 | |
| 2579 | default: |
| 2580 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2581 | << " to " << result_type; |
| 2582 | } |
| 2583 | break; |
| 2584 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimChar: |
| 2586 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimLong: |
| 2588 | // Type conversion from long to short is a result of code transformations. |
| 2589 | if (in.IsRegisterPair()) { |
| 2590 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2591 | } else if (in.IsDoubleStackSlot()) { |
| 2592 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2593 | } else { |
| 2594 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2595 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2596 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2597 | } |
| 2598 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2599 | case Primitive::kPrimBoolean: |
| 2600 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimByte: |
| 2602 | case Primitive::kPrimShort: |
| 2603 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2604 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2605 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2606 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2607 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2608 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2609 | } else { |
| 2610 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2611 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2612 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2613 | } |
| 2614 | break; |
| 2615 | |
| 2616 | default: |
| 2617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2618 | << " to " << result_type; |
| 2619 | } |
| 2620 | break; |
| 2621 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2623 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimBoolean: |
| 2625 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimByte: |
| 2627 | case Primitive::kPrimShort: |
| 2628 | case Primitive::kPrimInt: |
| 2629 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2630 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2631 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2632 | break; |
| 2633 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2634 | case Primitive::kPrimLong: { |
| 2635 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2636 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2637 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2638 | // Create stack space for the call to |
| 2639 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2640 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2641 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2642 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2643 | __ subl(ESP, Immediate(adjustment)); |
| 2644 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2645 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2646 | // Load the value to the FP stack, using temporaries if needed. |
| 2647 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2648 | |
| 2649 | if (out.IsStackSlot()) { |
| 2650 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2651 | } else { |
| 2652 | __ fstps(Address(ESP, 0)); |
| 2653 | Location stack_temp = Location::StackSlot(0); |
| 2654 | codegen_->Move32(out, stack_temp); |
| 2655 | } |
| 2656 | |
| 2657 | // Remove the temporary stack space we allocated. |
| 2658 | if (adjustment != 0) { |
| 2659 | __ addl(ESP, Immediate(adjustment)); |
| 2660 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2661 | break; |
| 2662 | } |
| 2663 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2665 | // Processing a Dex `double-to-float' instruction. |
| 2666 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
| 2669 | default: |
| 2670 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2671 | << " to " << result_type; |
| 2672 | }; |
| 2673 | break; |
| 2674 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2677 | case Primitive::kPrimBoolean: |
| 2678 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2679 | case Primitive::kPrimByte: |
| 2680 | case Primitive::kPrimShort: |
| 2681 | case Primitive::kPrimInt: |
| 2682 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2683 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2684 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2687 | case Primitive::kPrimLong: { |
| 2688 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2689 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2690 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2691 | // Create stack space for the call to |
| 2692 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2693 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2694 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2695 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2696 | __ subl(ESP, Immediate(adjustment)); |
| 2697 | } |
| 2698 | |
| 2699 | // Load the value to the FP stack, using temporaries if needed. |
| 2700 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2701 | |
| 2702 | if (out.IsDoubleStackSlot()) { |
| 2703 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2704 | } else { |
| 2705 | __ fstpl(Address(ESP, 0)); |
| 2706 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2707 | codegen_->Move64(out, stack_temp); |
| 2708 | } |
| 2709 | |
| 2710 | // Remove the temporary stack space we allocated. |
| 2711 | if (adjustment != 0) { |
| 2712 | __ addl(ESP, Immediate(adjustment)); |
| 2713 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2714 | break; |
| 2715 | } |
| 2716 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2718 | // Processing a Dex `float-to-double' instruction. |
| 2719 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | break; |
| 2721 | |
| 2722 | default: |
| 2723 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2724 | << " to " << result_type; |
| 2725 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | break; |
| 2727 | |
| 2728 | default: |
| 2729 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2730 | << " to " << result_type; |
| 2731 | } |
| 2732 | } |
| 2733 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2734 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2735 | LocationSummary* locations = |
| 2736 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2737 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2738 | case Primitive::kPrimInt: { |
| 2739 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2740 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2741 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2742 | break; |
| 2743 | } |
| 2744 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2745 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2746 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2747 | locations->SetInAt(1, Location::Any()); |
| 2748 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2749 | break; |
| 2750 | } |
| 2751 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2752 | case Primitive::kPrimFloat: |
| 2753 | case Primitive::kPrimDouble: { |
| 2754 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2755 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2756 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2757 | } else if (add->InputAt(1)->IsConstant()) { |
| 2758 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2759 | } else { |
| 2760 | locations->SetInAt(1, Location::Any()); |
| 2761 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2762 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2763 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2764 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2765 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2766 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2767 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2768 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2773 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2774 | Location first = locations->InAt(0); |
| 2775 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2776 | Location out = locations->Out(); |
| 2777 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2778 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2779 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2780 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2781 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2782 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2783 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2784 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2785 | } else { |
| 2786 | __ leal(out.AsRegister<Register>(), Address( |
| 2787 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2788 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2789 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2790 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2791 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2792 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2793 | } else { |
| 2794 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2795 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2796 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2797 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2798 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2799 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2800 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2804 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2805 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2806 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2807 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2808 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2809 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2810 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2811 | } else { |
| 2812 | DCHECK(second.IsConstant()) << second; |
| 2813 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2814 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2815 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2816 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2817 | break; |
| 2818 | } |
| 2819 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2820 | case Primitive::kPrimFloat: { |
| 2821 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2822 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2823 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2824 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2825 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2826 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2827 | codegen_->LiteralFloatAddress( |
| 2828 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2829 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2830 | } else { |
| 2831 | DCHECK(second.IsStackSlot()); |
| 2832 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2833 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2834 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | case Primitive::kPrimDouble: { |
| 2838 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2839 | __ addsd(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 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2844 | codegen_->LiteralDoubleAddress( |
| 2845 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2846 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2847 | } else { |
| 2848 | DCHECK(second.IsDoubleStackSlot()); |
| 2849 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2850 | } |
| 2851 | break; |
| 2852 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2853 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2854 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2855 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2859 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2860 | LocationSummary* locations = |
| 2861 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2862 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2863 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2864 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2865 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2866 | locations->SetInAt(1, Location::Any()); |
| 2867 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2868 | break; |
| 2869 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2870 | case Primitive::kPrimFloat: |
| 2871 | case Primitive::kPrimDouble: { |
| 2872 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2873 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2874 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2875 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2876 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2877 | } else { |
| 2878 | locations->SetInAt(1, Location::Any()); |
| 2879 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2880 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2881 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2882 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2883 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2884 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2885 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2886 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2890 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2891 | Location first = locations->InAt(0); |
| 2892 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2893 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2894 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2895 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2896 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2897 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2898 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2899 | __ subl(first.AsRegister<Register>(), |
| 2900 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2901 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2903 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2904 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2908 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2909 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2910 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2911 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2912 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2913 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2914 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2915 | } else { |
| 2916 | DCHECK(second.IsConstant()) << second; |
| 2917 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2918 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2919 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2920 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2921 | break; |
| 2922 | } |
| 2923 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2924 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2925 | if (second.IsFpuRegister()) { |
| 2926 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2927 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2928 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2929 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2930 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2931 | codegen_->LiteralFloatAddress( |
| 2932 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2933 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2934 | } else { |
| 2935 | DCHECK(second.IsStackSlot()); |
| 2936 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2937 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2938 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2942 | if (second.IsFpuRegister()) { |
| 2943 | __ subsd(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 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2948 | codegen_->LiteralDoubleAddress( |
| 2949 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2950 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2951 | } else { |
| 2952 | DCHECK(second.IsDoubleStackSlot()); |
| 2953 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2954 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2955 | break; |
| 2956 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2957 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2958 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2959 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2963 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2964 | LocationSummary* locations = |
| 2965 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2966 | switch (mul->GetResultType()) { |
| 2967 | case Primitive::kPrimInt: |
| 2968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2969 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2970 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2971 | // Can use 3 operand multiply. |
| 2972 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2973 | } else { |
| 2974 | locations->SetOut(Location::SameAsFirstInput()); |
| 2975 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2976 | break; |
| 2977 | case Primitive::kPrimLong: { |
| 2978 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2979 | locations->SetInAt(1, Location::Any()); |
| 2980 | locations->SetOut(Location::SameAsFirstInput()); |
| 2981 | // Needed for imul on 32bits with 64bits output. |
| 2982 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2983 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2984 | break; |
| 2985 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2986 | case Primitive::kPrimFloat: |
| 2987 | case Primitive::kPrimDouble: { |
| 2988 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2989 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2990 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2991 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2992 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2993 | } else { |
| 2994 | locations->SetInAt(1, Location::Any()); |
| 2995 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2996 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2997 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2998 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2999 | |
| 3000 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3001 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3006 | LocationSummary* locations = mul->GetLocations(); |
| 3007 | Location first = locations->InAt(0); |
| 3008 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3009 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3010 | |
| 3011 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3012 | case Primitive::kPrimInt: |
| 3013 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3014 | // problems where the output may not be the same as the first operand. |
| 3015 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3016 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3017 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3018 | } else if (second.IsRegister()) { |
| 3019 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3020 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3021 | } else { |
| 3022 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3023 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3024 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3025 | } |
| 3026 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3027 | |
| 3028 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3029 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3030 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3031 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3032 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3033 | |
| 3034 | DCHECK_EQ(EAX, eax); |
| 3035 | DCHECK_EQ(EDX, edx); |
| 3036 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3037 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3038 | // output: in1 |
| 3039 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3040 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3041 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3042 | if (second.IsConstant()) { |
| 3043 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3044 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3045 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3046 | int32_t low_value = Low32Bits(value); |
| 3047 | int32_t high_value = High32Bits(value); |
| 3048 | Immediate low(low_value); |
| 3049 | Immediate high(high_value); |
| 3050 | |
| 3051 | __ movl(eax, high); |
| 3052 | // eax <- in1.lo * in2.hi |
| 3053 | __ imull(eax, in1_lo); |
| 3054 | // in1.hi <- in1.hi * in2.lo |
| 3055 | __ imull(in1_hi, low); |
| 3056 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3057 | __ addl(in1_hi, eax); |
| 3058 | // move in2_lo to eax to prepare for double precision |
| 3059 | __ movl(eax, low); |
| 3060 | // edx:eax <- in1.lo * in2.lo |
| 3061 | __ mull(in1_lo); |
| 3062 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3063 | __ addl(in1_hi, edx); |
| 3064 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3065 | __ movl(in1_lo, eax); |
| 3066 | } else if (second.IsRegisterPair()) { |
| 3067 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3068 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3069 | |
| 3070 | __ movl(eax, in2_hi); |
| 3071 | // eax <- in1.lo * in2.hi |
| 3072 | __ imull(eax, in1_lo); |
| 3073 | // in1.hi <- in1.hi * in2.lo |
| 3074 | __ imull(in1_hi, in2_lo); |
| 3075 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3076 | __ addl(in1_hi, eax); |
| 3077 | // move in1_lo to eax to prepare for double precision |
| 3078 | __ movl(eax, in1_lo); |
| 3079 | // edx:eax <- in1.lo * in2.lo |
| 3080 | __ mull(in2_lo); |
| 3081 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3082 | __ addl(in1_hi, edx); |
| 3083 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3084 | __ movl(in1_lo, eax); |
| 3085 | } else { |
| 3086 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3087 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3088 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3089 | |
| 3090 | __ movl(eax, in2_hi); |
| 3091 | // eax <- in1.lo * in2.hi |
| 3092 | __ imull(eax, in1_lo); |
| 3093 | // in1.hi <- in1.hi * in2.lo |
| 3094 | __ imull(in1_hi, in2_lo); |
| 3095 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3096 | __ addl(in1_hi, eax); |
| 3097 | // move in1_lo to eax to prepare for double precision |
| 3098 | __ movl(eax, in1_lo); |
| 3099 | // edx:eax <- in1.lo * in2.lo |
| 3100 | __ mull(in2_lo); |
| 3101 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3102 | __ addl(in1_hi, edx); |
| 3103 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3104 | __ movl(in1_lo, eax); |
| 3105 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3106 | |
| 3107 | break; |
| 3108 | } |
| 3109 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3111 | DCHECK(first.Equals(locations->Out())); |
| 3112 | if (second.IsFpuRegister()) { |
| 3113 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3114 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3115 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3116 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3117 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3118 | codegen_->LiteralFloatAddress( |
| 3119 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3120 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3121 | } else { |
| 3122 | DCHECK(second.IsStackSlot()); |
| 3123 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3124 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3129 | DCHECK(first.Equals(locations->Out())); |
| 3130 | if (second.IsFpuRegister()) { |
| 3131 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3132 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3133 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3134 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3135 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3136 | codegen_->LiteralDoubleAddress( |
| 3137 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3138 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3139 | } else { |
| 3140 | DCHECK(second.IsDoubleStackSlot()); |
| 3141 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3142 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3143 | break; |
| 3144 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3145 | |
| 3146 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3147 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3151 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3152 | uint32_t temp_offset, |
| 3153 | uint32_t stack_adjustment, |
| 3154 | bool is_fp, |
| 3155 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3156 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3157 | DCHECK(!is_wide); |
| 3158 | if (is_fp) { |
| 3159 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3160 | } else { |
| 3161 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3162 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3163 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3164 | DCHECK(is_wide); |
| 3165 | if (is_fp) { |
| 3166 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3167 | } else { |
| 3168 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3169 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3170 | } else { |
| 3171 | // 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] | 3172 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3173 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3174 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3175 | if (is_fp) { |
| 3176 | __ flds(Address(ESP, temp_offset)); |
| 3177 | } else { |
| 3178 | __ filds(Address(ESP, temp_offset)); |
| 3179 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3180 | } else { |
| 3181 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3182 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3183 | if (is_fp) { |
| 3184 | __ fldl(Address(ESP, temp_offset)); |
| 3185 | } else { |
| 3186 | __ fildl(Address(ESP, temp_offset)); |
| 3187 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3193 | Primitive::Type type = rem->GetResultType(); |
| 3194 | bool is_float = type == Primitive::kPrimFloat; |
| 3195 | size_t elem_size = Primitive::ComponentSize(type); |
| 3196 | LocationSummary* locations = rem->GetLocations(); |
| 3197 | Location first = locations->InAt(0); |
| 3198 | Location second = locations->InAt(1); |
| 3199 | Location out = locations->Out(); |
| 3200 | |
| 3201 | // Create stack space for 2 elements. |
| 3202 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3203 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3204 | |
| 3205 | // 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] | 3206 | const bool is_wide = !is_float; |
| 3207 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3208 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3209 | |
| 3210 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3211 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3212 | __ Bind(&retry); |
| 3213 | __ fprem(); |
| 3214 | |
| 3215 | // Move FP status to AX. |
| 3216 | __ fstsw(); |
| 3217 | |
| 3218 | // And see if the argument reduction is complete. This is signaled by the |
| 3219 | // C2 FPU flag bit set to 0. |
| 3220 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3221 | __ j(kNotEqual, &retry); |
| 3222 | |
| 3223 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3224 | // Store FP top of stack to real stack. |
| 3225 | if (is_float) { |
| 3226 | __ fsts(Address(ESP, 0)); |
| 3227 | } else { |
| 3228 | __ fstl(Address(ESP, 0)); |
| 3229 | } |
| 3230 | |
| 3231 | // Pop the 2 items from the FP stack. |
| 3232 | __ fucompp(); |
| 3233 | |
| 3234 | // Load the value from the stack into an XMM register. |
| 3235 | DCHECK(out.IsFpuRegister()) << out; |
| 3236 | if (is_float) { |
| 3237 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3238 | } else { |
| 3239 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3240 | } |
| 3241 | |
| 3242 | // And remove the temporary stack space we allocated. |
| 3243 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3244 | } |
| 3245 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3246 | |
| 3247 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3248 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3249 | |
| 3250 | LocationSummary* locations = instruction->GetLocations(); |
| 3251 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3252 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3253 | |
| 3254 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3255 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3256 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3257 | |
| 3258 | DCHECK(imm == 1 || imm == -1); |
| 3259 | |
| 3260 | if (instruction->IsRem()) { |
| 3261 | __ xorl(out_register, out_register); |
| 3262 | } else { |
| 3263 | __ movl(out_register, input_register); |
| 3264 | if (imm == -1) { |
| 3265 | __ negl(out_register); |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3271 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3272 | LocationSummary* locations = instruction->GetLocations(); |
| 3273 | |
| 3274 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3275 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3276 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3277 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3278 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3279 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3280 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3281 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3282 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3283 | __ testl(input_register, input_register); |
| 3284 | __ cmovl(kGreaterEqual, num, input_register); |
| 3285 | int shift = CTZ(imm); |
| 3286 | __ sarl(num, Immediate(shift)); |
| 3287 | |
| 3288 | if (imm < 0) { |
| 3289 | __ negl(num); |
| 3290 | } |
| 3291 | |
| 3292 | __ movl(out_register, num); |
| 3293 | } |
| 3294 | |
| 3295 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3296 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3297 | |
| 3298 | LocationSummary* locations = instruction->GetLocations(); |
| 3299 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3300 | |
| 3301 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3302 | Register out = locations->Out().AsRegister<Register>(); |
| 3303 | Register num; |
| 3304 | Register edx; |
| 3305 | |
| 3306 | if (instruction->IsDiv()) { |
| 3307 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3308 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3309 | } else { |
| 3310 | edx = locations->Out().AsRegister<Register>(); |
| 3311 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3312 | } |
| 3313 | |
| 3314 | DCHECK_EQ(EAX, eax); |
| 3315 | DCHECK_EQ(EDX, edx); |
| 3316 | if (instruction->IsDiv()) { |
| 3317 | DCHECK_EQ(EAX, out); |
| 3318 | } else { |
| 3319 | DCHECK_EQ(EDX, out); |
| 3320 | } |
| 3321 | |
| 3322 | int64_t magic; |
| 3323 | int shift; |
| 3324 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3325 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3326 | // Save the numerator. |
| 3327 | __ movl(num, eax); |
| 3328 | |
| 3329 | // EAX = magic |
| 3330 | __ movl(eax, Immediate(magic)); |
| 3331 | |
| 3332 | // EDX:EAX = magic * numerator |
| 3333 | __ imull(num); |
| 3334 | |
| 3335 | if (imm > 0 && magic < 0) { |
| 3336 | // EDX += num |
| 3337 | __ addl(edx, num); |
| 3338 | } else if (imm < 0 && magic > 0) { |
| 3339 | __ subl(edx, num); |
| 3340 | } |
| 3341 | |
| 3342 | // Shift if needed. |
| 3343 | if (shift != 0) { |
| 3344 | __ sarl(edx, Immediate(shift)); |
| 3345 | } |
| 3346 | |
| 3347 | // EDX += 1 if EDX < 0 |
| 3348 | __ movl(eax, edx); |
| 3349 | __ shrl(edx, Immediate(31)); |
| 3350 | __ addl(edx, eax); |
| 3351 | |
| 3352 | if (instruction->IsRem()) { |
| 3353 | __ movl(eax, num); |
| 3354 | __ imull(edx, Immediate(imm)); |
| 3355 | __ subl(eax, edx); |
| 3356 | __ movl(edx, eax); |
| 3357 | } else { |
| 3358 | __ movl(eax, edx); |
| 3359 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3360 | } |
| 3361 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3362 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3363 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3364 | |
| 3365 | LocationSummary* locations = instruction->GetLocations(); |
| 3366 | Location out = locations->Out(); |
| 3367 | Location first = locations->InAt(0); |
| 3368 | Location second = locations->InAt(1); |
| 3369 | bool is_div = instruction->IsDiv(); |
| 3370 | |
| 3371 | switch (instruction->GetResultType()) { |
| 3372 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3373 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3374 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3375 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3376 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3377 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3378 | |
| 3379 | if (imm == 0) { |
| 3380 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3381 | } else if (imm == 1 || imm == -1) { |
| 3382 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3383 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3384 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3385 | } else { |
| 3386 | DCHECK(imm <= -2 || imm >= 2); |
| 3387 | GenerateDivRemWithAnyConstant(instruction); |
| 3388 | } |
| 3389 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3390 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3391 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3392 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3393 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3394 | Register second_reg = second.AsRegister<Register>(); |
| 3395 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3396 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3397 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3398 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3399 | __ cmpl(second_reg, Immediate(-1)); |
| 3400 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3401 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3402 | // edx:eax <- sign-extended of eax |
| 3403 | __ cdq(); |
| 3404 | // eax = quotient, edx = remainder |
| 3405 | __ idivl(second_reg); |
| 3406 | __ Bind(slow_path->GetExitLabel()); |
| 3407 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3408 | break; |
| 3409 | } |
| 3410 | |
| 3411 | case Primitive::kPrimLong: { |
| 3412 | InvokeRuntimeCallingConvention calling_convention; |
| 3413 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3414 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3415 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3416 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3417 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3418 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3419 | |
| 3420 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3421 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3422 | instruction, |
| 3423 | instruction->GetDexPc(), |
| 3424 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3425 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3426 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3427 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3428 | instruction, |
| 3429 | instruction->GetDexPc(), |
| 3430 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3431 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3432 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3433 | break; |
| 3434 | } |
| 3435 | |
| 3436 | default: |
| 3437 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3438 | } |
| 3439 | } |
| 3440 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3441 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3442 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3443 | ? LocationSummary::kCall |
| 3444 | : LocationSummary::kNoCall; |
| 3445 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3446 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3447 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3448 | case Primitive::kPrimInt: { |
| 3449 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3450 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3451 | locations->SetOut(Location::SameAsFirstInput()); |
| 3452 | // Intel uses edx:eax as the dividend. |
| 3453 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3454 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3455 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3456 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3457 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | locations->AddTemp(Location::RequiresRegister()); |
| 3459 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3460 | break; |
| 3461 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3462 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3463 | InvokeRuntimeCallingConvention calling_convention; |
| 3464 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3465 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3466 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3467 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3468 | // Runtime helper puts the result in EAX, EDX. |
| 3469 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3470 | break; |
| 3471 | } |
| 3472 | case Primitive::kPrimFloat: |
| 3473 | case Primitive::kPrimDouble: { |
| 3474 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3475 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3476 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3477 | } else if (div->InputAt(1)->IsConstant()) { |
| 3478 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3479 | } else { |
| 3480 | locations->SetInAt(1, Location::Any()); |
| 3481 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3482 | locations->SetOut(Location::SameAsFirstInput()); |
| 3483 | break; |
| 3484 | } |
| 3485 | |
| 3486 | default: |
| 3487 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3488 | } |
| 3489 | } |
| 3490 | |
| 3491 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3492 | LocationSummary* locations = div->GetLocations(); |
| 3493 | Location first = locations->InAt(0); |
| 3494 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3495 | |
| 3496 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3497 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3498 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3499 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3500 | break; |
| 3501 | } |
| 3502 | |
| 3503 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3504 | if (second.IsFpuRegister()) { |
| 3505 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3506 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3507 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3508 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3509 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3510 | codegen_->LiteralFloatAddress( |
| 3511 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3512 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3513 | } else { |
| 3514 | DCHECK(second.IsStackSlot()); |
| 3515 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3516 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3517 | break; |
| 3518 | } |
| 3519 | |
| 3520 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3521 | if (second.IsFpuRegister()) { |
| 3522 | __ divsd(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 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3527 | codegen_->LiteralDoubleAddress( |
| 3528 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3529 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3530 | } else { |
| 3531 | DCHECK(second.IsDoubleStackSlot()); |
| 3532 | __ divsd(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 | default: |
| 3538 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3539 | } |
| 3540 | } |
| 3541 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3542 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3543 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3544 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3545 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3546 | ? LocationSummary::kCall |
| 3547 | : LocationSummary::kNoCall; |
| 3548 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3549 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3550 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3551 | case Primitive::kPrimInt: { |
| 3552 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3553 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3554 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3555 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3556 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3557 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3558 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3559 | locations->AddTemp(Location::RequiresRegister()); |
| 3560 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3561 | break; |
| 3562 | } |
| 3563 | case Primitive::kPrimLong: { |
| 3564 | InvokeRuntimeCallingConvention calling_convention; |
| 3565 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3566 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3567 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3568 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3569 | // Runtime helper puts the result in EAX, EDX. |
| 3570 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3571 | break; |
| 3572 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3573 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3574 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3575 | locations->SetInAt(0, Location::Any()); |
| 3576 | locations->SetInAt(1, Location::Any()); |
| 3577 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3578 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3579 | break; |
| 3580 | } |
| 3581 | |
| 3582 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3583 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3588 | Primitive::Type type = rem->GetResultType(); |
| 3589 | switch (type) { |
| 3590 | case Primitive::kPrimInt: |
| 3591 | case Primitive::kPrimLong: { |
| 3592 | GenerateDivRemIntegral(rem); |
| 3593 | break; |
| 3594 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3595 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3596 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3597 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3598 | break; |
| 3599 | } |
| 3600 | default: |
| 3601 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3602 | } |
| 3603 | } |
| 3604 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3605 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3606 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3607 | ? LocationSummary::kCallOnSlowPath |
| 3608 | : LocationSummary::kNoCall; |
| 3609 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3610 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3611 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3612 | case Primitive::kPrimByte: |
| 3613 | case Primitive::kPrimChar: |
| 3614 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3615 | case Primitive::kPrimInt: { |
| 3616 | locations->SetInAt(0, Location::Any()); |
| 3617 | break; |
| 3618 | } |
| 3619 | case Primitive::kPrimLong: { |
| 3620 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3621 | if (!instruction->IsConstant()) { |
| 3622 | locations->AddTemp(Location::RequiresRegister()); |
| 3623 | } |
| 3624 | break; |
| 3625 | } |
| 3626 | default: |
| 3627 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3628 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3629 | if (instruction->HasUses()) { |
| 3630 | locations->SetOut(Location::SameAsFirstInput()); |
| 3631 | } |
| 3632 | } |
| 3633 | |
| 3634 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3635 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3636 | codegen_->AddSlowPath(slow_path); |
| 3637 | |
| 3638 | LocationSummary* locations = instruction->GetLocations(); |
| 3639 | Location value = locations->InAt(0); |
| 3640 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3641 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3642 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3643 | case Primitive::kPrimByte: |
| 3644 | case Primitive::kPrimChar: |
| 3645 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3646 | case Primitive::kPrimInt: { |
| 3647 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3648 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3649 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3650 | } else if (value.IsStackSlot()) { |
| 3651 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3652 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3653 | } else { |
| 3654 | DCHECK(value.IsConstant()) << value; |
| 3655 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3656 | __ jmp(slow_path->GetEntryLabel()); |
| 3657 | } |
| 3658 | } |
| 3659 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3660 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3661 | case Primitive::kPrimLong: { |
| 3662 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3663 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3664 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3665 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3666 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3667 | } else { |
| 3668 | DCHECK(value.IsConstant()) << value; |
| 3669 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3670 | __ jmp(slow_path->GetEntryLabel()); |
| 3671 | } |
| 3672 | } |
| 3673 | break; |
| 3674 | } |
| 3675 | default: |
| 3676 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3677 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3680 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3681 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3682 | |
| 3683 | LocationSummary* locations = |
| 3684 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3685 | |
| 3686 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3687 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3688 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3689 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3690 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3691 | // The shift count needs to be in CL or a constant. |
| 3692 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3693 | locations->SetOut(Location::SameAsFirstInput()); |
| 3694 | break; |
| 3695 | } |
| 3696 | default: |
| 3697 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3698 | } |
| 3699 | } |
| 3700 | |
| 3701 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3702 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3703 | |
| 3704 | LocationSummary* locations = op->GetLocations(); |
| 3705 | Location first = locations->InAt(0); |
| 3706 | Location second = locations->InAt(1); |
| 3707 | DCHECK(first.Equals(locations->Out())); |
| 3708 | |
| 3709 | switch (op->GetResultType()) { |
| 3710 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3711 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3712 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3713 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3714 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3715 | DCHECK_EQ(ECX, second_reg); |
| 3716 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3717 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3718 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3719 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3720 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3721 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3722 | } |
| 3723 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3724 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3725 | if (shift == 0) { |
| 3726 | return; |
| 3727 | } |
| 3728 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3729 | if (op->IsShl()) { |
| 3730 | __ shll(first_reg, imm); |
| 3731 | } else if (op->IsShr()) { |
| 3732 | __ sarl(first_reg, imm); |
| 3733 | } else { |
| 3734 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3735 | } |
| 3736 | } |
| 3737 | break; |
| 3738 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3739 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3740 | if (second.IsRegister()) { |
| 3741 | Register second_reg = second.AsRegister<Register>(); |
| 3742 | DCHECK_EQ(ECX, second_reg); |
| 3743 | if (op->IsShl()) { |
| 3744 | GenerateShlLong(first, second_reg); |
| 3745 | } else if (op->IsShr()) { |
| 3746 | GenerateShrLong(first, second_reg); |
| 3747 | } else { |
| 3748 | GenerateUShrLong(first, second_reg); |
| 3749 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3750 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3751 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3752 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3753 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3754 | if (shift != 0) { |
| 3755 | if (op->IsShl()) { |
| 3756 | GenerateShlLong(first, shift); |
| 3757 | } else if (op->IsShr()) { |
| 3758 | GenerateShrLong(first, shift); |
| 3759 | } else { |
| 3760 | GenerateUShrLong(first, shift); |
| 3761 | } |
| 3762 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3763 | } |
| 3764 | break; |
| 3765 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3766 | default: |
| 3767 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3768 | } |
| 3769 | } |
| 3770 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3771 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3772 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3773 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3774 | if (shift == 1) { |
| 3775 | // This is just an addition. |
| 3776 | __ addl(low, low); |
| 3777 | __ adcl(high, high); |
| 3778 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3779 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3780 | codegen_->EmitParallelMoves( |
| 3781 | loc.ToLow(), |
| 3782 | loc.ToHigh(), |
| 3783 | Primitive::kPrimInt, |
| 3784 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3785 | loc.ToLow(), |
| 3786 | Primitive::kPrimInt); |
| 3787 | } else if (shift > 32) { |
| 3788 | // Low part becomes 0. High part is low part << (shift-32). |
| 3789 | __ movl(high, low); |
| 3790 | __ shll(high, Immediate(shift - 32)); |
| 3791 | __ xorl(low, low); |
| 3792 | } else { |
| 3793 | // Between 1 and 31. |
| 3794 | __ shld(high, low, Immediate(shift)); |
| 3795 | __ shll(low, Immediate(shift)); |
| 3796 | } |
| 3797 | } |
| 3798 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3799 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3800 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3801 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3802 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3803 | __ testl(shifter, Immediate(32)); |
| 3804 | __ j(kEqual, &done); |
| 3805 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3806 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3807 | __ Bind(&done); |
| 3808 | } |
| 3809 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3810 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3811 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3812 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3813 | if (shift == 32) { |
| 3814 | // Need to copy the sign. |
| 3815 | DCHECK_NE(low, high); |
| 3816 | __ movl(low, high); |
| 3817 | __ sarl(high, Immediate(31)); |
| 3818 | } else if (shift > 32) { |
| 3819 | DCHECK_NE(low, high); |
| 3820 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3821 | __ movl(low, high); |
| 3822 | __ sarl(high, Immediate(31)); |
| 3823 | __ sarl(low, Immediate(shift - 32)); |
| 3824 | } else { |
| 3825 | // Between 1 and 31. |
| 3826 | __ shrd(low, high, Immediate(shift)); |
| 3827 | __ sarl(high, Immediate(shift)); |
| 3828 | } |
| 3829 | } |
| 3830 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3831 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3832 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3833 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3834 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3835 | __ testl(shifter, Immediate(32)); |
| 3836 | __ j(kEqual, &done); |
| 3837 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3838 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3839 | __ Bind(&done); |
| 3840 | } |
| 3841 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3842 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3843 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3844 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3845 | if (shift == 32) { |
| 3846 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3847 | codegen_->EmitParallelMoves( |
| 3848 | loc.ToHigh(), |
| 3849 | loc.ToLow(), |
| 3850 | Primitive::kPrimInt, |
| 3851 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3852 | loc.ToHigh(), |
| 3853 | Primitive::kPrimInt); |
| 3854 | } else if (shift > 32) { |
| 3855 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3856 | __ movl(low, high); |
| 3857 | __ shrl(low, Immediate(shift - 32)); |
| 3858 | __ xorl(high, high); |
| 3859 | } else { |
| 3860 | // Between 1 and 31. |
| 3861 | __ shrd(low, high, Immediate(shift)); |
| 3862 | __ shrl(high, Immediate(shift)); |
| 3863 | } |
| 3864 | } |
| 3865 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3867 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3868 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3869 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3870 | __ testl(shifter, Immediate(32)); |
| 3871 | __ j(kEqual, &done); |
| 3872 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3873 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3874 | __ Bind(&done); |
| 3875 | } |
| 3876 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3877 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3878 | LocationSummary* locations = |
| 3879 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3880 | |
| 3881 | switch (ror->GetResultType()) { |
| 3882 | case Primitive::kPrimLong: |
| 3883 | // Add the temporary needed. |
| 3884 | locations->AddTemp(Location::RequiresRegister()); |
| 3885 | FALLTHROUGH_INTENDED; |
| 3886 | case Primitive::kPrimInt: |
| 3887 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3888 | // The shift count needs to be in CL (unless it is a constant). |
| 3889 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3890 | locations->SetOut(Location::SameAsFirstInput()); |
| 3891 | break; |
| 3892 | default: |
| 3893 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3894 | UNREACHABLE(); |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3899 | LocationSummary* locations = ror->GetLocations(); |
| 3900 | Location first = locations->InAt(0); |
| 3901 | Location second = locations->InAt(1); |
| 3902 | |
| 3903 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3904 | Register first_reg = first.AsRegister<Register>(); |
| 3905 | if (second.IsRegister()) { |
| 3906 | Register second_reg = second.AsRegister<Register>(); |
| 3907 | __ rorl(first_reg, second_reg); |
| 3908 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3909 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3910 | __ rorl(first_reg, imm); |
| 3911 | } |
| 3912 | return; |
| 3913 | } |
| 3914 | |
| 3915 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3916 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3917 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3918 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3919 | if (second.IsRegister()) { |
| 3920 | Register second_reg = second.AsRegister<Register>(); |
| 3921 | DCHECK_EQ(second_reg, ECX); |
| 3922 | __ movl(temp_reg, first_reg_hi); |
| 3923 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3924 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3925 | __ movl(temp_reg, first_reg_hi); |
| 3926 | __ testl(second_reg, Immediate(32)); |
| 3927 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3928 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3929 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3930 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3931 | if (shift_amt == 0) { |
| 3932 | // Already fine. |
| 3933 | return; |
| 3934 | } |
| 3935 | if (shift_amt == 32) { |
| 3936 | // Just swap. |
| 3937 | __ movl(temp_reg, first_reg_lo); |
| 3938 | __ movl(first_reg_lo, first_reg_hi); |
| 3939 | __ movl(first_reg_hi, temp_reg); |
| 3940 | return; |
| 3941 | } |
| 3942 | |
| 3943 | Immediate imm(shift_amt); |
| 3944 | // Save the constents of the low value. |
| 3945 | __ movl(temp_reg, first_reg_lo); |
| 3946 | |
| 3947 | // Shift right into low, feeding bits from high. |
| 3948 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3949 | |
| 3950 | // Shift right into high, feeding bits from the original low. |
| 3951 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3952 | |
| 3953 | // Swap if needed. |
| 3954 | if (shift_amt > 32) { |
| 3955 | __ movl(temp_reg, first_reg_lo); |
| 3956 | __ movl(first_reg_lo, first_reg_hi); |
| 3957 | __ movl(first_reg_hi, temp_reg); |
| 3958 | } |
| 3959 | } |
| 3960 | } |
| 3961 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3962 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3963 | HandleShift(shl); |
| 3964 | } |
| 3965 | |
| 3966 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3967 | HandleShift(shl); |
| 3968 | } |
| 3969 | |
| 3970 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3971 | HandleShift(shr); |
| 3972 | } |
| 3973 | |
| 3974 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3975 | HandleShift(shr); |
| 3976 | } |
| 3977 | |
| 3978 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3979 | HandleShift(ushr); |
| 3980 | } |
| 3981 | |
| 3982 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3983 | HandleShift(ushr); |
| 3984 | } |
| 3985 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3986 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3987 | LocationSummary* locations = |
| 3988 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3989 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3990 | if (instruction->IsStringAlloc()) { |
| 3991 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3992 | } else { |
| 3993 | InvokeRuntimeCallingConvention calling_convention; |
| 3994 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3995 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3996 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4000 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4001 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4002 | if (instruction->IsStringAlloc()) { |
| 4003 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4004 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4005 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4006 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4007 | __ call(Address(temp, code_offset.Int32Value())); |
| 4008 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4009 | } else { |
| 4010 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4011 | instruction, |
| 4012 | instruction->GetDexPc(), |
| 4013 | nullptr); |
| 4014 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4015 | DCHECK(!codegen_->IsLeafMethod()); |
| 4016 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4019 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4020 | LocationSummary* locations = |
| 4021 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4022 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4023 | InvokeRuntimeCallingConvention calling_convention; |
| 4024 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4025 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4026 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4030 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4031 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4032 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4033 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4034 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4035 | instruction, |
| 4036 | instruction->GetDexPc(), |
| 4037 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4038 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4039 | DCHECK(!codegen_->IsLeafMethod()); |
| 4040 | } |
| 4041 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4042 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4043 | LocationSummary* locations = |
| 4044 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4045 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4046 | if (location.IsStackSlot()) { |
| 4047 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4048 | } else if (location.IsDoubleStackSlot()) { |
| 4049 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4050 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4051 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4054 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4055 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4056 | } |
| 4057 | |
| 4058 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4059 | LocationSummary* locations = |
| 4060 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4061 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4062 | } |
| 4063 | |
| 4064 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4065 | } |
| 4066 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4067 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4068 | LocationSummary* locations = |
| 4069 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4070 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4071 | locations->SetOut(Location::RequiresRegister()); |
| 4072 | } |
| 4073 | |
| 4074 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4075 | LocationSummary* locations = instruction->GetLocations(); |
| 4076 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4077 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4078 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4079 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4080 | } else { |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 4081 | __ movl(locations->InAt(0).AsRegister<Register>(), |
| 4082 | Address(locations->InAt(0).AsRegister<Register>(), |
| 4083 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); |
| 4084 | // temp = temp->GetImtEntryAt(method_offset); |
| 4085 | method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( |
| 4086 | instruction->GetIndex() % ImTable::kSize, kX86PointerSize)); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4087 | } |
| 4088 | __ movl(locations->Out().AsRegister<Register>(), |
| 4089 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4090 | } |
| 4091 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4092 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4093 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4094 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4095 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4096 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4097 | } |
| 4098 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4099 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4100 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4101 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4102 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4103 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4104 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4105 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4106 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4107 | break; |
| 4108 | |
| 4109 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4110 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4111 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4112 | break; |
| 4113 | |
| 4114 | default: |
| 4115 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4116 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4117 | } |
| 4118 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4119 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4120 | LocationSummary* locations = |
| 4121 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4122 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4123 | locations->SetOut(Location::SameAsFirstInput()); |
| 4124 | } |
| 4125 | |
| 4126 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4127 | LocationSummary* locations = bool_not->GetLocations(); |
| 4128 | Location in = locations->InAt(0); |
| 4129 | Location out = locations->Out(); |
| 4130 | DCHECK(in.Equals(out)); |
| 4131 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4132 | } |
| 4133 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4134 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4135 | LocationSummary* locations = |
| 4136 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4137 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4138 | case Primitive::kPrimBoolean: |
| 4139 | case Primitive::kPrimByte: |
| 4140 | case Primitive::kPrimShort: |
| 4141 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4142 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4143 | case Primitive::kPrimLong: { |
| 4144 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4145 | locations->SetInAt(1, Location::Any()); |
| 4146 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4147 | break; |
| 4148 | } |
| 4149 | case Primitive::kPrimFloat: |
| 4150 | case Primitive::kPrimDouble: { |
| 4151 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4152 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4153 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4154 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4155 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4156 | } else { |
| 4157 | locations->SetInAt(1, Location::Any()); |
| 4158 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4159 | locations->SetOut(Location::RequiresRegister()); |
| 4160 | break; |
| 4161 | } |
| 4162 | default: |
| 4163 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4164 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4168 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4169 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4170 | Location left = locations->InAt(0); |
| 4171 | Location right = locations->InAt(1); |
| 4172 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4173 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4174 | Condition less_cond = kLess; |
| 4175 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4176 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4177 | case Primitive::kPrimBoolean: |
| 4178 | case Primitive::kPrimByte: |
| 4179 | case Primitive::kPrimShort: |
| 4180 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4181 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4182 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4183 | break; |
| 4184 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4185 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4186 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4187 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4188 | int32_t val_low = 0; |
| 4189 | int32_t val_high = 0; |
| 4190 | bool right_is_const = false; |
| 4191 | |
| 4192 | if (right.IsConstant()) { |
| 4193 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4194 | right_is_const = true; |
| 4195 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4196 | val_low = Low32Bits(val); |
| 4197 | val_high = High32Bits(val); |
| 4198 | } |
| 4199 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4200 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4201 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4202 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4203 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4204 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4205 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4206 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4207 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4208 | __ j(kLess, &less); // Signed compare. |
| 4209 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4210 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4211 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4212 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4213 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4214 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4215 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4216 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4217 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4218 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4219 | break; |
| 4220 | } |
| 4221 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4222 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4223 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4224 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4225 | break; |
| 4226 | } |
| 4227 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4228 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4229 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4230 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4231 | break; |
| 4232 | } |
| 4233 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4234 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4235 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4236 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4237 | __ movl(out, Immediate(0)); |
| 4238 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4239 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4240 | |
| 4241 | __ Bind(&greater); |
| 4242 | __ movl(out, Immediate(1)); |
| 4243 | __ jmp(&done); |
| 4244 | |
| 4245 | __ Bind(&less); |
| 4246 | __ movl(out, Immediate(-1)); |
| 4247 | |
| 4248 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4249 | } |
| 4250 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4251 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4252 | LocationSummary* locations = |
| 4253 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4254 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4255 | locations->SetInAt(i, Location::Any()); |
| 4256 | } |
| 4257 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4258 | } |
| 4259 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4260 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4261 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4262 | } |
| 4263 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4264 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4265 | /* |
| 4266 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4267 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4268 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4269 | */ |
| 4270 | switch (kind) { |
| 4271 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4272 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4273 | break; |
| 4274 | } |
| 4275 | case MemBarrierKind::kAnyStore: |
| 4276 | case MemBarrierKind::kLoadAny: |
| 4277 | case MemBarrierKind::kStoreStore: { |
| 4278 | // nop |
| 4279 | break; |
| 4280 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4281 | case MemBarrierKind::kNTStoreStore: |
| 4282 | // Non-Temporal Store/Store needs an explicit fence. |
| 4283 | MemoryFence(/* non-temporal */ true); |
| 4284 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4285 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4286 | } |
| 4287 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4288 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4289 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4290 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4291 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4292 | |
| 4293 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4294 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4295 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4296 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4297 | if (GetGraph()->HasIrreducibleLoops() && |
| 4298 | (dispatch_info.method_load_kind == |
| 4299 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4300 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4301 | } |
| 4302 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4303 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4304 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4305 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4306 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4307 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4308 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4309 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4310 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4311 | 0u |
| 4312 | }; |
| 4313 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4314 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4315 | } |
| 4316 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4317 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4318 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4319 | Register temp) { |
| 4320 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4321 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4322 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4323 | return location.AsRegister<Register>(); |
| 4324 | } |
| 4325 | // For intrinsics we allow any location, so it may be on the stack. |
| 4326 | if (!location.IsRegister()) { |
| 4327 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4328 | return temp; |
| 4329 | } |
| 4330 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4331 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4332 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4333 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4334 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4335 | if (slow_path != nullptr) { |
| 4336 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4337 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4338 | __ movl(temp, Address(ESP, stack_offset)); |
| 4339 | return temp; |
| 4340 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4341 | } |
| 4342 | return location.AsRegister<Register>(); |
| 4343 | } |
| 4344 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4345 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4346 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4347 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4348 | switch (invoke->GetMethodLoadKind()) { |
| 4349 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4350 | // temp = thread->string_init_entrypoint |
| 4351 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4352 | break; |
| 4353 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4354 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4355 | break; |
| 4356 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4357 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4358 | break; |
| 4359 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4360 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4361 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4362 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4363 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4364 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4365 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4366 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4367 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4368 | // Bind a new fixup label at the end of the "movl" insn. |
| 4369 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4370 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4371 | break; |
| 4372 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4373 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4374 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4375 | Register method_reg; |
| 4376 | Register reg = temp.AsRegister<Register>(); |
| 4377 | if (current_method.IsRegister()) { |
| 4378 | method_reg = current_method.AsRegister<Register>(); |
| 4379 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4380 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4381 | DCHECK(!current_method.IsValid()); |
| 4382 | method_reg = reg; |
| 4383 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4384 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4385 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4386 | __ movl(reg, Address(method_reg, |
| 4387 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4388 | // temp = temp[index_in_cache]; |
| 4389 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4390 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4391 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4392 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4393 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4394 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4395 | return callee_method; |
| 4396 | } |
| 4397 | |
| 4398 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4399 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4400 | |
| 4401 | switch (invoke->GetCodePtrLocation()) { |
| 4402 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4403 | __ call(GetFrameEntryLabel()); |
| 4404 | break; |
| 4405 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4406 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4407 | Label* label = &relative_call_patches_.back().label; |
| 4408 | __ call(label); // Bind to the patch label, override at link time. |
| 4409 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4410 | break; |
| 4411 | } |
| 4412 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4413 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4414 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4415 | LOG(FATAL) << "Unsupported"; |
| 4416 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4417 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4418 | // (callee_method + offset_of_quick_compiled_code)() |
| 4419 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4420 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4421 | kX86WordSize).Int32Value())); |
| 4422 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4426 | } |
| 4427 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4428 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4429 | Register temp = temp_in.AsRegister<Register>(); |
| 4430 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4431 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4432 | |
| 4433 | // Use the calling convention instead of the location of the receiver, as |
| 4434 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4435 | // slow path, the arguments have been moved to the right place, so here we are |
| 4436 | // guaranteed that the receiver is the first register of the calling convention. |
| 4437 | InvokeDexCallingConvention calling_convention; |
| 4438 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4439 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4440 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4441 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4442 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4443 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4444 | // emit a read barrier for the previous class reference load. |
| 4445 | // However this is not required in practice, as this is an |
| 4446 | // intermediate/temporary reference and because the current |
| 4447 | // concurrent copying collector keeps the from-space memory |
| 4448 | // intact/accessible until the end of the marking phase (the |
| 4449 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4450 | __ MaybeUnpoisonHeapReference(temp); |
| 4451 | // temp = temp->GetMethodAt(method_offset); |
| 4452 | __ movl(temp, Address(temp, method_offset)); |
| 4453 | // call temp->GetEntryPoint(); |
| 4454 | __ call(Address( |
| 4455 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4456 | } |
| 4457 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4458 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4459 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4460 | simple_patches_.emplace_back(); |
| 4461 | __ Bind(&simple_patches_.back()); |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4466 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4467 | __ Bind(&string_patches_.back().label); |
| 4468 | } |
| 4469 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4470 | void CodeGeneratorX86::RecordTypePatch(HLoadClass* load_class) { |
| 4471 | type_patches_.emplace_back(load_class->GetDexFile(), load_class->GetTypeIndex()); |
| 4472 | __ Bind(&type_patches_.back().label); |
| 4473 | } |
| 4474 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4475 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4476 | uint32_t element_offset) { |
| 4477 | // Add the patch entry and bind its label at the end of the instruction. |
| 4478 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4479 | return &pc_relative_dex_cache_patches_.back().label; |
| 4480 | } |
| 4481 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4482 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4483 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4484 | size_t size = |
| 4485 | method_patches_.size() + |
| 4486 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4487 | pc_relative_dex_cache_patches_.size() + |
| 4488 | simple_patches_.size() + |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4489 | string_patches_.size() + |
| 4490 | type_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4491 | linker_patches->reserve(size); |
| 4492 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4493 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4494 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4495 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4496 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4497 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4498 | info.target_method.dex_file, |
| 4499 | info.target_method.dex_method_index)); |
| 4500 | } |
| 4501 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4502 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4504 | info.target_method.dex_file, |
| 4505 | info.target_method.dex_method_index)); |
| 4506 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4507 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4508 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4509 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4510 | &info.target_dex_file, |
| 4511 | GetMethodAddressOffset(), |
| 4512 | info.element_offset)); |
| 4513 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4514 | for (const Label& label : simple_patches_) { |
| 4515 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4516 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4517 | } |
| 4518 | if (GetCompilerOptions().GetCompilePic()) { |
| 4519 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4520 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4521 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4522 | &info.dex_file, |
| 4523 | GetMethodAddressOffset(), |
| 4524 | info.string_index)); |
| 4525 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4526 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4527 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4528 | linker_patches->push_back(LinkerPatch::RelativeTypePatch(literal_offset, |
| 4529 | &info.dex_file, |
| 4530 | GetMethodAddressOffset(), |
| 4531 | info.type_index)); |
| 4532 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4533 | } else { |
| 4534 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4535 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4536 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4537 | &info.dex_file, |
| 4538 | info.string_index)); |
| 4539 | } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4540 | for (const TypePatchInfo<Label>& info : type_patches_) { |
| 4541 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4542 | linker_patches->push_back(LinkerPatch::TypePatch(literal_offset, |
| 4543 | &info.dex_file, |
| 4544 | info.type_index)); |
| 4545 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4546 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4547 | } |
| 4548 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4549 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4550 | Register card, |
| 4551 | Register object, |
| 4552 | Register value, |
| 4553 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4554 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4555 | if (value_can_be_null) { |
| 4556 | __ testl(value, value); |
| 4557 | __ j(kEqual, &is_null); |
| 4558 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4559 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4560 | __ movl(temp, object); |
| 4561 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4562 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4563 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4564 | if (value_can_be_null) { |
| 4565 | __ Bind(&is_null); |
| 4566 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4567 | } |
| 4568 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4569 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4570 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4571 | |
| 4572 | bool object_field_get_with_read_barrier = |
| 4573 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4574 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4575 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4576 | kEmitCompilerReadBarrier ? |
| 4577 | LocationSummary::kCallOnSlowPath : |
| 4578 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4579 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4580 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4581 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4582 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4583 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4584 | // The output overlaps in case of long: we don't want the low move |
| 4585 | // to overwrite the object's location. Likewise, in the case of |
| 4586 | // an object field get with read barriers enabled, we do not want |
| 4587 | // the move to overwrite the object's location, as we need it to emit |
| 4588 | // the read barrier. |
| 4589 | locations->SetOut( |
| 4590 | Location::RequiresRegister(), |
| 4591 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4592 | Location::kOutputOverlap : |
| 4593 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4594 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4595 | |
| 4596 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4597 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4598 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4599 | // load the temp into the XMM and then copy the XMM into the |
| 4600 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4601 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4602 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4603 | // We need a temporary register for the read barrier marking slow |
| 4604 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4605 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4606 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4607 | } |
| 4608 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4609 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4610 | const FieldInfo& field_info) { |
| 4611 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4612 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4613 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4614 | Location base_loc = locations->InAt(0); |
| 4615 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4616 | Location out = locations->Out(); |
| 4617 | bool is_volatile = field_info.IsVolatile(); |
| 4618 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4619 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4620 | |
| 4621 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4622 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4623 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4624 | break; |
| 4625 | } |
| 4626 | |
| 4627 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4628 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4629 | break; |
| 4630 | } |
| 4631 | |
| 4632 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4634 | break; |
| 4635 | } |
| 4636 | |
| 4637 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4638 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4639 | break; |
| 4640 | } |
| 4641 | |
| 4642 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4643 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4644 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4645 | |
| 4646 | case Primitive::kPrimNot: { |
| 4647 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4648 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4649 | Location temp_loc = locations->GetTemp(0); |
| 4650 | // Note that a potential implicit null check is handled in this |
| 4651 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4652 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4653 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4654 | if (is_volatile) { |
| 4655 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4656 | } |
| 4657 | } else { |
| 4658 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4659 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4660 | if (is_volatile) { |
| 4661 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4662 | } |
| 4663 | // If read barriers are enabled, emit read barriers other than |
| 4664 | // Baker's using a slow path (and also unpoison the loaded |
| 4665 | // reference, if heap poisoning is enabled). |
| 4666 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4667 | } |
| 4668 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | if (is_volatile) { |
| 4673 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4674 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4675 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4676 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4677 | __ psrlq(temp, Immediate(32)); |
| 4678 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4679 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4680 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4681 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4682 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4683 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4684 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4685 | break; |
| 4686 | } |
| 4687 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4688 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4689 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4690 | break; |
| 4691 | } |
| 4692 | |
| 4693 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4694 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4695 | break; |
| 4696 | } |
| 4697 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4698 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4699 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4700 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4701 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4702 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4703 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4704 | // Potential implicit null checks, in the case of reference or |
| 4705 | // long fields, are handled in the previous switch statement. |
| 4706 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4707 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4708 | } |
| 4709 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4710 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4711 | if (field_type == Primitive::kPrimNot) { |
| 4712 | // Memory barriers, in the case of references, are also handled |
| 4713 | // in the previous switch statement. |
| 4714 | } else { |
| 4715 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4716 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4717 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4721 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4722 | |
| 4723 | LocationSummary* locations = |
| 4724 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4725 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4726 | bool is_volatile = field_info.IsVolatile(); |
| 4727 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4728 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4729 | || (field_type == Primitive::kPrimByte); |
| 4730 | |
| 4731 | // The register allocator does not support multiple |
| 4732 | // inputs that die at entry with one in a specific register. |
| 4733 | if (is_byte_type) { |
| 4734 | // Ensure the value is in a byte register. |
| 4735 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4736 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4737 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4738 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4739 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4740 | } else { |
| 4741 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4742 | } |
| 4743 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4744 | // 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] | 4745 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4746 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4748 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4749 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4750 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4751 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4752 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4753 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4754 | } else { |
| 4755 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4756 | |
| 4757 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4758 | // Temporary registers for the write barrier. |
| 4759 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4760 | // Ensure the card is in a byte register. |
| 4761 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4762 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4767 | const FieldInfo& field_info, |
| 4768 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4769 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4770 | |
| 4771 | LocationSummary* locations = instruction->GetLocations(); |
| 4772 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4773 | Location value = locations->InAt(1); |
| 4774 | bool is_volatile = field_info.IsVolatile(); |
| 4775 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4776 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4777 | bool needs_write_barrier = |
| 4778 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4779 | |
| 4780 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4781 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4784 | bool maybe_record_implicit_null_check_done = false; |
| 4785 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4786 | switch (field_type) { |
| 4787 | case Primitive::kPrimBoolean: |
| 4788 | case Primitive::kPrimByte: { |
| 4789 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4790 | break; |
| 4791 | } |
| 4792 | |
| 4793 | case Primitive::kPrimShort: |
| 4794 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4795 | if (value.IsConstant()) { |
| 4796 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4797 | __ movw(Address(base, offset), Immediate(v)); |
| 4798 | } else { |
| 4799 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4800 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4801 | break; |
| 4802 | } |
| 4803 | |
| 4804 | case Primitive::kPrimInt: |
| 4805 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4806 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4807 | // Note that in the case where `value` is a null reference, |
| 4808 | // we do not enter this block, as the reference does not |
| 4809 | // need poisoning. |
| 4810 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4811 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4812 | __ movl(temp, value.AsRegister<Register>()); |
| 4813 | __ PoisonHeapReference(temp); |
| 4814 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4815 | } else if (value.IsConstant()) { |
| 4816 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4817 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4818 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4819 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4820 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4821 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4822 | break; |
| 4823 | } |
| 4824 | |
| 4825 | case Primitive::kPrimLong: { |
| 4826 | if (is_volatile) { |
| 4827 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4828 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4829 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4830 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4831 | __ punpckldq(temp1, temp2); |
| 4832 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4833 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4834 | } else if (value.IsConstant()) { |
| 4835 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4836 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4837 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4838 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | } else { |
| 4840 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4841 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4842 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4843 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4844 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4845 | break; |
| 4846 | } |
| 4847 | |
| 4848 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4849 | if (value.IsConstant()) { |
| 4850 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4851 | __ movl(Address(base, offset), Immediate(v)); |
| 4852 | } else { |
| 4853 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4854 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4855 | break; |
| 4856 | } |
| 4857 | |
| 4858 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4859 | if (value.IsConstant()) { |
| 4860 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4861 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4862 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4863 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4864 | maybe_record_implicit_null_check_done = true; |
| 4865 | } else { |
| 4866 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4867 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4868 | break; |
| 4869 | } |
| 4870 | |
| 4871 | case Primitive::kPrimVoid: |
| 4872 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4873 | UNREACHABLE(); |
| 4874 | } |
| 4875 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4876 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4877 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4878 | } |
| 4879 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4880 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4881 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4882 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4883 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4886 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4887 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4892 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4893 | } |
| 4894 | |
| 4895 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4896 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4897 | } |
| 4898 | |
| 4899 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4900 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4901 | } |
| 4902 | |
| 4903 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4904 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4908 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4909 | } |
| 4910 | |
| 4911 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4912 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4916 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4917 | } |
| 4918 | |
| 4919 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4920 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4921 | } |
| 4922 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4923 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4924 | HUnresolvedInstanceFieldGet* instruction) { |
| 4925 | FieldAccessCallingConventionX86 calling_convention; |
| 4926 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4927 | instruction, instruction->GetFieldType(), calling_convention); |
| 4928 | } |
| 4929 | |
| 4930 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4931 | HUnresolvedInstanceFieldGet* instruction) { |
| 4932 | FieldAccessCallingConventionX86 calling_convention; |
| 4933 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4934 | instruction->GetFieldType(), |
| 4935 | instruction->GetFieldIndex(), |
| 4936 | instruction->GetDexPc(), |
| 4937 | calling_convention); |
| 4938 | } |
| 4939 | |
| 4940 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4941 | HUnresolvedInstanceFieldSet* instruction) { |
| 4942 | FieldAccessCallingConventionX86 calling_convention; |
| 4943 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4944 | instruction, instruction->GetFieldType(), calling_convention); |
| 4945 | } |
| 4946 | |
| 4947 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4948 | HUnresolvedInstanceFieldSet* 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::VisitUnresolvedStaticFieldGet( |
| 4958 | HUnresolvedStaticFieldGet* instruction) { |
| 4959 | FieldAccessCallingConventionX86 calling_convention; |
| 4960 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4961 | instruction, instruction->GetFieldType(), calling_convention); |
| 4962 | } |
| 4963 | |
| 4964 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4965 | HUnresolvedStaticFieldGet* 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::VisitUnresolvedStaticFieldSet( |
| 4975 | HUnresolvedStaticFieldSet* instruction) { |
| 4976 | FieldAccessCallingConventionX86 calling_convention; |
| 4977 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4978 | instruction, instruction->GetFieldType(), calling_convention); |
| 4979 | } |
| 4980 | |
| 4981 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4982 | HUnresolvedStaticFieldSet* instruction) { |
| 4983 | FieldAccessCallingConventionX86 calling_convention; |
| 4984 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4985 | instruction->GetFieldType(), |
| 4986 | instruction->GetFieldIndex(), |
| 4987 | instruction->GetDexPc(), |
| 4988 | calling_convention); |
| 4989 | } |
| 4990 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4991 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4992 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4993 | ? LocationSummary::kCallOnSlowPath |
| 4994 | : LocationSummary::kNoCall; |
| 4995 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4996 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4997 | ? Location::RequiresRegister() |
| 4998 | : Location::Any(); |
| 4999 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5000 | if (instruction->HasUses()) { |
| 5001 | locations->SetOut(Location::SameAsFirstInput()); |
| 5002 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5003 | } |
| 5004 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5005 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 5006 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5007 | return; |
| 5008 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5009 | LocationSummary* locations = instruction->GetLocations(); |
| 5010 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5011 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5012 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5013 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5016 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5017 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5018 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5019 | |
| 5020 | LocationSummary* locations = instruction->GetLocations(); |
| 5021 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5022 | |
| 5023 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5024 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5025 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5026 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5027 | } else { |
| 5028 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5029 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5030 | __ jmp(slow_path->GetEntryLabel()); |
| 5031 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5032 | } |
| 5033 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5034 | } |
| 5035 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5036 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5037 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5040 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5041 | bool object_array_get_with_read_barrier = |
| 5042 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5043 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5044 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5045 | object_array_get_with_read_barrier ? |
| 5046 | LocationSummary::kCallOnSlowPath : |
| 5047 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5048 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5049 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5050 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5051 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5052 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5053 | // The output overlaps in case of long: we don't want the low move |
| 5054 | // to overwrite the array's location. Likewise, in the case of an |
| 5055 | // object array get with read barriers enabled, we do not want the |
| 5056 | // move to overwrite the array's location, as we need it to emit |
| 5057 | // the read barrier. |
| 5058 | locations->SetOut( |
| 5059 | Location::RequiresRegister(), |
| 5060 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5061 | Location::kOutputOverlap : |
| 5062 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5063 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5064 | // We need a temporary register for the read barrier marking slow |
| 5065 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5066 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5067 | locations->AddTemp(Location::RequiresRegister()); |
| 5068 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5072 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5073 | Location obj_loc = locations->InAt(0); |
| 5074 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5075 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5076 | Location out_loc = locations->Out(); |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5077 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5078 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5079 | Primitive::Type type = instruction->GetType(); |
| 5080 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5081 | case Primitive::kPrimBoolean: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5082 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5083 | if (index.IsConstant()) { |
| 5084 | __ movzxb(out, Address(obj, |
| 5085 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5086 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5087 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5088 | } |
| 5089 | break; |
| 5090 | } |
| 5091 | |
| 5092 | case Primitive::kPrimByte: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5093 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5094 | if (index.IsConstant()) { |
| 5095 | __ movsxb(out, Address(obj, |
| 5096 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5097 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5098 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5099 | } |
| 5100 | break; |
| 5101 | } |
| 5102 | |
| 5103 | case Primitive::kPrimShort: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5104 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5105 | if (index.IsConstant()) { |
| 5106 | __ movsxw(out, Address(obj, |
| 5107 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5108 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5109 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5110 | } |
| 5111 | break; |
| 5112 | } |
| 5113 | |
| 5114 | case Primitive::kPrimChar: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5115 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5116 | if (index.IsConstant()) { |
| 5117 | __ movzxw(out, Address(obj, |
| 5118 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5119 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5120 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5121 | } |
| 5122 | break; |
| 5123 | } |
| 5124 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5125 | case Primitive::kPrimInt: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5126 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | if (index.IsConstant()) { |
| 5128 | __ movl(out, Address(obj, |
| 5129 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5130 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5131 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | } |
| 5133 | break; |
| 5134 | } |
| 5135 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5136 | case Primitive::kPrimNot: { |
| 5137 | static_assert( |
| 5138 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5139 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5140 | // /* HeapReference<Object> */ out = |
| 5141 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5142 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5143 | Location temp = locations->GetTemp(0); |
| 5144 | // Note that a potential implicit null check is handled in this |
| 5145 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5146 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5147 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5148 | } else { |
| 5149 | Register out = out_loc.AsRegister<Register>(); |
| 5150 | if (index.IsConstant()) { |
| 5151 | uint32_t offset = |
| 5152 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5153 | __ movl(out, Address(obj, offset)); |
| 5154 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5155 | // If read barriers are enabled, emit read barriers other than |
| 5156 | // Baker's using a slow path (and also unpoison the loaded |
| 5157 | // reference, if heap poisoning is enabled). |
| 5158 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5159 | } else { |
| 5160 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5161 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5162 | // If read barriers are enabled, emit read barriers other than |
| 5163 | // Baker's using a slow path (and also unpoison the loaded |
| 5164 | // reference, if heap poisoning is enabled). |
| 5165 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5166 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5167 | } |
| 5168 | } |
| 5169 | break; |
| 5170 | } |
| 5171 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5172 | case Primitive::kPrimLong: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5173 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5174 | if (index.IsConstant()) { |
| 5175 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5176 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5177 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5178 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5179 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5180 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5181 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5182 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5183 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5184 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5185 | } |
| 5186 | break; |
| 5187 | } |
| 5188 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5189 | case Primitive::kPrimFloat: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5190 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5191 | if (index.IsConstant()) { |
| 5192 | __ movss(out, Address(obj, |
| 5193 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5194 | } else { |
| 5195 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5196 | } |
| 5197 | break; |
| 5198 | } |
| 5199 | |
| 5200 | case Primitive::kPrimDouble: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5201 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5202 | if (index.IsConstant()) { |
| 5203 | __ movsd(out, Address(obj, |
| 5204 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5205 | } else { |
| 5206 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5207 | } |
| 5208 | break; |
| 5209 | } |
| 5210 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5211 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5212 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5213 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5214 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5215 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5216 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5217 | // Potential implicit null checks, in the case of reference or |
| 5218 | // long arrays, are handled in the previous switch statement. |
| 5219 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5220 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5221 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5225 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5226 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5227 | bool needs_write_barrier = |
| 5228 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5229 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5230 | bool object_array_set_with_read_barrier = |
| 5231 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5232 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5233 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5234 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5235 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5236 | LocationSummary::kCallOnSlowPath : |
| 5237 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5238 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5239 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5240 | || (value_type == Primitive::kPrimByte); |
| 5241 | // We need the inputs to be different than the output in case of long operation. |
| 5242 | // In case of a byte operation, the register allocator does not support multiple |
| 5243 | // inputs that die at entry with one in a specific register. |
| 5244 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5245 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5246 | if (is_byte_type) { |
| 5247 | // Ensure the value is in a byte register. |
| 5248 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5249 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5250 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5251 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5252 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5253 | } |
| 5254 | if (needs_write_barrier) { |
| 5255 | // Temporary registers for the write barrier. |
| 5256 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5257 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5258 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5263 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5264 | Location array_loc = locations->InAt(0); |
| 5265 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5266 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5267 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5268 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5270 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5271 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5272 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5273 | bool needs_write_barrier = |
| 5274 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5275 | |
| 5276 | switch (value_type) { |
| 5277 | case Primitive::kPrimBoolean: |
| 5278 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5279 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5280 | Address address = index.IsConstant() |
| 5281 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5282 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5283 | if (value.IsRegister()) { |
| 5284 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5285 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5286 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5287 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5288 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5289 | break; |
| 5290 | } |
| 5291 | |
| 5292 | case Primitive::kPrimShort: |
| 5293 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5294 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5295 | Address address = index.IsConstant() |
| 5296 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5297 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5298 | if (value.IsRegister()) { |
| 5299 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5300 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5301 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5304 | break; |
| 5305 | } |
| 5306 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5307 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5308 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5309 | Address address = index.IsConstant() |
| 5310 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5311 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5312 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5313 | if (!value.IsRegister()) { |
| 5314 | // Just setting null. |
| 5315 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5316 | DCHECK(value.IsConstant()) << value; |
| 5317 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5318 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5319 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5320 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5321 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5322 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5323 | |
| 5324 | DCHECK(needs_write_barrier); |
| 5325 | Register register_value = value.AsRegister<Register>(); |
| 5326 | NearLabel done, not_null, do_put; |
| 5327 | SlowPathCode* slow_path = nullptr; |
| 5328 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5329 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5330 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5331 | codegen_->AddSlowPath(slow_path); |
| 5332 | if (instruction->GetValueCanBeNull()) { |
| 5333 | __ testl(register_value, register_value); |
| 5334 | __ j(kNotEqual, ¬_null); |
| 5335 | __ movl(address, Immediate(0)); |
| 5336 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5337 | __ jmp(&done); |
| 5338 | __ Bind(¬_null); |
| 5339 | } |
| 5340 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5341 | if (kEmitCompilerReadBarrier) { |
| 5342 | // When read barriers are enabled, the type checking |
| 5343 | // instrumentation requires two read barriers: |
| 5344 | // |
| 5345 | // __ movl(temp2, temp); |
| 5346 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5347 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5348 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5349 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5350 | // |
| 5351 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5352 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5353 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5354 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5355 | // |
| 5356 | // __ cmpl(temp, temp2); |
| 5357 | // |
| 5358 | // However, the second read barrier may trash `temp`, as it |
| 5359 | // is a temporary register, and as such would not be saved |
| 5360 | // along with live registers before calling the runtime (nor |
| 5361 | // restored afterwards). So in this case, we bail out and |
| 5362 | // delegate the work to the array set slow path. |
| 5363 | // |
| 5364 | // TODO: Extend the register allocator to support a new |
| 5365 | // "(locally) live temp" location so as to avoid always |
| 5366 | // going into the slow path when read barriers are enabled. |
| 5367 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5368 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5369 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5370 | __ movl(temp, Address(array, class_offset)); |
| 5371 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5372 | __ MaybeUnpoisonHeapReference(temp); |
| 5373 | |
| 5374 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5375 | __ movl(temp, Address(temp, component_offset)); |
| 5376 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5377 | // nor the object reference in `register_value->klass`, as |
| 5378 | // we are comparing two poisoned references. |
| 5379 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5380 | |
| 5381 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5382 | __ j(kEqual, &do_put); |
| 5383 | // If heap poisoning is enabled, the `temp` reference has |
| 5384 | // not been unpoisoned yet; unpoison it now. |
| 5385 | __ MaybeUnpoisonHeapReference(temp); |
| 5386 | |
| 5387 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5388 | __ movl(temp, Address(temp, super_offset)); |
| 5389 | // If heap poisoning is enabled, no need to unpoison |
| 5390 | // `temp`, as we are comparing against null below. |
| 5391 | __ testl(temp, temp); |
| 5392 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5393 | __ Bind(&do_put); |
| 5394 | } else { |
| 5395 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5396 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | if (kPoisonHeapReferences) { |
| 5401 | __ movl(temp, register_value); |
| 5402 | __ PoisonHeapReference(temp); |
| 5403 | __ movl(address, temp); |
| 5404 | } else { |
| 5405 | __ movl(address, register_value); |
| 5406 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5407 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5408 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5409 | } |
| 5410 | |
| 5411 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5412 | codegen_->MarkGCCard( |
| 5413 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5414 | __ Bind(&done); |
| 5415 | |
| 5416 | if (slow_path != nullptr) { |
| 5417 | __ Bind(slow_path->GetExitLabel()); |
| 5418 | } |
| 5419 | |
| 5420 | break; |
| 5421 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5422 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5423 | case Primitive::kPrimInt: { |
| 5424 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5425 | Address address = index.IsConstant() |
| 5426 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5427 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5428 | if (value.IsRegister()) { |
| 5429 | __ movl(address, value.AsRegister<Register>()); |
| 5430 | } else { |
| 5431 | DCHECK(value.IsConstant()) << value; |
| 5432 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5433 | __ movl(address, Immediate(v)); |
| 5434 | } |
| 5435 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5439 | case Primitive::kPrimLong: { |
| 5440 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5441 | if (index.IsConstant()) { |
| 5442 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5443 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5444 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5445 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5446 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5447 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5448 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5449 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5450 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5451 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5452 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5453 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5454 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5455 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5456 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5457 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5458 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5459 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5460 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5461 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5462 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5463 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5464 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5465 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5466 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5467 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5468 | Immediate(High32Bits(val))); |
| 5469 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5470 | } |
| 5471 | break; |
| 5472 | } |
| 5473 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5474 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5475 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5476 | Address address = index.IsConstant() |
| 5477 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5478 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5479 | if (value.IsFpuRegister()) { |
| 5480 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5481 | } else { |
| 5482 | DCHECK(value.IsConstant()); |
| 5483 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5484 | __ movl(address, Immediate(v)); |
| 5485 | } |
| 5486 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5487 | break; |
| 5488 | } |
| 5489 | |
| 5490 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5491 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5492 | Address address = index.IsConstant() |
| 5493 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5494 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5495 | if (value.IsFpuRegister()) { |
| 5496 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5497 | } else { |
| 5498 | DCHECK(value.IsConstant()); |
| 5499 | Address address_hi = index.IsConstant() ? |
| 5500 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5501 | offset + kX86WordSize) : |
| 5502 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5503 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5504 | __ movl(address, Immediate(Low32Bits(v))); |
| 5505 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5506 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5507 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5508 | break; |
| 5509 | } |
| 5510 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5511 | case Primitive::kPrimVoid: |
| 5512 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5513 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5518 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5520 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5524 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5525 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5526 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5527 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5528 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5529 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5533 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5534 | ? LocationSummary::kCallOnSlowPath |
| 5535 | : LocationSummary::kNoCall; |
| 5536 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5537 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5538 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5539 | if (instruction->HasUses()) { |
| 5540 | locations->SetOut(Location::SameAsFirstInput()); |
| 5541 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5545 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5546 | Location index_loc = locations->InAt(0); |
| 5547 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5548 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5549 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5550 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5551 | if (length_loc.IsConstant()) { |
| 5552 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5553 | if (index_loc.IsConstant()) { |
| 5554 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5555 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5556 | if (index < 0 || index >= length) { |
| 5557 | codegen_->AddSlowPath(slow_path); |
| 5558 | __ jmp(slow_path->GetEntryLabel()); |
| 5559 | } else { |
| 5560 | // Some optimization after BCE may have generated this, and we should not |
| 5561 | // generate a bounds check if it is a valid range. |
| 5562 | } |
| 5563 | return; |
| 5564 | } |
| 5565 | |
| 5566 | // We have to reverse the jump condition because the length is the constant. |
| 5567 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5568 | __ cmpl(index_reg, Immediate(length)); |
| 5569 | codegen_->AddSlowPath(slow_path); |
| 5570 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5571 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5572 | Register length = length_loc.AsRegister<Register>(); |
| 5573 | if (index_loc.IsConstant()) { |
| 5574 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5575 | __ cmpl(length, Immediate(value)); |
| 5576 | } else { |
| 5577 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5578 | } |
| 5579 | codegen_->AddSlowPath(slow_path); |
| 5580 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5581 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5582 | } |
| 5583 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5584 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5585 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5589 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5590 | } |
| 5591 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5592 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5593 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5594 | } |
| 5595 | |
| 5596 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5597 | HBasicBlock* block = instruction->GetBlock(); |
| 5598 | if (block->GetLoopInformation() != nullptr) { |
| 5599 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5600 | // The back edge will generate the suspend check. |
| 5601 | return; |
| 5602 | } |
| 5603 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5604 | // The goto will generate the suspend check. |
| 5605 | return; |
| 5606 | } |
| 5607 | GenerateSuspendCheck(instruction, nullptr); |
| 5608 | } |
| 5609 | |
| 5610 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5611 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5612 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5613 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5614 | if (slow_path == nullptr) { |
| 5615 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5616 | instruction->SetSlowPath(slow_path); |
| 5617 | codegen_->AddSlowPath(slow_path); |
| 5618 | if (successor != nullptr) { |
| 5619 | DCHECK(successor->IsLoopHeader()); |
| 5620 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5621 | } |
| 5622 | } else { |
| 5623 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5624 | } |
| 5625 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5626 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5627 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5628 | if (successor == nullptr) { |
| 5629 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5630 | __ Bind(slow_path->GetReturnLabel()); |
| 5631 | } else { |
| 5632 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5633 | __ jmp(slow_path->GetEntryLabel()); |
| 5634 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5635 | } |
| 5636 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5637 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5638 | return codegen_->GetAssembler(); |
| 5639 | } |
| 5640 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5641 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5642 | ScratchRegisterScope ensure_scratch( |
| 5643 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5644 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5645 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5646 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5647 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5648 | } |
| 5649 | |
| 5650 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5651 | ScratchRegisterScope ensure_scratch( |
| 5652 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5653 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5654 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5655 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5656 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5657 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5658 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5662 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5663 | Location source = move->GetSource(); |
| 5664 | Location destination = move->GetDestination(); |
| 5665 | |
| 5666 | if (source.IsRegister()) { |
| 5667 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5668 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5669 | } else if (destination.IsFpuRegister()) { |
| 5670 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5671 | } else { |
| 5672 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5673 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5674 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5675 | } else if (source.IsRegisterPair()) { |
| 5676 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5677 | // Create stack space for 2 elements. |
| 5678 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5679 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5680 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5681 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5682 | // And remove the temporary stack space we allocated. |
| 5683 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5684 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5685 | if (destination.IsRegister()) { |
| 5686 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5687 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5688 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5689 | } else if (destination.IsRegisterPair()) { |
| 5690 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5691 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5692 | __ psrlq(src_reg, Immediate(32)); |
| 5693 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5694 | } else if (destination.IsStackSlot()) { |
| 5695 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5696 | } else { |
| 5697 | DCHECK(destination.IsDoubleStackSlot()); |
| 5698 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5699 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5700 | } else if (source.IsStackSlot()) { |
| 5701 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5702 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5703 | } else if (destination.IsFpuRegister()) { |
| 5704 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5705 | } else { |
| 5706 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5707 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5708 | } |
| 5709 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5710 | if (destination.IsRegisterPair()) { |
| 5711 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5712 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5713 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5714 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5715 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5716 | } else { |
| 5717 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5718 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5719 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5720 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5721 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5722 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5723 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5724 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5725 | if (value == 0) { |
| 5726 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5727 | } else { |
| 5728 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5729 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5730 | } else { |
| 5731 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5732 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5733 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5734 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5735 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5736 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5737 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5738 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5739 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5740 | if (value == 0) { |
| 5741 | // Easy handling of 0.0. |
| 5742 | __ xorps(dest, dest); |
| 5743 | } else { |
| 5744 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5745 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5746 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5747 | __ movl(temp, Immediate(value)); |
| 5748 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5749 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5750 | } else { |
| 5751 | DCHECK(destination.IsStackSlot()) << destination; |
| 5752 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5753 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5754 | } else if (constant->IsLongConstant()) { |
| 5755 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5756 | int32_t low_value = Low32Bits(value); |
| 5757 | int32_t high_value = High32Bits(value); |
| 5758 | Immediate low(low_value); |
| 5759 | Immediate high(high_value); |
| 5760 | if (destination.IsDoubleStackSlot()) { |
| 5761 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5762 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5763 | } else { |
| 5764 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5765 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5766 | } |
| 5767 | } else { |
| 5768 | DCHECK(constant->IsDoubleConstant()); |
| 5769 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5770 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5771 | int32_t low_value = Low32Bits(value); |
| 5772 | int32_t high_value = High32Bits(value); |
| 5773 | Immediate low(low_value); |
| 5774 | Immediate high(high_value); |
| 5775 | if (destination.IsFpuRegister()) { |
| 5776 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5777 | if (value == 0) { |
| 5778 | // Easy handling of 0.0. |
| 5779 | __ xorpd(dest, dest); |
| 5780 | } else { |
| 5781 | __ pushl(high); |
| 5782 | __ pushl(low); |
| 5783 | __ movsd(dest, Address(ESP, 0)); |
| 5784 | __ addl(ESP, Immediate(8)); |
| 5785 | } |
| 5786 | } else { |
| 5787 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5788 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5789 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5790 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5791 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5792 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5793 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5794 | } |
| 5795 | } |
| 5796 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5797 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5798 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5799 | ScratchRegisterScope ensure_scratch( |
| 5800 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5801 | |
| 5802 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5803 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5804 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5805 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5806 | } |
| 5807 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5808 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5809 | ScratchRegisterScope ensure_scratch( |
| 5810 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5811 | |
| 5812 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5813 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5814 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5815 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5816 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5817 | } |
| 5818 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5819 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5820 | ScratchRegisterScope ensure_scratch1( |
| 5821 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5822 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5823 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5824 | ScratchRegisterScope ensure_scratch2( |
| 5825 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5826 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5827 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5828 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5829 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5830 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5831 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5832 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5836 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5837 | Location source = move->GetSource(); |
| 5838 | Location destination = move->GetDestination(); |
| 5839 | |
| 5840 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5841 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5842 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5843 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5844 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5845 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5846 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5847 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5848 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5849 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5850 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5851 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5852 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5853 | // Use XOR Swap algorithm to avoid a temporary. |
| 5854 | DCHECK_NE(source.reg(), destination.reg()); |
| 5855 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5856 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5857 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5858 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5859 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5860 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5861 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5862 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5863 | // Take advantage of the 16 bytes in the XMM register. |
| 5864 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5865 | Address stack(ESP, destination.GetStackIndex()); |
| 5866 | // Load the double into the high doubleword. |
| 5867 | __ movhpd(reg, stack); |
| 5868 | |
| 5869 | // Store the low double into the destination. |
| 5870 | __ movsd(stack, reg); |
| 5871 | |
| 5872 | // Move the high double to the low double. |
| 5873 | __ psrldq(reg, Immediate(8)); |
| 5874 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5875 | // Take advantage of the 16 bytes in the XMM register. |
| 5876 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5877 | Address stack(ESP, source.GetStackIndex()); |
| 5878 | // Load the double into the high doubleword. |
| 5879 | __ movhpd(reg, stack); |
| 5880 | |
| 5881 | // Store the low double into the destination. |
| 5882 | __ movsd(stack, reg); |
| 5883 | |
| 5884 | // Move the high double to the low double. |
| 5885 | __ psrldq(reg, Immediate(8)); |
| 5886 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5887 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5888 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5889 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5890 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | |
| 5894 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5895 | __ pushl(static_cast<Register>(reg)); |
| 5896 | } |
| 5897 | |
| 5898 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5899 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5900 | } |
| 5901 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5902 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( |
| 5903 | HLoadClass::LoadKind desired_class_load_kind) { |
| 5904 | if (kEmitCompilerReadBarrier) { |
| 5905 | switch (desired_class_load_kind) { |
| 5906 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5907 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5908 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5909 | // TODO: Implement for read barrier. |
| 5910 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5911 | default: |
| 5912 | break; |
| 5913 | } |
| 5914 | } |
| 5915 | switch (desired_class_load_kind) { |
| 5916 | case HLoadClass::LoadKind::kReferrersClass: |
| 5917 | break; |
| 5918 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: |
| 5919 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5920 | break; |
| 5921 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: |
| 5922 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5923 | FALLTHROUGH_INTENDED; |
| 5924 | case HLoadClass::LoadKind::kDexCachePcRelative: |
| 5925 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
| 5926 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5927 | // is incompatible with it. |
| 5928 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5929 | // with irreducible loops. |
| 5930 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5931 | return HLoadClass::LoadKind::kDexCacheViaMethod; |
| 5932 | } |
| 5933 | break; |
| 5934 | case HLoadClass::LoadKind::kBootImageAddress: |
| 5935 | break; |
| 5936 | case HLoadClass::LoadKind::kDexCacheAddress: |
| 5937 | DCHECK(Runtime::Current()->UseJitCompilation()); |
| 5938 | break; |
| 5939 | case HLoadClass::LoadKind::kDexCacheViaMethod: |
| 5940 | break; |
| 5941 | } |
| 5942 | return desired_class_load_kind; |
| 5943 | } |
| 5944 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5945 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5946 | if (cls->NeedsAccessCheck()) { |
| 5947 | InvokeRuntimeCallingConvention calling_convention; |
| 5948 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5949 | cls, |
| 5950 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 5951 | Location::RegisterLocation(EAX), |
| 5952 | /* code_generator_supports_read_barrier */ true); |
| 5953 | return; |
| 5954 | } |
| 5955 | |
| 5956 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier) |
| 5957 | ? LocationSummary::kCallOnSlowPath |
| 5958 | : LocationSummary::kNoCall; |
| 5959 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
| 5960 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); |
| 5961 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || |
| 5962 | load_kind == HLoadClass::LoadKind::kDexCacheViaMethod || |
| 5963 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || |
| 5964 | load_kind == HLoadClass::LoadKind::kDexCachePcRelative) { |
| 5965 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5966 | } |
| 5967 | locations->SetOut(Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5971 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5972 | if (cls->NeedsAccessCheck()) { |
| 5973 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5974 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5975 | cls, |
| 5976 | cls->GetDexPc(), |
| 5977 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5978 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5979 | return; |
| 5980 | } |
| 5981 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5982 | Location out_loc = locations->Out(); |
| 5983 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5984 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 5985 | bool generate_null_check = false; |
| 5986 | switch (cls->GetLoadKind()) { |
| 5987 | case HLoadClass::LoadKind::kReferrersClass: { |
| 5988 | DCHECK(!cls->CanCallRuntime()); |
| 5989 | DCHECK(!cls->MustGenerateClinitCheck()); |
| 5990 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5991 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 5992 | GenerateGcRootFieldLoad( |
| 5993 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 5994 | break; |
| 5995 | } |
| 5996 | case HLoadClass::LoadKind::kBootImageLinkTimeAddress: { |
| 5997 | DCHECK(!kEmitCompilerReadBarrier); |
| 5998 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 5999 | codegen_->RecordTypePatch(cls); |
| 6000 | break; |
| 6001 | } |
| 6002 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { |
| 6003 | DCHECK(!kEmitCompilerReadBarrier); |
| 6004 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6005 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6006 | codegen_->RecordTypePatch(cls); |
| 6007 | break; |
| 6008 | } |
| 6009 | case HLoadClass::LoadKind::kBootImageAddress: { |
| 6010 | DCHECK(!kEmitCompilerReadBarrier); |
| 6011 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6012 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6013 | __ movl(out, Immediate(address)); |
| 6014 | codegen_->RecordSimplePatch(); |
| 6015 | break; |
| 6016 | } |
| 6017 | case HLoadClass::LoadKind::kDexCacheAddress: { |
| 6018 | DCHECK_NE(cls->GetAddress(), 0u); |
| 6019 | uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress()); |
| 6020 | // /* GcRoot<mirror::Class> */ out = *address |
| 6021 | GenerateGcRootFieldLoad(cls, out_loc, Address::Absolute(address)); |
| 6022 | generate_null_check = !cls->IsInDexCache(); |
| 6023 | break; |
| 6024 | } |
| 6025 | case HLoadClass::LoadKind::kDexCachePcRelative: { |
| 6026 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6027 | uint32_t offset = cls->GetDexCacheElementOffset(); |
| 6028 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(cls->GetDexFile(), offset); |
| 6029 | // /* GcRoot<mirror::Class> */ out = *(base + offset) /* PC-relative */ |
| 6030 | GenerateGcRootFieldLoad( |
| 6031 | cls, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6032 | generate_null_check = !cls->IsInDexCache(); |
| 6033 | break; |
| 6034 | } |
| 6035 | case HLoadClass::LoadKind::kDexCacheViaMethod: { |
| 6036 | // /* GcRoot<mirror::Class>[] */ out = |
| 6037 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 6038 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6039 | __ movl(out, Address(current_method, |
| 6040 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 6041 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 6042 | GenerateGcRootFieldLoad( |
| 6043 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
| 6044 | generate_null_check = !cls->IsInDexCache(); |
| 6045 | break; |
| 6046 | } |
| 6047 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6048 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6049 | if (generate_null_check || cls->MustGenerateClinitCheck()) { |
| 6050 | DCHECK(cls->CanCallRuntime()); |
| 6051 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 6052 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 6053 | codegen_->AddSlowPath(slow_path); |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6054 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6055 | if (generate_null_check) { |
| 6056 | __ testl(out, out); |
| 6057 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6058 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6059 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6060 | if (cls->MustGenerateClinitCheck()) { |
| 6061 | GenerateClassInitializationCheck(slow_path, out); |
| 6062 | } else { |
| 6063 | __ Bind(slow_path->GetExitLabel()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6064 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
| 6068 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 6069 | LocationSummary* locations = |
| 6070 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 6071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6072 | if (check->HasUses()) { |
| 6073 | locations->SetOut(Location::SameAsFirstInput()); |
| 6074 | } |
| 6075 | } |
| 6076 | |
| 6077 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6078 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6079 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6080 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6081 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6082 | GenerateClassInitializationCheck(slow_path, |
| 6083 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6084 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6085 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6086 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6087 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6088 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 6089 | Immediate(mirror::Class::kStatusInitialized)); |
| 6090 | __ j(kLess, slow_path->GetEntryLabel()); |
| 6091 | __ Bind(slow_path->GetExitLabel()); |
| 6092 | // No need for memory fence, thanks to the X86 memory model. |
| 6093 | } |
| 6094 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6095 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 6096 | HLoadString::LoadKind desired_string_load_kind) { |
| 6097 | if (kEmitCompilerReadBarrier) { |
| 6098 | switch (desired_string_load_kind) { |
| 6099 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6100 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6101 | case HLoadString::LoadKind::kBootImageAddress: |
| 6102 | // TODO: Implement for read barrier. |
| 6103 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6104 | default: |
| 6105 | break; |
| 6106 | } |
| 6107 | } |
| 6108 | switch (desired_string_load_kind) { |
| 6109 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 6110 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 6111 | break; |
| 6112 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 6113 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 6114 | FALLTHROUGH_INTENDED; |
| 6115 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6116 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6117 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 6118 | // is incompatible with it. |
| 6119 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 6120 | // with irreducible loops. |
| 6121 | if (GetGraph()->HasIrreducibleLoops()) { |
| 6122 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 6123 | } |
| 6124 | break; |
| 6125 | case HLoadString::LoadKind::kBootImageAddress: |
| 6126 | break; |
| 6127 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 6128 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6129 | break; |
| 6130 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 6131 | break; |
| 6132 | } |
| 6133 | return desired_string_load_kind; |
| 6134 | } |
| 6135 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6136 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6137 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6138 | ? LocationSummary::kCallOnSlowPath |
| 6139 | : LocationSummary::kNoCall; |
| 6140 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6141 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6142 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 6143 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 6144 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 6145 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6146 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6147 | locations->SetOut(Location::RequiresRegister()); |
| 6148 | } |
| 6149 | |
| 6150 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6151 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6152 | Location out_loc = locations->Out(); |
| 6153 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6154 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6155 | switch (load->GetLoadKind()) { |
| 6156 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6157 | DCHECK(!kEmitCompilerReadBarrier); |
| 6158 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6159 | codegen_->RecordStringPatch(load); |
| 6160 | return; // No dex cache slow path. |
| 6161 | } |
| 6162 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6163 | DCHECK(!kEmitCompilerReadBarrier); |
| 6164 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6165 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6166 | codegen_->RecordStringPatch(load); |
| 6167 | return; // No dex cache slow path. |
| 6168 | } |
| 6169 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6170 | DCHECK(!kEmitCompilerReadBarrier); |
| 6171 | DCHECK_NE(load->GetAddress(), 0u); |
| 6172 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6173 | __ movl(out, Immediate(address)); |
| 6174 | codegen_->RecordSimplePatch(); |
| 6175 | return; // No dex cache slow path. |
| 6176 | } |
| 6177 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 6178 | DCHECK_NE(load->GetAddress(), 0u); |
| 6179 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6180 | // /* GcRoot<mirror::String> */ out = *address |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6181 | GenerateGcRootFieldLoad(load, out_loc, Address::Absolute(address)); |
| 6182 | break; |
| 6183 | } |
| 6184 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 6185 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6186 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 6187 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6188 | // /* GcRoot<mirror::String> */ out = *(base + offset) /* PC-relative */ |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6189 | GenerateGcRootFieldLoad( |
| 6190 | load, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6191 | break; |
| 6192 | } |
| 6193 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 6194 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6195 | |
| 6196 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6197 | GenerateGcRootFieldLoad( |
| 6198 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6199 | |
| 6200 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 6201 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
| 6202 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 6203 | GenerateGcRootFieldLoad( |
| 6204 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 6205 | break; |
| 6206 | } |
| 6207 | default: |
| 6208 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 6209 | UNREACHABLE(); |
| 6210 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6212 | if (!load->IsInDexCache()) { |
| 6213 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6214 | codegen_->AddSlowPath(slow_path); |
| 6215 | __ testl(out, out); |
| 6216 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6217 | __ Bind(slow_path->GetExitLabel()); |
| 6218 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6219 | } |
| 6220 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6221 | static Address GetExceptionTlsAddress() { |
| 6222 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6223 | } |
| 6224 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6225 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6226 | LocationSummary* locations = |
| 6227 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6228 | locations->SetOut(Location::RequiresRegister()); |
| 6229 | } |
| 6230 | |
| 6231 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6232 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6233 | } |
| 6234 | |
| 6235 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6236 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6237 | } |
| 6238 | |
| 6239 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6240 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6244 | LocationSummary* locations = |
| 6245 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6246 | InvokeRuntimeCallingConvention calling_convention; |
| 6247 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6248 | } |
| 6249 | |
| 6250 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6251 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6252 | instruction, |
| 6253 | instruction->GetDexPc(), |
| 6254 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6255 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6258 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6259 | return kEmitCompilerReadBarrier && |
| 6260 | (kUseBakerReadBarrier || |
| 6261 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6262 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6263 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6264 | } |
| 6265 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6266 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6267 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6268 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6269 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6270 | case TypeCheckKind::kExactCheck: |
| 6271 | case TypeCheckKind::kAbstractClassCheck: |
| 6272 | case TypeCheckKind::kClassHierarchyCheck: |
| 6273 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | call_kind = |
| 6275 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6276 | break; |
| 6277 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6278 | case TypeCheckKind::kUnresolvedCheck: |
| 6279 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6280 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6281 | break; |
| 6282 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6284 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6285 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6286 | locations->SetInAt(1, Location::Any()); |
| 6287 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6288 | locations->SetOut(Location::RequiresRegister()); |
| 6289 | // When read barriers are enabled, we need a temporary register for |
| 6290 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6291 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6292 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6293 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6294 | } |
| 6295 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6296 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6297 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6298 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6299 | Location obj_loc = locations->InAt(0); |
| 6300 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6301 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | Location out_loc = locations->Out(); |
| 6303 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6304 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6305 | locations->GetTemp(0) : |
| 6306 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6307 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6308 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6309 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6310 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6311 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6313 | |
| 6314 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6315 | // Avoid null check if we know obj is not null. |
| 6316 | if (instruction->MustDoNullCheck()) { |
| 6317 | __ testl(obj, obj); |
| 6318 | __ j(kEqual, &zero); |
| 6319 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6320 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6321 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6322 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6324 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6325 | case TypeCheckKind::kExactCheck: { |
| 6326 | if (cls.IsRegister()) { |
| 6327 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6328 | } else { |
| 6329 | DCHECK(cls.IsStackSlot()) << cls; |
| 6330 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6331 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6332 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6333 | // Classes must be equal for the instanceof to succeed. |
| 6334 | __ j(kNotEqual, &zero); |
| 6335 | __ movl(out, Immediate(1)); |
| 6336 | __ jmp(&done); |
| 6337 | break; |
| 6338 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6339 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6340 | case TypeCheckKind::kAbstractClassCheck: { |
| 6341 | // If the class is abstract, we eagerly fetch the super class of the |
| 6342 | // object to avoid doing a comparison we know will fail. |
| 6343 | NearLabel loop; |
| 6344 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6345 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6346 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6347 | __ testl(out, out); |
| 6348 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6349 | __ j(kEqual, &done); |
| 6350 | if (cls.IsRegister()) { |
| 6351 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6352 | } else { |
| 6353 | DCHECK(cls.IsStackSlot()) << cls; |
| 6354 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6355 | } |
| 6356 | __ j(kNotEqual, &loop); |
| 6357 | __ movl(out, Immediate(1)); |
| 6358 | if (zero.IsLinked()) { |
| 6359 | __ jmp(&done); |
| 6360 | } |
| 6361 | break; |
| 6362 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6364 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6365 | // Walk over the class hierarchy to find a match. |
| 6366 | NearLabel loop, success; |
| 6367 | __ Bind(&loop); |
| 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 | } |
| 6374 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6375 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6376 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6377 | __ testl(out, out); |
| 6378 | __ j(kNotEqual, &loop); |
| 6379 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6380 | __ jmp(&done); |
| 6381 | __ Bind(&success); |
| 6382 | __ movl(out, Immediate(1)); |
| 6383 | if (zero.IsLinked()) { |
| 6384 | __ jmp(&done); |
| 6385 | } |
| 6386 | break; |
| 6387 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6388 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6389 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6390 | // Do an exact check. |
| 6391 | NearLabel exact_check; |
| 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(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6399 | // 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] | 6400 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6401 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6402 | __ testl(out, out); |
| 6403 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6404 | __ j(kEqual, &done); |
| 6405 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6406 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6407 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6408 | __ movl(out, Immediate(1)); |
| 6409 | __ jmp(&done); |
| 6410 | break; |
| 6411 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6412 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6413 | case TypeCheckKind::kArrayCheck: { |
| 6414 | if (cls.IsRegister()) { |
| 6415 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6416 | } else { |
| 6417 | DCHECK(cls.IsStackSlot()) << cls; |
| 6418 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6419 | } |
| 6420 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6421 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6422 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6423 | codegen_->AddSlowPath(slow_path); |
| 6424 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6425 | __ movl(out, Immediate(1)); |
| 6426 | if (zero.IsLinked()) { |
| 6427 | __ jmp(&done); |
| 6428 | } |
| 6429 | break; |
| 6430 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6431 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6432 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6433 | case TypeCheckKind::kInterfaceCheck: { |
| 6434 | // 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] | 6435 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6436 | // cases. |
| 6437 | // |
| 6438 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6439 | // entry point without resorting to a type checking slow path |
| 6440 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6441 | // require to assign fixed registers for the inputs of this |
| 6442 | // HInstanceOf instruction (following the runtime calling |
| 6443 | // convention), which might be cluttered by the potential first |
| 6444 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6445 | // |
| 6446 | // TODO: Introduce a new runtime entry point taking the object |
| 6447 | // to test (instead of its class) as argument, and let it deal |
| 6448 | // with the read barrier issues. This will let us refactor this |
| 6449 | // case of the `switch` code as it was previously (with a direct |
| 6450 | // call to the runtime not using a type checking slow path). |
| 6451 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6452 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6453 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6454 | /* is_fatal */ false); |
| 6455 | codegen_->AddSlowPath(slow_path); |
| 6456 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6457 | if (zero.IsLinked()) { |
| 6458 | __ jmp(&done); |
| 6459 | } |
| 6460 | break; |
| 6461 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6462 | } |
| 6463 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6464 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6465 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6466 | __ xorl(out, out); |
| 6467 | } |
| 6468 | |
| 6469 | if (done.IsLinked()) { |
| 6470 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6471 | } |
| 6472 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6473 | if (slow_path != nullptr) { |
| 6474 | __ Bind(slow_path->GetExitLabel()); |
| 6475 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6476 | } |
| 6477 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6478 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6479 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6480 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6481 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6482 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6483 | case TypeCheckKind::kExactCheck: |
| 6484 | case TypeCheckKind::kAbstractClassCheck: |
| 6485 | case TypeCheckKind::kClassHierarchyCheck: |
| 6486 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6487 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6488 | LocationSummary::kCallOnSlowPath : |
| 6489 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6490 | break; |
| 6491 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6492 | case TypeCheckKind::kUnresolvedCheck: |
| 6493 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6494 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6495 | break; |
| 6496 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6497 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6498 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6499 | locations->SetInAt(1, Location::Any()); |
| 6500 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6501 | locations->AddTemp(Location::RequiresRegister()); |
| 6502 | // When read barriers are enabled, we need an additional temporary |
| 6503 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6504 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6505 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6506 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
| 6509 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6510 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6511 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6512 | Location obj_loc = locations->InAt(0); |
| 6513 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6514 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6515 | Location temp_loc = locations->GetTemp(0); |
| 6516 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6517 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6518 | locations->GetTemp(1) : |
| 6519 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6520 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6521 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6522 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6523 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6524 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6525 | bool is_type_check_slow_path_fatal = |
| 6526 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6527 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6528 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6529 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6530 | !instruction->CanThrowIntoCatchBlock(); |
| 6531 | SlowPathCode* type_check_slow_path = |
| 6532 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6533 | is_type_check_slow_path_fatal); |
| 6534 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6536 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6537 | // Avoid null check if we know obj is not null. |
| 6538 | if (instruction->MustDoNullCheck()) { |
| 6539 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6540 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6541 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6542 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6543 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6544 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6545 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6546 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6547 | case TypeCheckKind::kExactCheck: |
| 6548 | case TypeCheckKind::kArrayCheck: { |
| 6549 | if (cls.IsRegister()) { |
| 6550 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6551 | } else { |
| 6552 | DCHECK(cls.IsStackSlot()) << cls; |
| 6553 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6554 | } |
| 6555 | // Jump to slow path for throwing the exception or doing a |
| 6556 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6557 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6558 | break; |
| 6559 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6560 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6561 | case TypeCheckKind::kAbstractClassCheck: { |
| 6562 | // If the class is abstract, we eagerly fetch the super class of the |
| 6563 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6564 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6565 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6566 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6567 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6568 | |
| 6569 | // If the class reference currently in `temp` is not null, jump |
| 6570 | // to the `compare_classes` label to compare it with the checked |
| 6571 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6572 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6573 | __ j(kNotEqual, &compare_classes); |
| 6574 | // Otherwise, jump to the slow path to throw the exception. |
| 6575 | // |
| 6576 | // But before, move back the object's class into `temp` before |
| 6577 | // going into the slow path, as it has been overwritten in the |
| 6578 | // meantime. |
| 6579 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6580 | GenerateReferenceLoadTwoRegisters( |
| 6581 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6582 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6583 | |
| 6584 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6585 | if (cls.IsRegister()) { |
| 6586 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6587 | } else { |
| 6588 | DCHECK(cls.IsStackSlot()) << cls; |
| 6589 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6590 | } |
| 6591 | __ j(kNotEqual, &loop); |
| 6592 | break; |
| 6593 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6594 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6595 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6596 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6597 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6598 | __ Bind(&loop); |
| 6599 | if (cls.IsRegister()) { |
| 6600 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6601 | } else { |
| 6602 | DCHECK(cls.IsStackSlot()) << cls; |
| 6603 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6604 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6605 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6606 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6607 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6608 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6609 | |
| 6610 | // If the class reference currently in `temp` is not null, jump |
| 6611 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6612 | __ testl(temp, temp); |
| 6613 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6614 | // Otherwise, jump to the slow path to throw the exception. |
| 6615 | // |
| 6616 | // But before, move back the object's class into `temp` before |
| 6617 | // going into the slow path, as it has been overwritten in the |
| 6618 | // meantime. |
| 6619 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6620 | GenerateReferenceLoadTwoRegisters( |
| 6621 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6622 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6623 | break; |
| 6624 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6625 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6626 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6627 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6628 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6629 | if (cls.IsRegister()) { |
| 6630 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6631 | } else { |
| 6632 | DCHECK(cls.IsStackSlot()) << cls; |
| 6633 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6634 | } |
| 6635 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6636 | |
| 6637 | // 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] | 6638 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6639 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6640 | |
| 6641 | // If the component type is not null (i.e. the object is indeed |
| 6642 | // an array), jump to label `check_non_primitive_component_type` |
| 6643 | // to further check that this component type is not a primitive |
| 6644 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6645 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6646 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6647 | // Otherwise, jump to the slow path to throw the exception. |
| 6648 | // |
| 6649 | // But before, move back the object's class into `temp` before |
| 6650 | // going into the slow path, as it has been overwritten in the |
| 6651 | // meantime. |
| 6652 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6653 | GenerateReferenceLoadTwoRegisters( |
| 6654 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6655 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6656 | |
| 6657 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6658 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6659 | __ j(kEqual, &done); |
| 6660 | // Same comment as above regarding `temp` and the slow path. |
| 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 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6668 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6669 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6670 | // We always go into the type check slow path for the unresolved |
| 6671 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6672 | // |
| 6673 | // We cannot directly call the CheckCast runtime entry point |
| 6674 | // without resorting to a type checking slow path here (i.e. by |
| 6675 | // calling InvokeRuntime directly), as it would require to |
| 6676 | // assign fixed registers for the inputs of this HInstanceOf |
| 6677 | // instruction (following the runtime calling convention), which |
| 6678 | // might be cluttered by the potential first read barrier |
| 6679 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6680 | // |
| 6681 | // TODO: Introduce a new runtime entry point taking the object |
| 6682 | // to test (instead of its class) as argument, and let it deal |
| 6683 | // with the read barrier issues. This will let us refactor this |
| 6684 | // case of the `switch` code as it was previously (with a direct |
| 6685 | // call to the runtime not using a type checking slow path). |
| 6686 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6687 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6688 | break; |
| 6689 | } |
| 6690 | __ Bind(&done); |
| 6691 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6692 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6693 | } |
| 6694 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6695 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6696 | LocationSummary* locations = |
| 6697 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6698 | InvokeRuntimeCallingConvention calling_convention; |
| 6699 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6700 | } |
| 6701 | |
| 6702 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6703 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6704 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6705 | instruction, |
| 6706 | instruction->GetDexPc(), |
| 6707 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6708 | if (instruction->IsEnter()) { |
| 6709 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6710 | } else { |
| 6711 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6712 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6713 | } |
| 6714 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6715 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6716 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6717 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6718 | |
| 6719 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6720 | LocationSummary* locations = |
| 6721 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6722 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6723 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6724 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6725 | locations->SetInAt(1, Location::Any()); |
| 6726 | locations->SetOut(Location::SameAsFirstInput()); |
| 6727 | } |
| 6728 | |
| 6729 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6730 | HandleBitwiseOperation(instruction); |
| 6731 | } |
| 6732 | |
| 6733 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6734 | HandleBitwiseOperation(instruction); |
| 6735 | } |
| 6736 | |
| 6737 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6738 | HandleBitwiseOperation(instruction); |
| 6739 | } |
| 6740 | |
| 6741 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6742 | LocationSummary* locations = instruction->GetLocations(); |
| 6743 | Location first = locations->InAt(0); |
| 6744 | Location second = locations->InAt(1); |
| 6745 | DCHECK(first.Equals(locations->Out())); |
| 6746 | |
| 6747 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6748 | if (second.IsRegister()) { |
| 6749 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6750 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6751 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6752 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6753 | } else { |
| 6754 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6755 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6756 | } |
| 6757 | } else if (second.IsConstant()) { |
| 6758 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6759 | __ andl(first.AsRegister<Register>(), |
| 6760 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6761 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6762 | __ orl(first.AsRegister<Register>(), |
| 6763 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6764 | } else { |
| 6765 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6766 | __ xorl(first.AsRegister<Register>(), |
| 6767 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6768 | } |
| 6769 | } else { |
| 6770 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6771 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6772 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6773 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6774 | } else { |
| 6775 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6776 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6777 | } |
| 6778 | } |
| 6779 | } else { |
| 6780 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6781 | if (second.IsRegisterPair()) { |
| 6782 | if (instruction->IsAnd()) { |
| 6783 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6784 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6785 | } else if (instruction->IsOr()) { |
| 6786 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6787 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6788 | } else { |
| 6789 | DCHECK(instruction->IsXor()); |
| 6790 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6791 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6792 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6793 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6794 | if (instruction->IsAnd()) { |
| 6795 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6796 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6797 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6798 | } else if (instruction->IsOr()) { |
| 6799 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6800 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6801 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6802 | } else { |
| 6803 | DCHECK(instruction->IsXor()); |
| 6804 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6805 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6806 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6807 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6808 | } else { |
| 6809 | DCHECK(second.IsConstant()) << second; |
| 6810 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6811 | int32_t low_value = Low32Bits(value); |
| 6812 | int32_t high_value = High32Bits(value); |
| 6813 | Immediate low(low_value); |
| 6814 | Immediate high(high_value); |
| 6815 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6816 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6817 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6818 | if (low_value == 0) { |
| 6819 | __ xorl(first_low, first_low); |
| 6820 | } else if (low_value != -1) { |
| 6821 | __ andl(first_low, low); |
| 6822 | } |
| 6823 | if (high_value == 0) { |
| 6824 | __ xorl(first_high, first_high); |
| 6825 | } else if (high_value != -1) { |
| 6826 | __ andl(first_high, high); |
| 6827 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6828 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6829 | if (low_value != 0) { |
| 6830 | __ orl(first_low, low); |
| 6831 | } |
| 6832 | if (high_value != 0) { |
| 6833 | __ orl(first_high, high); |
| 6834 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6835 | } else { |
| 6836 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6837 | if (low_value != 0) { |
| 6838 | __ xorl(first_low, low); |
| 6839 | } |
| 6840 | if (high_value != 0) { |
| 6841 | __ xorl(first_high, high); |
| 6842 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6843 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6844 | } |
| 6845 | } |
| 6846 | } |
| 6847 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6848 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6849 | Location out, |
| 6850 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6851 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6852 | Register out_reg = out.AsRegister<Register>(); |
| 6853 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6854 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6855 | if (kUseBakerReadBarrier) { |
| 6856 | // Load with fast path based Baker's read barrier. |
| 6857 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6858 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6859 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6860 | } else { |
| 6861 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6862 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6863 | // in the following move operation, as we will need it for the |
| 6864 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6865 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6866 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6867 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6868 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6869 | } |
| 6870 | } else { |
| 6871 | // Plain load with no read barrier. |
| 6872 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6873 | __ movl(out_reg, Address(out_reg, offset)); |
| 6874 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6875 | } |
| 6876 | } |
| 6877 | |
| 6878 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6879 | Location out, |
| 6880 | Location obj, |
| 6881 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6882 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6883 | Register out_reg = out.AsRegister<Register>(); |
| 6884 | Register obj_reg = obj.AsRegister<Register>(); |
| 6885 | if (kEmitCompilerReadBarrier) { |
| 6886 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6887 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6888 | // Load with fast path based Baker's read barrier. |
| 6889 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6890 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6891 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6892 | } else { |
| 6893 | // Load with slow path based read barrier. |
| 6894 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6895 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6896 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6897 | } |
| 6898 | } else { |
| 6899 | // Plain load with no read barrier. |
| 6900 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6901 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6902 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6903 | } |
| 6904 | } |
| 6905 | |
| 6906 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6907 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6908 | const Address& address, |
| 6909 | Label* fixup_label) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6910 | Register root_reg = root.AsRegister<Register>(); |
| 6911 | if (kEmitCompilerReadBarrier) { |
| 6912 | if (kUseBakerReadBarrier) { |
| 6913 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6914 | // Baker's read barrier are used: |
| 6915 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6916 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6917 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6918 | // root = ReadBarrier::Mark(root) |
| 6919 | // } |
| 6920 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6921 | // /* GcRoot<mirror::Object> */ root = *address |
| 6922 | __ movl(root_reg, address); |
| 6923 | if (fixup_label != nullptr) { |
| 6924 | __ Bind(fixup_label); |
| 6925 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6926 | static_assert( |
| 6927 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6928 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6929 | "have different sizes."); |
| 6930 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6931 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6932 | "have different sizes."); |
| 6933 | |
| 6934 | // Slow path used to mark the GC root `root`. |
| 6935 | SlowPathCode* slow_path = |
| 6936 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6937 | codegen_->AddSlowPath(slow_path); |
| 6938 | |
| 6939 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6940 | Immediate(0)); |
| 6941 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6942 | __ Bind(slow_path->GetExitLabel()); |
| 6943 | } else { |
| 6944 | // GC root loaded through a slow path for read barriers other |
| 6945 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6946 | // /* GcRoot<mirror::Object>* */ root = address |
| 6947 | __ leal(root_reg, address); |
| 6948 | if (fixup_label != nullptr) { |
| 6949 | __ Bind(fixup_label); |
| 6950 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6951 | // /* mirror::Object* */ root = root->Read() |
| 6952 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6953 | } |
| 6954 | } else { |
| 6955 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6956 | // /* GcRoot<mirror::Object> */ root = *address |
| 6957 | __ movl(root_reg, address); |
| 6958 | if (fixup_label != nullptr) { |
| 6959 | __ Bind(fixup_label); |
| 6960 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6961 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6962 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6963 | } |
| 6964 | } |
| 6965 | |
| 6966 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6967 | Location ref, |
| 6968 | Register obj, |
| 6969 | uint32_t offset, |
| 6970 | Location temp, |
| 6971 | bool needs_null_check) { |
| 6972 | DCHECK(kEmitCompilerReadBarrier); |
| 6973 | DCHECK(kUseBakerReadBarrier); |
| 6974 | |
| 6975 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6976 | Address src(obj, offset); |
| 6977 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6978 | } |
| 6979 | |
| 6980 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6981 | Location ref, |
| 6982 | Register obj, |
| 6983 | uint32_t data_offset, |
| 6984 | Location index, |
| 6985 | Location temp, |
| 6986 | bool needs_null_check) { |
| 6987 | DCHECK(kEmitCompilerReadBarrier); |
| 6988 | DCHECK(kUseBakerReadBarrier); |
| 6989 | |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 6990 | static_assert( |
| 6991 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 6992 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6993 | // /* HeapReference<Object> */ ref = |
| 6994 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6995 | Address src = index.IsConstant() ? |
| 6996 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6997 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6998 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6999 | } |
| 7000 | |
| 7001 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 7002 | Location ref, |
| 7003 | Register obj, |
| 7004 | const Address& src, |
| 7005 | Location temp, |
| 7006 | bool needs_null_check) { |
| 7007 | DCHECK(kEmitCompilerReadBarrier); |
| 7008 | DCHECK(kUseBakerReadBarrier); |
| 7009 | |
| 7010 | // In slow path based read barriers, the read barrier call is |
| 7011 | // inserted after the original load. However, in fast path based |
| 7012 | // Baker's read barriers, we need to perform the load of |
| 7013 | // mirror::Object::monitor_ *before* the original reference load. |
| 7014 | // This load-load ordering is required by the read barrier. |
| 7015 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 7016 | // |
| 7017 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 7018 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 7019 | // HeapReference<Object> ref = *src; // Original reference load. |
| 7020 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 7021 | // if (is_gray) { |
| 7022 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 7023 | // } |
| 7024 | // |
| 7025 | // Note: the original implementation in ReadBarrier::Barrier is |
| 7026 | // slightly more complex as: |
| 7027 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7028 | // the high-bits of rb_state, which are expected to be all zeroes |
| 7029 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 7030 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7031 | // - it performs additional checks that we do not do here for |
| 7032 | // performance reasons. |
| 7033 | |
| 7034 | Register ref_reg = ref.AsRegister<Register>(); |
| 7035 | Register temp_reg = temp.AsRegister<Register>(); |
| 7036 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 7037 | |
| 7038 | // /* int32_t */ monitor = obj->monitor_ |
| 7039 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 7040 | if (needs_null_check) { |
| 7041 | MaybeRecordImplicitNullCheck(instruction); |
| 7042 | } |
| 7043 | // /* LockWord */ lock_word = LockWord(monitor) |
| 7044 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 7045 | "art::LockWord and int32_t have different sizes."); |
| 7046 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 7047 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 7048 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 7049 | static_assert( |
| 7050 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 7051 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 7052 | |
| 7053 | // Load fence to prevent load-load reordering. |
| 7054 | // Note that this is a no-op, thanks to the x86 memory model. |
| 7055 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 7056 | |
| 7057 | // The actual reference load. |
| 7058 | // /* HeapReference<Object> */ ref = *src |
| 7059 | __ movl(ref_reg, src); |
| 7060 | |
| 7061 | // Object* ref = ref_addr->AsMirrorPtr() |
| 7062 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 7063 | |
| 7064 | // Slow path used to mark the object `ref` when it is gray. |
| 7065 | SlowPathCode* slow_path = |
| 7066 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 7067 | AddSlowPath(slow_path); |
| 7068 | |
| 7069 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 7070 | // ref = ReadBarrier::Mark(ref); |
| 7071 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 7072 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 7073 | __ Bind(slow_path->GetExitLabel()); |
| 7074 | } |
| 7075 | |
| 7076 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 7077 | Location out, |
| 7078 | Location ref, |
| 7079 | Location obj, |
| 7080 | uint32_t offset, |
| 7081 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7082 | DCHECK(kEmitCompilerReadBarrier); |
| 7083 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7084 | // Insert a slow path based read barrier *after* the reference load. |
| 7085 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7086 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 7087 | // reference will be carried out by the runtime within the slow |
| 7088 | // path. |
| 7089 | // |
| 7090 | // Note that `ref` currently does not get unpoisoned (when heap |
| 7091 | // poisoning is enabled), which is alright as the `ref` argument is |
| 7092 | // not used by the artReadBarrierSlow entry point. |
| 7093 | // |
| 7094 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 7095 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 7096 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 7097 | AddSlowPath(slow_path); |
| 7098 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7099 | __ jmp(slow_path->GetEntryLabel()); |
| 7100 | __ Bind(slow_path->GetExitLabel()); |
| 7101 | } |
| 7102 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7103 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 7104 | Location out, |
| 7105 | Location ref, |
| 7106 | Location obj, |
| 7107 | uint32_t offset, |
| 7108 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7109 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7110 | // Baker's read barriers shall be handled by the fast path |
| 7111 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 7112 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7113 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 7114 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7115 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7116 | } else if (kPoisonHeapReferences) { |
| 7117 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 7118 | } |
| 7119 | } |
| 7120 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7121 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 7122 | Location out, |
| 7123 | Location root) { |
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 GC root load. |
| 7127 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7128 | // Note that GC roots are not affected by heap poisoning, so we do |
| 7129 | // not need to do anything special for this here. |
| 7130 | SlowPathCode* slow_path = |
| 7131 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 7132 | AddSlowPath(slow_path); |
| 7133 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7134 | __ jmp(slow_path->GetEntryLabel()); |
| 7135 | __ Bind(slow_path->GetExitLabel()); |
| 7136 | } |
| 7137 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7138 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7139 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7140 | LOG(FATAL) << "Unreachable"; |
| 7141 | } |
| 7142 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7143 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7144 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7145 | LOG(FATAL) << "Unreachable"; |
| 7146 | } |
| 7147 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7148 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7149 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7150 | LocationSummary* locations = |
| 7151 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7152 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7153 | } |
| 7154 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7155 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7156 | int32_t lower_bound, |
| 7157 | uint32_t num_entries, |
| 7158 | HBasicBlock* switch_block, |
| 7159 | HBasicBlock* default_block) { |
| 7160 | // Figure out the correct compare values and jump conditions. |
| 7161 | // Handle the first compare/branch as a special case because it might |
| 7162 | // jump to the default case. |
| 7163 | DCHECK_GT(num_entries, 2u); |
| 7164 | Condition first_condition; |
| 7165 | uint32_t index; |
| 7166 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7167 | if (lower_bound != 0) { |
| 7168 | first_condition = kLess; |
| 7169 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7170 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7171 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7172 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7173 | index = 1; |
| 7174 | } else { |
| 7175 | // Handle all the compare/jumps below. |
| 7176 | first_condition = kBelow; |
| 7177 | index = 0; |
| 7178 | } |
| 7179 | |
| 7180 | // Handle the rest of the compare/jumps. |
| 7181 | for (; index + 1 < num_entries; index += 2) { |
| 7182 | int32_t compare_to_value = lower_bound + index + 1; |
| 7183 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7184 | // Jump to successors[index] if value < case_value[index]. |
| 7185 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7186 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7187 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7188 | } |
| 7189 | |
| 7190 | if (index != num_entries) { |
| 7191 | // There are an odd number of entries. Handle the last one. |
| 7192 | DCHECK_EQ(index + 1, num_entries); |
| 7193 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7194 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7195 | } |
| 7196 | |
| 7197 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7198 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7199 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7200 | } |
| 7201 | } |
| 7202 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7203 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7204 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7205 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7206 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7207 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7208 | |
| 7209 | GenPackedSwitchWithCompares(value_reg, |
| 7210 | lower_bound, |
| 7211 | num_entries, |
| 7212 | switch_instr->GetBlock(), |
| 7213 | switch_instr->GetDefaultBlock()); |
| 7214 | } |
| 7215 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7216 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7217 | LocationSummary* locations = |
| 7218 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7219 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7220 | |
| 7221 | // Constant area pointer. |
| 7222 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7223 | |
| 7224 | // And the temporary we need. |
| 7225 | locations->AddTemp(Location::RequiresRegister()); |
| 7226 | } |
| 7227 | |
| 7228 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7229 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7230 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7231 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7232 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7233 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7234 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7235 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7236 | GenPackedSwitchWithCompares(value_reg, |
| 7237 | lower_bound, |
| 7238 | num_entries, |
| 7239 | switch_instr->GetBlock(), |
| 7240 | default_block); |
| 7241 | return; |
| 7242 | } |
| 7243 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7244 | // Optimizing has a jump area. |
| 7245 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7246 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7247 | |
| 7248 | // Remove the bias, if needed. |
| 7249 | if (lower_bound != 0) { |
| 7250 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7251 | value_reg = temp_reg; |
| 7252 | } |
| 7253 | |
| 7254 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7255 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7256 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7257 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7258 | |
| 7259 | // We are in the range of the table. |
| 7260 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7261 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7262 | |
| 7263 | // Compute the actual target address by adding in constant_area. |
| 7264 | __ addl(temp_reg, constant_area); |
| 7265 | |
| 7266 | // And jump. |
| 7267 | __ jmp(temp_reg); |
| 7268 | } |
| 7269 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7270 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7271 | HX86ComputeBaseMethodAddress* insn) { |
| 7272 | LocationSummary* locations = |
| 7273 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7274 | locations->SetOut(Location::RequiresRegister()); |
| 7275 | } |
| 7276 | |
| 7277 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7278 | HX86ComputeBaseMethodAddress* insn) { |
| 7279 | LocationSummary* locations = insn->GetLocations(); |
| 7280 | Register reg = locations->Out().AsRegister<Register>(); |
| 7281 | |
| 7282 | // Generate call to next instruction. |
| 7283 | Label next_instruction; |
| 7284 | __ call(&next_instruction); |
| 7285 | __ Bind(&next_instruction); |
| 7286 | |
| 7287 | // Remember this offset for later use with constant area. |
| 7288 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7289 | |
| 7290 | // Grab the return address off the stack. |
| 7291 | __ popl(reg); |
| 7292 | } |
| 7293 | |
| 7294 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7295 | HX86LoadFromConstantTable* insn) { |
| 7296 | LocationSummary* locations = |
| 7297 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7298 | |
| 7299 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7300 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7301 | |
| 7302 | // 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] | 7303 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7304 | return; |
| 7305 | } |
| 7306 | |
| 7307 | switch (insn->GetType()) { |
| 7308 | case Primitive::kPrimFloat: |
| 7309 | case Primitive::kPrimDouble: |
| 7310 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7311 | break; |
| 7312 | |
| 7313 | case Primitive::kPrimInt: |
| 7314 | locations->SetOut(Location::RequiresRegister()); |
| 7315 | break; |
| 7316 | |
| 7317 | default: |
| 7318 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7319 | } |
| 7320 | } |
| 7321 | |
| 7322 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7323 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7324 | return; |
| 7325 | } |
| 7326 | |
| 7327 | LocationSummary* locations = insn->GetLocations(); |
| 7328 | Location out = locations->Out(); |
| 7329 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7330 | HConstant *value = insn->GetConstant(); |
| 7331 | |
| 7332 | switch (insn->GetType()) { |
| 7333 | case Primitive::kPrimFloat: |
| 7334 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7335 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7336 | break; |
| 7337 | |
| 7338 | case Primitive::kPrimDouble: |
| 7339 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7340 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7341 | break; |
| 7342 | |
| 7343 | case Primitive::kPrimInt: |
| 7344 | __ movl(out.AsRegister<Register>(), |
| 7345 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7346 | break; |
| 7347 | |
| 7348 | default: |
| 7349 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7350 | } |
| 7351 | } |
| 7352 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7353 | /** |
| 7354 | * Class to handle late fixup of offsets into constant area. |
| 7355 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7356 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7357 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7358 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7359 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7360 | |
| 7361 | protected: |
| 7362 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7363 | |
| 7364 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7365 | |
| 7366 | private: |
| 7367 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7368 | // Patch the correct offset for the instruction. The place to patch is the |
| 7369 | // last 4 bytes of the instruction. |
| 7370 | // The value to patch is the distance from the offset in the constant area |
| 7371 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7372 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7373 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7374 | |
| 7375 | // Patch in the right value. |
| 7376 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7377 | } |
| 7378 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7379 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7380 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7381 | }; |
| 7382 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7383 | /** |
| 7384 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7385 | * constant area. |
| 7386 | */ |
| 7387 | class JumpTableRIPFixup : public RIPFixup { |
| 7388 | public: |
| 7389 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7390 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7391 | |
| 7392 | void CreateJumpTable() { |
| 7393 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7394 | |
| 7395 | // Ensure that the reference to the jump table has the correct offset. |
| 7396 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7397 | SetOffset(offset_in_constant_table); |
| 7398 | |
| 7399 | // The label values in the jump table are computed relative to the |
| 7400 | // instruction addressing the constant area. |
| 7401 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7402 | |
| 7403 | // Populate the jump table with the correct values for the jump table. |
| 7404 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7405 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7406 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7407 | // The value that we want is the target offset - the position of the table. |
| 7408 | for (int32_t i = 0; i < num_entries; i++) { |
| 7409 | HBasicBlock* b = successors[i]; |
| 7410 | Label* l = codegen_->GetLabelOf(b); |
| 7411 | DCHECK(l->IsBound()); |
| 7412 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7413 | assembler->AppendInt32(offset_to_block); |
| 7414 | } |
| 7415 | } |
| 7416 | |
| 7417 | private: |
| 7418 | const HX86PackedSwitch* switch_instr_; |
| 7419 | }; |
| 7420 | |
| 7421 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7422 | // Generate the constant area if needed. |
| 7423 | X86Assembler* assembler = GetAssembler(); |
| 7424 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7425 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7426 | // byte values. |
| 7427 | assembler->Align(4, 0); |
| 7428 | constant_area_start_ = assembler->CodeSize(); |
| 7429 | |
| 7430 | // Populate any jump tables. |
| 7431 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7432 | jump_table->CreateJumpTable(); |
| 7433 | } |
| 7434 | |
| 7435 | // And now add the constant area to the generated code. |
| 7436 | assembler->AddConstantArea(); |
| 7437 | } |
| 7438 | |
| 7439 | // And finish up. |
| 7440 | CodeGenerator::Finalize(allocator); |
| 7441 | } |
| 7442 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7443 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7444 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7445 | return Address(reg, kDummy32BitOffset, fixup); |
| 7446 | } |
| 7447 | |
| 7448 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7449 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7450 | return Address(reg, kDummy32BitOffset, fixup); |
| 7451 | } |
| 7452 | |
| 7453 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7454 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7455 | return Address(reg, kDummy32BitOffset, fixup); |
| 7456 | } |
| 7457 | |
| 7458 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7459 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7460 | return Address(reg, kDummy32BitOffset, fixup); |
| 7461 | } |
| 7462 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7463 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7464 | if (value == 0) { |
| 7465 | __ xorl(dest, dest); |
| 7466 | } else { |
| 7467 | __ movl(dest, Immediate(value)); |
| 7468 | } |
| 7469 | } |
| 7470 | |
| 7471 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7472 | if (value == 0) { |
| 7473 | __ testl(dest, dest); |
| 7474 | } else { |
| 7475 | __ cmpl(dest, Immediate(value)); |
| 7476 | } |
| 7477 | } |
| 7478 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7479 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7480 | Register reg, |
| 7481 | Register value) { |
| 7482 | // Create a fixup to be used to create and address the jump table. |
| 7483 | JumpTableRIPFixup* table_fixup = |
| 7484 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7485 | |
| 7486 | // We have to populate the jump tables. |
| 7487 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7488 | |
| 7489 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7490 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7491 | } |
| 7492 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7493 | // TODO: target as memory. |
| 7494 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7495 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7496 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7497 | return; |
| 7498 | } |
| 7499 | |
| 7500 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7501 | |
| 7502 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7503 | if (target.Equals(return_loc)) { |
| 7504 | return; |
| 7505 | } |
| 7506 | |
| 7507 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7508 | // with the else branch. |
| 7509 | if (type == Primitive::kPrimLong) { |
| 7510 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7511 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7512 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7513 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7514 | } else { |
| 7515 | // Let the parallel move resolver take care of all of this. |
| 7516 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7517 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7518 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7519 | } |
| 7520 | } |
| 7521 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7522 | #undef __ |
| 7523 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7524 | } // namespace x86 |
| 7525 | } // namespace art |