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" |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 29 | #include "pc_relative_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace x86 { |
| 42 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = EAX; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 46 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 47 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 48 | static constexpr int kC2ConditionMask = 0x400; |
| 49 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 50 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 51 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 52 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 53 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 55 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 57 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 59 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 60 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 61 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 62 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 63 | // Live registers will be restored in the catch block if caught. |
| 64 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 65 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 66 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 67 | instruction_, |
| 68 | instruction_->GetDexPc(), |
| 69 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 70 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 73 | bool IsFatal() const OVERRIDE { return true; } |
| 74 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 75 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 76 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 78 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 79 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 80 | }; |
| 81 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 82 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | public: |
| 84 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 85 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 86 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 87 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 88 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 89 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 90 | // Live registers will be restored in the catch block if caught. |
| 91 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 92 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 93 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 94 | instruction_, |
| 95 | instruction_->GetDexPc(), |
| 96 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 97 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 100 | bool IsFatal() const OVERRIDE { return true; } |
| 101 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 102 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 103 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 104 | private: |
| 105 | HDivZeroCheck* const instruction_; |
| 106 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 107 | }; |
| 108 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 109 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 111 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 113 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 114 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 115 | if (is_div_) { |
| 116 | __ negl(reg_); |
| 117 | } else { |
| 118 | __ movl(reg_, Immediate(0)); |
| 119 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | __ jmp(GetExitLabel()); |
| 121 | } |
| 122 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 123 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 124 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 125 | private: |
| 126 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 127 | bool is_div_; |
| 128 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 131 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 134 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 135 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 136 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 137 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 138 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 139 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 140 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 141 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 142 | // Live registers will be restored in the catch block if caught. |
| 143 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 144 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 145 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 146 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 147 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 148 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 149 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 150 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 151 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 152 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 153 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 154 | instruction_, |
| 155 | instruction_->GetDexPc(), |
| 156 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 157 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 160 | bool IsFatal() const OVERRIDE { return true; } |
| 161 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 162 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 163 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 164 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 165 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 166 | |
| 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) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | : instruction_(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: |
| 204 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 205 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 206 | Label return_label_; |
| 207 | |
| 208 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 209 | }; |
| 210 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 211 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 212 | public: |
| 213 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 214 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 215 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 216 | LocationSummary* locations = instruction_->GetLocations(); |
| 217 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 218 | |
| 219 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 220 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 221 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 222 | |
| 223 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 224 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
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: |
| 239 | HLoadString* const instruction_; |
| 240 | |
| 241 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 242 | }; |
| 243 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 244 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | public: |
| 246 | LoadClassSlowPathX86(HLoadClass* cls, |
| 247 | HInstruction* at, |
| 248 | uint32_t dex_pc, |
| 249 | bool do_clinit) |
| 250 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 251 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 252 | } |
| 253 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 254 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 255 | LocationSummary* locations = at_->GetLocations(); |
| 256 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 257 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 258 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | |
| 260 | InvokeRuntimeCallingConvention calling_convention; |
| 261 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 262 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 263 | : QUICK_ENTRY_POINT(pInitializeType), |
| 264 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 265 | if (do_clinit_) { |
| 266 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 267 | } else { |
| 268 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 269 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | |
| 271 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 272 | Location out = locations->Out(); |
| 273 | if (out.IsValid()) { |
| 274 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 275 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 276 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 277 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 278 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 279 | __ jmp(GetExitLabel()); |
| 280 | } |
| 281 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 282 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 283 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 284 | private: |
| 285 | // The class this slow path will load. |
| 286 | HLoadClass* const cls_; |
| 287 | |
| 288 | // The instruction where this slow path is happening. |
| 289 | // (Might be the load class or an initialization check). |
| 290 | HInstruction* const at_; |
| 291 | |
| 292 | // The dex PC of `at_`. |
| 293 | const uint32_t dex_pc_; |
| 294 | |
| 295 | // Whether to initialize the class. |
| 296 | const bool do_clinit_; |
| 297 | |
| 298 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 299 | }; |
| 300 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 301 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 302 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 303 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 304 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 306 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 307 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 308 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 309 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 310 | DCHECK(instruction_->IsCheckCast() |
| 311 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
| 313 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 314 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 315 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 316 | if (!is_fatal_) { |
| 317 | SaveLiveRegisters(codegen, locations); |
| 318 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | |
| 320 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 321 | // move resolver. |
| 322 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 323 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 324 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 325 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 326 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 327 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 328 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 329 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 330 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 331 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 332 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 333 | instruction_, |
| 334 | instruction_->GetDexPc(), |
| 335 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 336 | CheckEntrypointTypes< |
| 337 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | } else { |
| 339 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 340 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 341 | instruction_, |
| 342 | instruction_->GetDexPc(), |
| 343 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 344 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 347 | if (!is_fatal_) { |
| 348 | if (instruction_->IsInstanceOf()) { |
| 349 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 350 | } |
| 351 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 353 | __ jmp(GetExitLabel()); |
| 354 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 357 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 358 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 359 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 360 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 361 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 362 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 363 | |
| 364 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 365 | }; |
| 366 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 367 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | public: |
| 369 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 370 | : instruction_(instruction) {} |
| 371 | |
| 372 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 373 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 374 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 375 | __ Bind(GetEntryLabel()); |
| 376 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 377 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 378 | instruction_, |
| 379 | instruction_->GetDexPc(), |
| 380 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 381 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 384 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 385 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | private: |
| 387 | HInstruction* const instruction_; |
| 388 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 389 | }; |
| 390 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 391 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 392 | public: |
| 393 | explicit ArraySetSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
| 394 | |
| 395 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 396 | LocationSummary* locations = instruction_->GetLocations(); |
| 397 | __ Bind(GetEntryLabel()); |
| 398 | SaveLiveRegisters(codegen, locations); |
| 399 | |
| 400 | InvokeRuntimeCallingConvention calling_convention; |
| 401 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 402 | parallel_move.AddMove( |
| 403 | locations->InAt(0), |
| 404 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 405 | Primitive::kPrimNot, |
| 406 | nullptr); |
| 407 | parallel_move.AddMove( |
| 408 | locations->InAt(1), |
| 409 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 410 | Primitive::kPrimInt, |
| 411 | nullptr); |
| 412 | parallel_move.AddMove( |
| 413 | locations->InAt(2), |
| 414 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 415 | Primitive::kPrimNot, |
| 416 | nullptr); |
| 417 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 418 | |
| 419 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 420 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 421 | instruction_, |
| 422 | instruction_->GetDexPc(), |
| 423 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 424 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 425 | RestoreLiveRegisters(codegen, locations); |
| 426 | __ jmp(GetExitLabel()); |
| 427 | } |
| 428 | |
| 429 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 430 | |
| 431 | private: |
| 432 | HInstruction* const instruction_; |
| 433 | |
| 434 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 435 | }; |
| 436 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 437 | // Slow path generating a read barrier for a heap reference. |
| 438 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 439 | public: |
| 440 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 441 | Location out, |
| 442 | Location ref, |
| 443 | Location obj, |
| 444 | uint32_t offset, |
| 445 | Location index) |
| 446 | : instruction_(instruction), |
| 447 | out_(out), |
| 448 | ref_(ref), |
| 449 | obj_(obj), |
| 450 | offset_(offset), |
| 451 | index_(index) { |
| 452 | DCHECK(kEmitCompilerReadBarrier); |
| 453 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 454 | // has been overwritten by (or after) the heap object reference load |
| 455 | // to be instrumented, e.g.: |
| 456 | // |
| 457 | // __ movl(out, Address(out, offset)); |
| 458 | // codegen_->GenerateReadBarrier(instruction, out_loc, out_loc, out_loc, offset); |
| 459 | // |
| 460 | // In that case, we have lost the information about the original |
| 461 | // object, and the emitted read barrier cannot work properly. |
| 462 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 463 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 464 | } |
| 465 | |
| 466 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 467 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 468 | LocationSummary* locations = instruction_->GetLocations(); |
| 469 | Register reg_out = out_.AsRegister<Register>(); |
| 470 | DCHECK(locations->CanCall()); |
| 471 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 472 | DCHECK(!instruction_->IsInvoke() || |
| 473 | (instruction_->IsInvokeStaticOrDirect() && |
| 474 | instruction_->GetLocations()->Intrinsified())); |
| 475 | |
| 476 | __ Bind(GetEntryLabel()); |
| 477 | SaveLiveRegisters(codegen, locations); |
| 478 | |
| 479 | // We may have to change the index's value, but as `index_` is a |
| 480 | // constant member (like other "inputs" of this slow path), |
| 481 | // introduce a copy of it, `index`. |
| 482 | Location index = index_; |
| 483 | if (index_.IsValid()) { |
| 484 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 485 | if (instruction_->IsArrayGet()) { |
| 486 | // Compute the actual memory offset and store it in `index`. |
| 487 | Register index_reg = index_.AsRegister<Register>(); |
| 488 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 489 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 490 | // We are about to change the value of `index_reg` (see the |
| 491 | // calls to art::x86::X86Assembler::shll and |
| 492 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 493 | // not been saved by the previous call to |
| 494 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 495 | // callee-save register -- |
| 496 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 497 | // callee-save registers, as it has been designed with the |
| 498 | // assumption that callee-save registers are supposed to be |
| 499 | // handled by the called function. So, as a callee-save |
| 500 | // register, `index_reg` _would_ eventually be saved onto |
| 501 | // the stack, but it would be too late: we would have |
| 502 | // changed its value earlier. Therefore, we manually save |
| 503 | // it here into another freely available register, |
| 504 | // `free_reg`, chosen of course among the caller-save |
| 505 | // registers (as a callee-save `free_reg` register would |
| 506 | // exhibit the same problem). |
| 507 | // |
| 508 | // Note we could have requested a temporary register from |
| 509 | // the register allocator instead; but we prefer not to, as |
| 510 | // this is a slow path, and we know we can find a |
| 511 | // caller-save register that is available. |
| 512 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 513 | __ movl(free_reg, index_reg); |
| 514 | index_reg = free_reg; |
| 515 | index = Location::RegisterLocation(index_reg); |
| 516 | } else { |
| 517 | // The initial register stored in `index_` has already been |
| 518 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 519 | // (as it is not a callee-save register), so we can freely |
| 520 | // use it. |
| 521 | } |
| 522 | // Shifting the index value contained in `index_reg` by the scale |
| 523 | // factor (2) cannot overflow in practice, as the runtime is |
| 524 | // unable to allocate object arrays with a size larger than |
| 525 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 526 | __ shll(index_reg, Immediate(TIMES_4)); |
| 527 | static_assert( |
| 528 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 529 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 530 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 531 | } else { |
| 532 | DCHECK(instruction_->IsInvoke()); |
| 533 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 534 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 535 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 536 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 537 | DCHECK_EQ(offset_, 0U); |
| 538 | DCHECK(index_.IsRegisterPair()); |
| 539 | // UnsafeGet's offset location is a register pair, the low |
| 540 | // part contains the correct offset. |
| 541 | index = index_.ToLow(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | // We're moving two or three locations to locations that could |
| 546 | // overlap, so we need a parallel move resolver. |
| 547 | InvokeRuntimeCallingConvention calling_convention; |
| 548 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 549 | parallel_move.AddMove(ref_, |
| 550 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 551 | Primitive::kPrimNot, |
| 552 | nullptr); |
| 553 | parallel_move.AddMove(obj_, |
| 554 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 555 | Primitive::kPrimNot, |
| 556 | nullptr); |
| 557 | if (index.IsValid()) { |
| 558 | parallel_move.AddMove(index, |
| 559 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 560 | Primitive::kPrimInt, |
| 561 | nullptr); |
| 562 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 563 | } else { |
| 564 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 565 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 566 | } |
| 567 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 568 | instruction_, |
| 569 | instruction_->GetDexPc(), |
| 570 | this); |
| 571 | CheckEntrypointTypes< |
| 572 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 573 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 574 | |
| 575 | RestoreLiveRegisters(codegen, locations); |
| 576 | __ jmp(GetExitLabel()); |
| 577 | } |
| 578 | |
| 579 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 580 | |
| 581 | private: |
| 582 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 583 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 584 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 585 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 586 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 587 | return static_cast<Register>(i); |
| 588 | } |
| 589 | } |
| 590 | // We shall never fail to find a free caller-save register, as |
| 591 | // there are more than two core caller-save registers on x86 |
| 592 | // (meaning it is possible to find one which is different from |
| 593 | // `ref` and `obj`). |
| 594 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 595 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 596 | UNREACHABLE(); |
| 597 | } |
| 598 | |
| 599 | HInstruction* const instruction_; |
| 600 | const Location out_; |
| 601 | const Location ref_; |
| 602 | const Location obj_; |
| 603 | const uint32_t offset_; |
| 604 | // An additional location containing an index to an array. |
| 605 | // Only used for HArrayGet and the UnsafeGetObject & |
| 606 | // UnsafeGetObjectVolatile intrinsics. |
| 607 | const Location index_; |
| 608 | |
| 609 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 610 | }; |
| 611 | |
| 612 | // Slow path generating a read barrier for a GC root. |
| 613 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 614 | public: |
| 615 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
| 616 | : instruction_(instruction), out_(out), root_(root) {} |
| 617 | |
| 618 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 619 | LocationSummary* locations = instruction_->GetLocations(); |
| 620 | Register reg_out = out_.AsRegister<Register>(); |
| 621 | DCHECK(locations->CanCall()); |
| 622 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 623 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()); |
| 624 | |
| 625 | __ Bind(GetEntryLabel()); |
| 626 | SaveLiveRegisters(codegen, locations); |
| 627 | |
| 628 | InvokeRuntimeCallingConvention calling_convention; |
| 629 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 630 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 631 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 632 | instruction_, |
| 633 | instruction_->GetDexPc(), |
| 634 | this); |
| 635 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 636 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 637 | |
| 638 | RestoreLiveRegisters(codegen, locations); |
| 639 | __ jmp(GetExitLabel()); |
| 640 | } |
| 641 | |
| 642 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 643 | |
| 644 | private: |
| 645 | HInstruction* const instruction_; |
| 646 | const Location out_; |
| 647 | const Location root_; |
| 648 | |
| 649 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 650 | }; |
| 651 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 652 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 653 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 654 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 655 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 656 | switch (cond) { |
| 657 | case kCondEQ: return kEqual; |
| 658 | case kCondNE: return kNotEqual; |
| 659 | case kCondLT: return kLess; |
| 660 | case kCondLE: return kLessEqual; |
| 661 | case kCondGT: return kGreater; |
| 662 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 663 | case kCondB: return kBelow; |
| 664 | case kCondBE: return kBelowEqual; |
| 665 | case kCondA: return kAbove; |
| 666 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 667 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 668 | LOG(FATAL) << "Unreachable"; |
| 669 | UNREACHABLE(); |
| 670 | } |
| 671 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 672 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 673 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 674 | switch (cond) { |
| 675 | case kCondEQ: return kEqual; |
| 676 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 677 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 678 | case kCondLT: return kBelow; |
| 679 | case kCondLE: return kBelowEqual; |
| 680 | case kCondGT: return kAbove; |
| 681 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 682 | // Unsigned remain unchanged. |
| 683 | case kCondB: return kBelow; |
| 684 | case kCondBE: return kBelowEqual; |
| 685 | case kCondA: return kAbove; |
| 686 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 687 | } |
| 688 | LOG(FATAL) << "Unreachable"; |
| 689 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 692 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 693 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 697 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 700 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 701 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 702 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 703 | } |
| 704 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 705 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 706 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 707 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 708 | } |
| 709 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 710 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 711 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 712 | return GetFloatingPointSpillSlotSize(); |
| 713 | } |
| 714 | |
| 715 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 716 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 717 | return GetFloatingPointSpillSlotSize(); |
| 718 | } |
| 719 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 720 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 721 | HInstruction* instruction, |
| 722 | uint32_t dex_pc, |
| 723 | SlowPathCode* slow_path) { |
| 724 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 725 | instruction, |
| 726 | dex_pc, |
| 727 | slow_path); |
| 728 | } |
| 729 | |
| 730 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 731 | HInstruction* instruction, |
| 732 | uint32_t dex_pc, |
| 733 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 734 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 735 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 736 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 737 | } |
| 738 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 739 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 740 | const X86InstructionSetFeatures& isa_features, |
| 741 | const CompilerOptions& compiler_options, |
| 742 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 743 | : CodeGenerator(graph, |
| 744 | kNumberOfCpuRegisters, |
| 745 | kNumberOfXmmRegisters, |
| 746 | kNumberOfRegisterPairs, |
| 747 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 748 | arraysize(kCoreCalleeSaves)) |
| 749 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 750 | 0, |
| 751 | compiler_options, |
| 752 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 753 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 754 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 755 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 756 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 757 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 758 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 759 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 760 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 761 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 762 | // Use a fake return address register to mimic Quick. |
| 763 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 764 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 765 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 766 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 767 | switch (type) { |
| 768 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 769 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 770 | X86ManagedRegister pair = |
| 771 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 772 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 773 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 774 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 775 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 776 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 777 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | case Primitive::kPrimByte: |
| 781 | case Primitive::kPrimBoolean: |
| 782 | case Primitive::kPrimChar: |
| 783 | case Primitive::kPrimShort: |
| 784 | case Primitive::kPrimInt: |
| 785 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 786 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 787 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 788 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 789 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 790 | X86ManagedRegister current = |
| 791 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 792 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 793 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 794 | } |
| 795 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 796 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 800 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 801 | return Location::FpuRegisterLocation( |
| 802 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 803 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 804 | |
| 805 | case Primitive::kPrimVoid: |
| 806 | LOG(FATAL) << "Unreachable type " << type; |
| 807 | } |
| 808 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 809 | return Location::NoLocation(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 810 | } |
| 811 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 812 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 813 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 814 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 815 | |
| 816 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 817 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 818 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 819 | if (is_baseline) { |
| 820 | blocked_core_registers_[EBP] = true; |
| 821 | blocked_core_registers_[ESI] = true; |
| 822 | blocked_core_registers_[EDI] = true; |
| 823 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 824 | |
| 825 | UpdateBlockedPairRegisters(); |
| 826 | } |
| 827 | |
| 828 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 829 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 830 | X86ManagedRegister current = |
| 831 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 832 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 833 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 834 | blocked_register_pairs_[i] = true; |
| 835 | } |
| 836 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 839 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 840 | : HGraphVisitor(graph), |
| 841 | assembler_(codegen->GetAssembler()), |
| 842 | codegen_(codegen) {} |
| 843 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 844 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 845 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 846 | } |
| 847 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 848 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 849 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 850 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 851 | bool skip_overflow_check = |
| 852 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 853 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 854 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 855 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 856 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 857 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 858 | } |
| 859 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 860 | if (HasEmptyFrame()) { |
| 861 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 862 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 863 | |
| 864 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 865 | Register reg = kCoreCalleeSaves[i]; |
| 866 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 867 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 868 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 869 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 873 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 874 | __ subl(ESP, Immediate(adjust)); |
| 875 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 876 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 880 | __ cfi().RememberState(); |
| 881 | if (!HasEmptyFrame()) { |
| 882 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 883 | __ addl(ESP, Immediate(adjust)); |
| 884 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 885 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 886 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 887 | Register reg = kCoreCalleeSaves[i]; |
| 888 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 889 | __ popl(reg); |
| 890 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 891 | __ cfi().Restore(DWARFReg(reg)); |
| 892 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 893 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 894 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 895 | __ ret(); |
| 896 | __ cfi().RestoreState(); |
| 897 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 898 | } |
| 899 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 900 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 901 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 902 | } |
| 903 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 904 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 905 | switch (load->GetType()) { |
| 906 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 907 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 908 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 909 | |
| 910 | case Primitive::kPrimInt: |
| 911 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 912 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 913 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 914 | |
| 915 | case Primitive::kPrimBoolean: |
| 916 | case Primitive::kPrimByte: |
| 917 | case Primitive::kPrimChar: |
| 918 | case Primitive::kPrimShort: |
| 919 | case Primitive::kPrimVoid: |
| 920 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 921 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 925 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 926 | } |
| 927 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 928 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 929 | switch (type) { |
| 930 | case Primitive::kPrimBoolean: |
| 931 | case Primitive::kPrimByte: |
| 932 | case Primitive::kPrimChar: |
| 933 | case Primitive::kPrimShort: |
| 934 | case Primitive::kPrimInt: |
| 935 | case Primitive::kPrimNot: |
| 936 | return Location::RegisterLocation(EAX); |
| 937 | |
| 938 | case Primitive::kPrimLong: |
| 939 | return Location::RegisterPairLocation(EAX, EDX); |
| 940 | |
| 941 | case Primitive::kPrimVoid: |
| 942 | return Location::NoLocation(); |
| 943 | |
| 944 | case Primitive::kPrimDouble: |
| 945 | case Primitive::kPrimFloat: |
| 946 | return Location::FpuRegisterLocation(XMM0); |
| 947 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 948 | |
| 949 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 953 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 954 | } |
| 955 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 956 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 957 | switch (type) { |
| 958 | case Primitive::kPrimBoolean: |
| 959 | case Primitive::kPrimByte: |
| 960 | case Primitive::kPrimChar: |
| 961 | case Primitive::kPrimShort: |
| 962 | case Primitive::kPrimInt: |
| 963 | case Primitive::kPrimNot: { |
| 964 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 965 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 966 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 967 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
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::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 970 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 971 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 972 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 973 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 974 | uint32_t index = gp_index_; |
| 975 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 976 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 977 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 978 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 979 | calling_convention.GetRegisterPairAt(index)); |
| 980 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 981 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 982 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 987 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 988 | stack_index_++; |
| 989 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 990 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 991 | } else { |
| 992 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 997 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 998 | stack_index_ += 2; |
| 999 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1000 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1001 | } else { |
| 1002 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1006 | case Primitive::kPrimVoid: |
| 1007 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1008 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1009 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1010 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1011 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1012 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1013 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1014 | if (source.Equals(destination)) { |
| 1015 | return; |
| 1016 | } |
| 1017 | if (destination.IsRegister()) { |
| 1018 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1019 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1020 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1021 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1022 | } else { |
| 1023 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1024 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1025 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1026 | } else if (destination.IsFpuRegister()) { |
| 1027 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1028 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1029 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1030 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1031 | } else { |
| 1032 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1033 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1034 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1035 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1036 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1037 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1038 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1039 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1040 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1041 | } else if (source.IsConstant()) { |
| 1042 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1043 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1044 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1045 | } else { |
| 1046 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1047 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1048 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1054 | if (source.Equals(destination)) { |
| 1055 | return; |
| 1056 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1057 | if (destination.IsRegisterPair()) { |
| 1058 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1059 | EmitParallelMoves( |
| 1060 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1061 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1062 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1063 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1064 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1065 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1066 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1067 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1068 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1069 | __ psrlq(src_reg, Immediate(32)); |
| 1070 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1071 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1072 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1073 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1074 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1075 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1076 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1077 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1078 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1079 | if (source.IsFpuRegister()) { |
| 1080 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1081 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1082 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1083 | } else if (source.IsRegisterPair()) { |
| 1084 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1085 | // Create stack space for 2 elements. |
| 1086 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1087 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1088 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1089 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1090 | // And remove the temporary stack space we allocated. |
| 1091 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1092 | } else { |
| 1093 | LOG(FATAL) << "Unimplemented"; |
| 1094 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1095 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1096 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1097 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1098 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1099 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1100 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1101 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1102 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1103 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1104 | } else if (source.IsConstant()) { |
| 1105 | HConstant* constant = source.GetConstant(); |
| 1106 | int64_t value; |
| 1107 | if (constant->IsLongConstant()) { |
| 1108 | value = constant->AsLongConstant()->GetValue(); |
| 1109 | } else { |
| 1110 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1111 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1112 | } |
| 1113 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1114 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1115 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1116 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1117 | EmitParallelMoves( |
| 1118 | Location::StackSlot(source.GetStackIndex()), |
| 1119 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1120 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1121 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1122 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1123 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1128 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1129 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1130 | if (instruction->IsCurrentMethod()) { |
| 1131 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1132 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1133 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1134 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1135 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1136 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1137 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1138 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1139 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1140 | } else if (location.IsStackSlot()) { |
| 1141 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 1142 | } else { |
| 1143 | DCHECK(location.IsConstant()); |
| 1144 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1145 | } |
| 1146 | } else if (const_to_move->IsLongConstant()) { |
| 1147 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1148 | if (location.IsRegisterPair()) { |
| 1149 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 1150 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 1151 | } else if (location.IsDoubleStackSlot()) { |
| 1152 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1153 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 1154 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1155 | } else { |
| 1156 | DCHECK(location.IsConstant()); |
| 1157 | DCHECK_EQ(location.GetConstant(), instruction); |
| 1158 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1159 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1160 | } else if (instruction->IsTemporary()) { |
| 1161 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1162 | if (temp_location.IsStackSlot()) { |
| 1163 | Move32(location, temp_location); |
| 1164 | } else { |
| 1165 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1166 | Move64(location, temp_location); |
| 1167 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1168 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1169 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1170 | switch (instruction->GetType()) { |
| 1171 | case Primitive::kPrimBoolean: |
| 1172 | case Primitive::kPrimByte: |
| 1173 | case Primitive::kPrimChar: |
| 1174 | case Primitive::kPrimShort: |
| 1175 | case Primitive::kPrimInt: |
| 1176 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1177 | case Primitive::kPrimFloat: |
| 1178 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1179 | break; |
| 1180 | |
| 1181 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1182 | case Primitive::kPrimDouble: |
| 1183 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1184 | break; |
| 1185 | |
| 1186 | default: |
| 1187 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 1188 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1189 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1190 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1191 | switch (instruction->GetType()) { |
| 1192 | case Primitive::kPrimBoolean: |
| 1193 | case Primitive::kPrimByte: |
| 1194 | case Primitive::kPrimChar: |
| 1195 | case Primitive::kPrimShort: |
| 1196 | case Primitive::kPrimInt: |
| 1197 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1198 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1199 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1200 | break; |
| 1201 | |
| 1202 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1203 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1204 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1205 | break; |
| 1206 | |
| 1207 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1208 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1209 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1213 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1214 | DCHECK(location.IsRegister()); |
| 1215 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1216 | } |
| 1217 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1218 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1219 | if (Primitive::Is64BitType(dst_type)) { |
| 1220 | Move64(dst, src); |
| 1221 | } else { |
| 1222 | Move32(dst, src); |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1227 | if (location.IsRegister()) { |
| 1228 | locations->AddTemp(location); |
| 1229 | } else if (location.IsRegisterPair()) { |
| 1230 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1231 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1232 | } else { |
| 1233 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1234 | } |
| 1235 | } |
| 1236 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1237 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1238 | DCHECK(!successor->IsExitBlock()); |
| 1239 | |
| 1240 | HBasicBlock* block = got->GetBlock(); |
| 1241 | HInstruction* previous = got->GetPrevious(); |
| 1242 | |
| 1243 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1244 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1245 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1246 | return; |
| 1247 | } |
| 1248 | |
| 1249 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1250 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1251 | } |
| 1252 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1253 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1257 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1258 | got->SetLocations(nullptr); |
| 1259 | } |
| 1260 | |
| 1261 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1262 | HandleGoto(got, got->GetSuccessor()); |
| 1263 | } |
| 1264 | |
| 1265 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1266 | try_boundary->SetLocations(nullptr); |
| 1267 | } |
| 1268 | |
| 1269 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1270 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1271 | if (!successor->IsExitBlock()) { |
| 1272 | HandleGoto(try_boundary, successor); |
| 1273 | } |
| 1274 | } |
| 1275 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1276 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1277 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1280 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1283 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 1284 | Label* true_label, |
| 1285 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1286 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1287 | __ j(kUnordered, true_label); |
| 1288 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1289 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1291 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 1295 | Label* true_label, |
| 1296 | Label* false_label) { |
| 1297 | LocationSummary* locations = cond->GetLocations(); |
| 1298 | Location left = locations->InAt(0); |
| 1299 | Location right = locations->InAt(1); |
| 1300 | IfCondition if_cond = cond->GetCondition(); |
| 1301 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1302 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1303 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1304 | IfCondition true_high_cond = if_cond; |
| 1305 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1306 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1307 | |
| 1308 | // Set the conditions for the test, remembering that == needs to be |
| 1309 | // decided using the low words. |
| 1310 | switch (if_cond) { |
| 1311 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1312 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1313 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1314 | break; |
| 1315 | case kCondLT: |
| 1316 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1317 | break; |
| 1318 | case kCondLE: |
| 1319 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1320 | break; |
| 1321 | case kCondGT: |
| 1322 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1323 | break; |
| 1324 | case kCondGE: |
| 1325 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1326 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1327 | case kCondB: |
| 1328 | false_high_cond = kCondA; |
| 1329 | break; |
| 1330 | case kCondBE: |
| 1331 | true_high_cond = kCondB; |
| 1332 | break; |
| 1333 | case kCondA: |
| 1334 | false_high_cond = kCondB; |
| 1335 | break; |
| 1336 | case kCondAE: |
| 1337 | true_high_cond = kCondA; |
| 1338 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | if (right.IsConstant()) { |
| 1342 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1343 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1344 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 | |
| 1346 | if (val_high == 0) { |
| 1347 | __ testl(left_high, left_high); |
| 1348 | } else { |
| 1349 | __ cmpl(left_high, Immediate(val_high)); |
| 1350 | } |
| 1351 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1352 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1353 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1354 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1355 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1356 | __ j(X86Condition(true_high_cond), true_label); |
| 1357 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1358 | } |
| 1359 | // Must be equal high, so compare the lows. |
| 1360 | if (val_low == 0) { |
| 1361 | __ testl(left_low, left_low); |
| 1362 | } else { |
| 1363 | __ cmpl(left_low, Immediate(val_low)); |
| 1364 | } |
| 1365 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1366 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1367 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1368 | |
| 1369 | __ cmpl(left_high, right_high); |
| 1370 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1371 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1373 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1374 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1375 | __ j(X86Condition(true_high_cond), true_label); |
| 1376 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1377 | } |
| 1378 | // Must be equal high, so compare the lows. |
| 1379 | __ cmpl(left_low, right_low); |
| 1380 | } |
| 1381 | // The last comparison might be unsigned. |
| 1382 | __ j(final_condition, true_label); |
| 1383 | } |
| 1384 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1385 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| 1386 | Label* true_target_in, |
| 1387 | Label* false_target_in) { |
| 1388 | // Generated branching requires both targets to be explicit. If either of the |
| 1389 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1390 | Label fallthrough_target; |
| 1391 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1392 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1393 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1394 | LocationSummary* locations = condition->GetLocations(); |
| 1395 | Location left = locations->InAt(0); |
| 1396 | Location right = locations->InAt(1); |
| 1397 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1399 | switch (type) { |
| 1400 | case Primitive::kPrimLong: |
| 1401 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1402 | break; |
| 1403 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1404 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1405 | GenerateFPJumps(condition, true_target, false_target); |
| 1406 | break; |
| 1407 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1409 | GenerateFPJumps(condition, true_target, false_target); |
| 1410 | break; |
| 1411 | default: |
| 1412 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1413 | } |
| 1414 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1415 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1416 | __ jmp(false_target); |
| 1417 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1418 | |
| 1419 | if (fallthrough_target.IsLinked()) { |
| 1420 | __ Bind(&fallthrough_target); |
| 1421 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1424 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1425 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1426 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1427 | // conditions if they are materialized due to the complex branching. |
| 1428 | return cond->IsCondition() && |
| 1429 | cond->GetNext() == branch && |
| 1430 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1431 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1432 | } |
| 1433 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1434 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1435 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1436 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1437 | Label* false_target) { |
| 1438 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1439 | |
| 1440 | if (true_target == nullptr && false_target == nullptr) { |
| 1441 | // Nothing to do. The code always falls through. |
| 1442 | return; |
| 1443 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1444 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1445 | if (cond->AsIntConstant()->IsOne()) { |
| 1446 | if (true_target != nullptr) { |
| 1447 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1448 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1449 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1451 | if (false_target != nullptr) { |
| 1452 | __ jmp(false_target); |
| 1453 | } |
| 1454 | } |
| 1455 | return; |
| 1456 | } |
| 1457 | |
| 1458 | // The following code generates these patterns: |
| 1459 | // (1) true_target == nullptr && false_target != nullptr |
| 1460 | // - opposite condition true => branch to false_target |
| 1461 | // (2) true_target != nullptr && false_target == nullptr |
| 1462 | // - condition true => branch to true_target |
| 1463 | // (3) true_target != nullptr && false_target != nullptr |
| 1464 | // - condition true => branch to true_target |
| 1465 | // - branch to false_target |
| 1466 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1467 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1468 | if (true_target == nullptr) { |
| 1469 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1470 | } else { |
| 1471 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1472 | } |
| 1473 | } else { |
| 1474 | // Materialized condition, compare against 0. |
| 1475 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1476 | if (lhs.IsRegister()) { |
| 1477 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1478 | } else { |
| 1479 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1480 | } |
| 1481 | if (true_target == nullptr) { |
| 1482 | __ j(kEqual, false_target); |
| 1483 | } else { |
| 1484 | __ j(kNotEqual, true_target); |
| 1485 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1486 | } |
| 1487 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1488 | // Condition has not been materialized, use its inputs as the comparison and |
| 1489 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1490 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1491 | |
| 1492 | // If this is a long or FP comparison that has been folded into |
| 1493 | // the HCondition, generate the comparison directly. |
| 1494 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1495 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1496 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1497 | return; |
| 1498 | } |
| 1499 | |
| 1500 | Location lhs = condition->GetLocations()->InAt(0); |
| 1501 | Location rhs = condition->GetLocations()->InAt(1); |
| 1502 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::VisitCondition). |
| 1503 | if (rhs.IsRegister()) { |
| 1504 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1505 | } else if (rhs.IsConstant()) { |
| 1506 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1507 | if (constant == 0) { |
| 1508 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1509 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1510 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1511 | } |
| 1512 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1513 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1514 | } |
| 1515 | if (true_target == nullptr) { |
| 1516 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1517 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1518 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1519 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1520 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1521 | |
| 1522 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1523 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1524 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1525 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1529 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1530 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1531 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1532 | locations->SetInAt(0, Location::Any()); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1537 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1538 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1539 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1540 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1541 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1542 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1543 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1547 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1548 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1549 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1550 | locations->SetInAt(0, Location::Any()); |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1555 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1556 | DeoptimizationSlowPathX86(deoptimize); |
| 1557 | codegen_->AddSlowPath(slow_path); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1558 | GenerateTestAndBranch(deoptimize, |
| 1559 | /* condition_input_index */ 0, |
| 1560 | slow_path->GetEntryLabel(), |
| 1561 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1564 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1565 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1568 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1569 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1572 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1573 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1576 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1577 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1580 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1581 | LocationSummary* locations = |
| 1582 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1583 | switch (store->InputAt(1)->GetType()) { |
| 1584 | case Primitive::kPrimBoolean: |
| 1585 | case Primitive::kPrimByte: |
| 1586 | case Primitive::kPrimChar: |
| 1587 | case Primitive::kPrimShort: |
| 1588 | case Primitive::kPrimInt: |
| 1589 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1590 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1591 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1592 | break; |
| 1593 | |
| 1594 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1595 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1596 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1597 | break; |
| 1598 | |
| 1599 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1600 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1601 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1604 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1607 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1608 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1609 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1610 | // Handle the long/FP comparisons made in instruction simplification. |
| 1611 | switch (cond->InputAt(0)->GetType()) { |
| 1612 | case Primitive::kPrimLong: { |
| 1613 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1614 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1615 | if (cond->NeedsMaterialization()) { |
| 1616 | locations->SetOut(Location::RequiresRegister()); |
| 1617 | } |
| 1618 | break; |
| 1619 | } |
| 1620 | case Primitive::kPrimFloat: |
| 1621 | case Primitive::kPrimDouble: { |
| 1622 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1623 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1624 | if (cond->NeedsMaterialization()) { |
| 1625 | locations->SetOut(Location::RequiresRegister()); |
| 1626 | } |
| 1627 | break; |
| 1628 | } |
| 1629 | default: |
| 1630 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1631 | locations->SetInAt(1, Location::Any()); |
| 1632 | if (cond->NeedsMaterialization()) { |
| 1633 | // We need a byte register. |
| 1634 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1635 | } |
| 1636 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1637 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1640 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1641 | if (!cond->NeedsMaterialization()) { |
| 1642 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1643 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1644 | |
| 1645 | LocationSummary* locations = cond->GetLocations(); |
| 1646 | Location lhs = locations->InAt(0); |
| 1647 | Location rhs = locations->InAt(1); |
| 1648 | Register reg = locations->Out().AsRegister<Register>(); |
| 1649 | Label true_label, false_label; |
| 1650 | |
| 1651 | switch (cond->InputAt(0)->GetType()) { |
| 1652 | default: { |
| 1653 | // Integer case. |
| 1654 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1655 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1656 | __ xorl(reg, reg); |
| 1657 | |
| 1658 | if (rhs.IsRegister()) { |
| 1659 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1660 | } else if (rhs.IsConstant()) { |
| 1661 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1662 | if (constant == 0) { |
| 1663 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1664 | } else { |
| 1665 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1666 | } |
| 1667 | } else { |
| 1668 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1669 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1670 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | return; |
| 1672 | } |
| 1673 | case Primitive::kPrimLong: |
| 1674 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1675 | break; |
| 1676 | case Primitive::kPrimFloat: |
| 1677 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1678 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1679 | break; |
| 1680 | case Primitive::kPrimDouble: |
| 1681 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1682 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1683 | break; |
| 1684 | } |
| 1685 | |
| 1686 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1687 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1688 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1689 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1690 | __ Bind(&false_label); |
| 1691 | __ xorl(reg, reg); |
| 1692 | __ jmp(&done_label); |
| 1693 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1694 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 | __ Bind(&true_label); |
| 1696 | __ movl(reg, Immediate(1)); |
| 1697 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1701 | VisitCondition(comp); |
| 1702 | } |
| 1703 | |
| 1704 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1705 | VisitCondition(comp); |
| 1706 | } |
| 1707 | |
| 1708 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1709 | VisitCondition(comp); |
| 1710 | } |
| 1711 | |
| 1712 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1713 | VisitCondition(comp); |
| 1714 | } |
| 1715 | |
| 1716 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1717 | VisitCondition(comp); |
| 1718 | } |
| 1719 | |
| 1720 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1721 | VisitCondition(comp); |
| 1722 | } |
| 1723 | |
| 1724 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1725 | VisitCondition(comp); |
| 1726 | } |
| 1727 | |
| 1728 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1729 | VisitCondition(comp); |
| 1730 | } |
| 1731 | |
| 1732 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1733 | VisitCondition(comp); |
| 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1737 | VisitCondition(comp); |
| 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1741 | VisitCondition(comp); |
| 1742 | } |
| 1743 | |
| 1744 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1745 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1748 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
| 1749 | VisitCondition(comp); |
| 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
| 1753 | VisitCondition(comp); |
| 1754 | } |
| 1755 | |
| 1756 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1757 | VisitCondition(comp); |
| 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
| 1761 | VisitCondition(comp); |
| 1762 | } |
| 1763 | |
| 1764 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
| 1765 | VisitCondition(comp); |
| 1766 | } |
| 1767 | |
| 1768 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
| 1769 | VisitCondition(comp); |
| 1770 | } |
| 1771 | |
| 1772 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1773 | VisitCondition(comp); |
| 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
| 1777 | VisitCondition(comp); |
| 1778 | } |
| 1779 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1780 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1781 | LocationSummary* locations = |
| 1782 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1783 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1786 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1787 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1790 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1791 | LocationSummary* locations = |
| 1792 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1793 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1794 | } |
| 1795 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1796 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1797 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1800 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1801 | LocationSummary* locations = |
| 1802 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1803 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1804 | } |
| 1805 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1806 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1807 | // Will be generated at use site. |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1810 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1811 | LocationSummary* locations = |
| 1812 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1813 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1814 | } |
| 1815 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1816 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1817 | // Will be generated at use site. |
| 1818 | } |
| 1819 | |
| 1820 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1821 | LocationSummary* locations = |
| 1822 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1823 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1824 | } |
| 1825 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1826 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1827 | // Will be generated at use site. |
| 1828 | } |
| 1829 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1830 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1831 | memory_barrier->SetLocations(nullptr); |
| 1832 | } |
| 1833 | |
| 1834 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1835 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1836 | } |
| 1837 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1838 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1839 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1842 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1843 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1846 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1847 | LocationSummary* locations = |
| 1848 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1849 | switch (ret->InputAt(0)->GetType()) { |
| 1850 | case Primitive::kPrimBoolean: |
| 1851 | case Primitive::kPrimByte: |
| 1852 | case Primitive::kPrimChar: |
| 1853 | case Primitive::kPrimShort: |
| 1854 | case Primitive::kPrimInt: |
| 1855 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1856 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1857 | break; |
| 1858 | |
| 1859 | case Primitive::kPrimLong: |
| 1860 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1861 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1862 | break; |
| 1863 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1864 | case Primitive::kPrimFloat: |
| 1865 | case Primitive::kPrimDouble: |
| 1866 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1867 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1868 | break; |
| 1869 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1870 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1871 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1872 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1875 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1876 | if (kIsDebugBuild) { |
| 1877 | switch (ret->InputAt(0)->GetType()) { |
| 1878 | case Primitive::kPrimBoolean: |
| 1879 | case Primitive::kPrimByte: |
| 1880 | case Primitive::kPrimChar: |
| 1881 | case Primitive::kPrimShort: |
| 1882 | case Primitive::kPrimInt: |
| 1883 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1884 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1885 | break; |
| 1886 | |
| 1887 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1888 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1889 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1890 | break; |
| 1891 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1892 | case Primitive::kPrimFloat: |
| 1893 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1894 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1895 | break; |
| 1896 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1897 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1898 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1899 | } |
| 1900 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1901 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1904 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1905 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1906 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1907 | // the method_idx. |
| 1908 | HandleInvoke(invoke); |
| 1909 | } |
| 1910 | |
| 1911 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1912 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1913 | } |
| 1914 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1915 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1916 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1917 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1918 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1919 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1920 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1921 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1922 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1923 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1924 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1925 | return; |
| 1926 | } |
| 1927 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1928 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1929 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1930 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1931 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1932 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1935 | if (codegen_->IsBaseline()) { |
| 1936 | // Baseline does not have enough registers if the current method also |
| 1937 | // needs a register. We therefore do not require a register for it, and let |
| 1938 | // the code generation of the invoke handle it. |
| 1939 | LocationSummary* locations = invoke->GetLocations(); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1940 | Location location = locations->InAt(invoke->GetSpecialInputIndex()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1941 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1942 | locations->SetInAt(invoke->GetSpecialInputIndex(), Location::NoLocation()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1943 | } |
| 1944 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1945 | } |
| 1946 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1947 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1948 | if (invoke->GetLocations()->Intrinsified()) { |
| 1949 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1950 | intrinsic.Dispatch(invoke); |
| 1951 | return true; |
| 1952 | } |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1956 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1957 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1958 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1959 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1960 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1961 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1962 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1963 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1964 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1965 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1966 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1967 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1968 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1972 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1973 | if (intrinsic.TryDispatch(invoke)) { |
| 1974 | return; |
| 1975 | } |
| 1976 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1977 | HandleInvoke(invoke); |
| 1978 | } |
| 1979 | |
| 1980 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1981 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1982 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1985 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1986 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1987 | return; |
| 1988 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1989 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1990 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1991 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1992 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1995 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1996 | // This call to HandleInvoke allocates a temporary (core) register |
| 1997 | // which is also used to transfer the hidden argument from FP to |
| 1998 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1999 | HandleInvoke(invoke); |
| 2000 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2001 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2005 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2006 | LocationSummary* locations = invoke->GetLocations(); |
| 2007 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2008 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2009 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2010 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2011 | Location receiver = locations->InAt(0); |
| 2012 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2013 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2014 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2015 | // won't be modified thereafter, before the `call` instruction. |
| 2016 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2017 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2018 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2019 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2020 | if (receiver.IsStackSlot()) { |
| 2021 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2022 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2023 | __ movl(temp, Address(temp, class_offset)); |
| 2024 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2025 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2026 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2027 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2028 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2029 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2030 | // emit a read barrier for the previous class reference load. |
| 2031 | // However this is not required in practice, as this is an |
| 2032 | // intermediate/temporary reference and because the current |
| 2033 | // concurrent copying collector keeps the from-space memory |
| 2034 | // intact/accessible until the end of the marking phase (the |
| 2035 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2036 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2037 | // temp = temp->GetImtEntryAt(method_offset); |
| 2038 | __ movl(temp, Address(temp, method_offset)); |
| 2039 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2040 | __ call(Address(temp, |
| 2041 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2042 | |
| 2043 | DCHECK(!codegen_->IsLeafMethod()); |
| 2044 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2045 | } |
| 2046 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2047 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2048 | LocationSummary* locations = |
| 2049 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2050 | switch (neg->GetResultType()) { |
| 2051 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2052 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2053 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2054 | locations->SetOut(Location::SameAsFirstInput()); |
| 2055 | break; |
| 2056 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2057 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2058 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2059 | locations->SetOut(Location::SameAsFirstInput()); |
| 2060 | locations->AddTemp(Location::RequiresRegister()); |
| 2061 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2062 | break; |
| 2063 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2064 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2065 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2066 | locations->SetOut(Location::SameAsFirstInput()); |
| 2067 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2068 | break; |
| 2069 | |
| 2070 | default: |
| 2071 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2076 | LocationSummary* locations = neg->GetLocations(); |
| 2077 | Location out = locations->Out(); |
| 2078 | Location in = locations->InAt(0); |
| 2079 | switch (neg->GetResultType()) { |
| 2080 | case Primitive::kPrimInt: |
| 2081 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2082 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2083 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2084 | break; |
| 2085 | |
| 2086 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2087 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2088 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2089 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2090 | // Negation is similar to subtraction from zero. The least |
| 2091 | // significant byte triggers a borrow when it is different from |
| 2092 | // zero; to take it into account, add 1 to the most significant |
| 2093 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2094 | // operation. |
| 2095 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2096 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2097 | break; |
| 2098 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2099 | case Primitive::kPrimFloat: { |
| 2100 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2101 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2102 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2103 | // Implement float negation with an exclusive or with value |
| 2104 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2105 | // single-precision floating-point number). |
| 2106 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2107 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2108 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2109 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2110 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2111 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimDouble: { |
| 2113 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2114 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2115 | // Implement double negation with an exclusive or with value |
| 2116 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2117 | // a double-precision floating-point number). |
| 2118 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2119 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2120 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2121 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2122 | |
| 2123 | default: |
| 2124 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2125 | } |
| 2126 | } |
| 2127 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2128 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2129 | Primitive::Type result_type = conversion->GetResultType(); |
| 2130 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2131 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2132 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2133 | // The float-to-long and double-to-long type conversions rely on a |
| 2134 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2135 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2137 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2138 | ? LocationSummary::kCall |
| 2139 | : LocationSummary::kNoCall; |
| 2140 | LocationSummary* locations = |
| 2141 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2142 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2143 | // The Java language does not allow treating boolean as an integral type but |
| 2144 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2145 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2146 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2147 | case Primitive::kPrimByte: |
| 2148 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2149 | case Primitive::kPrimBoolean: |
| 2150 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2151 | case Primitive::kPrimShort: |
| 2152 | case Primitive::kPrimInt: |
| 2153 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2154 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2155 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2156 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2157 | // the validation of the linear scan implementation |
| 2158 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2159 | break; |
| 2160 | |
| 2161 | default: |
| 2162 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2163 | << " to " << result_type; |
| 2164 | } |
| 2165 | break; |
| 2166 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2167 | case Primitive::kPrimShort: |
| 2168 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2169 | case Primitive::kPrimBoolean: |
| 2170 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2171 | case Primitive::kPrimByte: |
| 2172 | case Primitive::kPrimInt: |
| 2173 | case Primitive::kPrimChar: |
| 2174 | // Processing a Dex `int-to-short' instruction. |
| 2175 | locations->SetInAt(0, Location::Any()); |
| 2176 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2177 | break; |
| 2178 | |
| 2179 | default: |
| 2180 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2181 | << " to " << result_type; |
| 2182 | } |
| 2183 | break; |
| 2184 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2185 | case Primitive::kPrimInt: |
| 2186 | switch (input_type) { |
| 2187 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2188 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2189 | locations->SetInAt(0, Location::Any()); |
| 2190 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2191 | break; |
| 2192 | |
| 2193 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2194 | // Processing a Dex `float-to-int' instruction. |
| 2195 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2196 | locations->SetOut(Location::RequiresRegister()); |
| 2197 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2198 | break; |
| 2199 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2200 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2201 | // Processing a Dex `double-to-int' instruction. |
| 2202 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2203 | locations->SetOut(Location::RequiresRegister()); |
| 2204 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | |
| 2207 | default: |
| 2208 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2209 | << " to " << result_type; |
| 2210 | } |
| 2211 | break; |
| 2212 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimLong: |
| 2214 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2215 | case Primitive::kPrimBoolean: |
| 2216 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2217 | case Primitive::kPrimByte: |
| 2218 | case Primitive::kPrimShort: |
| 2219 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2221 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2222 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2223 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2224 | break; |
| 2225 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2226 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2227 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2228 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2229 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2230 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2231 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2232 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2233 | // The runtime helper puts the result in EAX, EDX. |
| 2234 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2235 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2236 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2237 | |
| 2238 | default: |
| 2239 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2240 | << " to " << result_type; |
| 2241 | } |
| 2242 | break; |
| 2243 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2244 | case Primitive::kPrimChar: |
| 2245 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimBoolean: |
| 2247 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimByte: |
| 2249 | case Primitive::kPrimShort: |
| 2250 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2251 | // Processing a Dex `int-to-char' instruction. |
| 2252 | locations->SetInAt(0, Location::Any()); |
| 2253 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2254 | break; |
| 2255 | |
| 2256 | default: |
| 2257 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2258 | << " to " << result_type; |
| 2259 | } |
| 2260 | break; |
| 2261 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2262 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2263 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2264 | case Primitive::kPrimBoolean: |
| 2265 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimByte: |
| 2267 | case Primitive::kPrimShort: |
| 2268 | case Primitive::kPrimInt: |
| 2269 | case Primitive::kPrimChar: |
| 2270 | // Processing a Dex `int-to-float' instruction. |
| 2271 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2272 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2273 | break; |
| 2274 | |
| 2275 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2276 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2277 | locations->SetInAt(0, Location::Any()); |
| 2278 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2279 | break; |
| 2280 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2282 | // Processing a Dex `double-to-float' instruction. |
| 2283 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2284 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2285 | break; |
| 2286 | |
| 2287 | default: |
| 2288 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2289 | << " to " << result_type; |
| 2290 | }; |
| 2291 | break; |
| 2292 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2293 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2294 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2295 | case Primitive::kPrimBoolean: |
| 2296 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2297 | case Primitive::kPrimByte: |
| 2298 | case Primitive::kPrimShort: |
| 2299 | case Primitive::kPrimInt: |
| 2300 | case Primitive::kPrimChar: |
| 2301 | // Processing a Dex `int-to-double' instruction. |
| 2302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2303 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2304 | break; |
| 2305 | |
| 2306 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2307 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2308 | locations->SetInAt(0, Location::Any()); |
| 2309 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2310 | break; |
| 2311 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2313 | // Processing a Dex `float-to-double' instruction. |
| 2314 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2315 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2316 | break; |
| 2317 | |
| 2318 | default: |
| 2319 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2320 | << " to " << result_type; |
| 2321 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2322 | break; |
| 2323 | |
| 2324 | default: |
| 2325 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2326 | << " to " << result_type; |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2331 | LocationSummary* locations = conversion->GetLocations(); |
| 2332 | Location out = locations->Out(); |
| 2333 | Location in = locations->InAt(0); |
| 2334 | Primitive::Type result_type = conversion->GetResultType(); |
| 2335 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2336 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2337 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2338 | case Primitive::kPrimByte: |
| 2339 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2340 | case Primitive::kPrimBoolean: |
| 2341 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2342 | case Primitive::kPrimShort: |
| 2343 | case Primitive::kPrimInt: |
| 2344 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2345 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2346 | if (in.IsRegister()) { |
| 2347 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2348 | } else { |
| 2349 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2350 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2351 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2352 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | |
| 2355 | default: |
| 2356 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2357 | << " to " << result_type; |
| 2358 | } |
| 2359 | break; |
| 2360 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimShort: |
| 2362 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimBoolean: |
| 2364 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimByte: |
| 2366 | case Primitive::kPrimInt: |
| 2367 | case Primitive::kPrimChar: |
| 2368 | // Processing a Dex `int-to-short' instruction. |
| 2369 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2370 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2371 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2372 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2373 | } else { |
| 2374 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2375 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2376 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2377 | } |
| 2378 | break; |
| 2379 | |
| 2380 | default: |
| 2381 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2382 | << " to " << result_type; |
| 2383 | } |
| 2384 | break; |
| 2385 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2386 | case Primitive::kPrimInt: |
| 2387 | switch (input_type) { |
| 2388 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2389 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2390 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2391 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2392 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2393 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2394 | } else { |
| 2395 | DCHECK(in.IsConstant()); |
| 2396 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2397 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2398 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2399 | } |
| 2400 | break; |
| 2401 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2402 | case Primitive::kPrimFloat: { |
| 2403 | // Processing a Dex `float-to-int' instruction. |
| 2404 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2405 | Register output = out.AsRegister<Register>(); |
| 2406 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2407 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2408 | |
| 2409 | __ movl(output, Immediate(kPrimIntMax)); |
| 2410 | // temp = int-to-float(output) |
| 2411 | __ cvtsi2ss(temp, output); |
| 2412 | // if input >= temp goto done |
| 2413 | __ comiss(input, temp); |
| 2414 | __ j(kAboveEqual, &done); |
| 2415 | // if input == NaN goto nan |
| 2416 | __ j(kUnordered, &nan); |
| 2417 | // output = float-to-int-truncate(input) |
| 2418 | __ cvttss2si(output, input); |
| 2419 | __ jmp(&done); |
| 2420 | __ Bind(&nan); |
| 2421 | // output = 0 |
| 2422 | __ xorl(output, output); |
| 2423 | __ Bind(&done); |
| 2424 | break; |
| 2425 | } |
| 2426 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimDouble: { |
| 2428 | // Processing a Dex `double-to-int' instruction. |
| 2429 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2430 | Register output = out.AsRegister<Register>(); |
| 2431 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2432 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2433 | |
| 2434 | __ movl(output, Immediate(kPrimIntMax)); |
| 2435 | // temp = int-to-double(output) |
| 2436 | __ cvtsi2sd(temp, output); |
| 2437 | // if input >= temp goto done |
| 2438 | __ comisd(input, temp); |
| 2439 | __ j(kAboveEqual, &done); |
| 2440 | // if input == NaN goto nan |
| 2441 | __ j(kUnordered, &nan); |
| 2442 | // output = double-to-int-truncate(input) |
| 2443 | __ cvttsd2si(output, input); |
| 2444 | __ jmp(&done); |
| 2445 | __ Bind(&nan); |
| 2446 | // output = 0 |
| 2447 | __ xorl(output, output); |
| 2448 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2449 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2450 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2451 | |
| 2452 | default: |
| 2453 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2454 | << " to " << result_type; |
| 2455 | } |
| 2456 | break; |
| 2457 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimLong: |
| 2459 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimBoolean: |
| 2461 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2462 | case Primitive::kPrimByte: |
| 2463 | case Primitive::kPrimShort: |
| 2464 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2466 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2467 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2468 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2469 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2470 | __ cdq(); |
| 2471 | break; |
| 2472 | |
| 2473 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2474 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2475 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2476 | conversion, |
| 2477 | conversion->GetDexPc(), |
| 2478 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2479 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2480 | break; |
| 2481 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2482 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2483 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2484 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2485 | conversion, |
| 2486 | conversion->GetDexPc(), |
| 2487 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2488 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2489 | break; |
| 2490 | |
| 2491 | default: |
| 2492 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2493 | << " to " << result_type; |
| 2494 | } |
| 2495 | break; |
| 2496 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimChar: |
| 2498 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimBoolean: |
| 2500 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2501 | case Primitive::kPrimByte: |
| 2502 | case Primitive::kPrimShort: |
| 2503 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2504 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2505 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2506 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2507 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2508 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2509 | } else { |
| 2510 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2511 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2512 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2513 | } |
| 2514 | break; |
| 2515 | |
| 2516 | default: |
| 2517 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2518 | << " to " << result_type; |
| 2519 | } |
| 2520 | break; |
| 2521 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2522 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2523 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2524 | case Primitive::kPrimBoolean: |
| 2525 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimByte: |
| 2527 | case Primitive::kPrimShort: |
| 2528 | case Primitive::kPrimInt: |
| 2529 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2530 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2531 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2532 | break; |
| 2533 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimLong: { |
| 2535 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2536 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2537 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2538 | // Create stack space for the call to |
| 2539 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2540 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2541 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2542 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2543 | __ subl(ESP, Immediate(adjustment)); |
| 2544 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2545 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2546 | // Load the value to the FP stack, using temporaries if needed. |
| 2547 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2548 | |
| 2549 | if (out.IsStackSlot()) { |
| 2550 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2551 | } else { |
| 2552 | __ fstps(Address(ESP, 0)); |
| 2553 | Location stack_temp = Location::StackSlot(0); |
| 2554 | codegen_->Move32(out, stack_temp); |
| 2555 | } |
| 2556 | |
| 2557 | // Remove the temporary stack space we allocated. |
| 2558 | if (adjustment != 0) { |
| 2559 | __ addl(ESP, Immediate(adjustment)); |
| 2560 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2561 | break; |
| 2562 | } |
| 2563 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2565 | // Processing a Dex `double-to-float' instruction. |
| 2566 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2571 | << " to " << result_type; |
| 2572 | }; |
| 2573 | break; |
| 2574 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2575 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2576 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2577 | case Primitive::kPrimBoolean: |
| 2578 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2579 | case Primitive::kPrimByte: |
| 2580 | case Primitive::kPrimShort: |
| 2581 | case Primitive::kPrimInt: |
| 2582 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2583 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2584 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimLong: { |
| 2588 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2589 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2590 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2591 | // Create stack space for the call to |
| 2592 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2593 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2594 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2595 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2596 | __ subl(ESP, Immediate(adjustment)); |
| 2597 | } |
| 2598 | |
| 2599 | // Load the value to the FP stack, using temporaries if needed. |
| 2600 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2601 | |
| 2602 | if (out.IsDoubleStackSlot()) { |
| 2603 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2604 | } else { |
| 2605 | __ fstpl(Address(ESP, 0)); |
| 2606 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2607 | codegen_->Move64(out, stack_temp); |
| 2608 | } |
| 2609 | |
| 2610 | // Remove the temporary stack space we allocated. |
| 2611 | if (adjustment != 0) { |
| 2612 | __ addl(ESP, Immediate(adjustment)); |
| 2613 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2614 | break; |
| 2615 | } |
| 2616 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2617 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2618 | // Processing a Dex `float-to-double' instruction. |
| 2619 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2620 | break; |
| 2621 | |
| 2622 | default: |
| 2623 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2624 | << " to " << result_type; |
| 2625 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | |
| 2628 | default: |
| 2629 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2630 | << " to " << result_type; |
| 2631 | } |
| 2632 | } |
| 2633 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2634 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2635 | LocationSummary* locations = |
| 2636 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2637 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2638 | case Primitive::kPrimInt: { |
| 2639 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2640 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2641 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2642 | break; |
| 2643 | } |
| 2644 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2645 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2647 | locations->SetInAt(1, Location::Any()); |
| 2648 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2649 | break; |
| 2650 | } |
| 2651 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2652 | case Primitive::kPrimFloat: |
| 2653 | case Primitive::kPrimDouble: { |
| 2654 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2655 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2656 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2657 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2658 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2659 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2660 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2661 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2662 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2663 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2667 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2668 | Location first = locations->InAt(0); |
| 2669 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2670 | Location out = locations->Out(); |
| 2671 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2672 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2673 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2674 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2675 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2676 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2677 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2678 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2679 | } else { |
| 2680 | __ leal(out.AsRegister<Register>(), Address( |
| 2681 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2682 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2683 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2684 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2685 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2686 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2687 | } else { |
| 2688 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2689 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2690 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2691 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2692 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2693 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2694 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2698 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2699 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2700 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2701 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2702 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2703 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2704 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2705 | } else { |
| 2706 | DCHECK(second.IsConstant()) << second; |
| 2707 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2708 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2709 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2710 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2711 | break; |
| 2712 | } |
| 2713 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2714 | case Primitive::kPrimFloat: { |
| 2715 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2716 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2717 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2718 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2719 | DCHECK(!const_area->NeedsMaterialization()); |
| 2720 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2721 | codegen_->LiteralFloatAddress( |
| 2722 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2723 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2724 | } else { |
| 2725 | DCHECK(second.IsStackSlot()); |
| 2726 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2727 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2728 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | case Primitive::kPrimDouble: { |
| 2732 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2733 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2734 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2735 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2736 | DCHECK(!const_area->NeedsMaterialization()); |
| 2737 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2738 | codegen_->LiteralDoubleAddress( |
| 2739 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2740 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2741 | } else { |
| 2742 | DCHECK(second.IsDoubleStackSlot()); |
| 2743 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2744 | } |
| 2745 | break; |
| 2746 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2747 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2748 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2749 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2753 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2754 | LocationSummary* locations = |
| 2755 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2756 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2757 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2758 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2759 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2760 | locations->SetInAt(1, Location::Any()); |
| 2761 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2762 | break; |
| 2763 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2764 | case Primitive::kPrimFloat: |
| 2765 | case Primitive::kPrimDouble: { |
| 2766 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2767 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2768 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2769 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2770 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2771 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2772 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2773 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2774 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2778 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2779 | Location first = locations->InAt(0); |
| 2780 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2781 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2782 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2783 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2784 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2785 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2786 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2787 | __ subl(first.AsRegister<Register>(), |
| 2788 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2789 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2790 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2791 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2792 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2796 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2797 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2798 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2799 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2800 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2801 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2802 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2803 | } else { |
| 2804 | DCHECK(second.IsConstant()) << second; |
| 2805 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2806 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2807 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2808 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2809 | break; |
| 2810 | } |
| 2811 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2812 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2813 | if (second.IsFpuRegister()) { |
| 2814 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2815 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2816 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2817 | DCHECK(!const_area->NeedsMaterialization()); |
| 2818 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2819 | codegen_->LiteralFloatAddress( |
| 2820 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2821 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2822 | } else { |
| 2823 | DCHECK(second.IsStackSlot()); |
| 2824 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2825 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2826 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2830 | if (second.IsFpuRegister()) { |
| 2831 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2832 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2833 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2834 | DCHECK(!const_area->NeedsMaterialization()); |
| 2835 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2836 | codegen_->LiteralDoubleAddress( |
| 2837 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2838 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2839 | } else { |
| 2840 | DCHECK(second.IsDoubleStackSlot()); |
| 2841 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2842 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2843 | break; |
| 2844 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2845 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2846 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2847 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2848 | } |
| 2849 | } |
| 2850 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2851 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2852 | LocationSummary* locations = |
| 2853 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2854 | switch (mul->GetResultType()) { |
| 2855 | case Primitive::kPrimInt: |
| 2856 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2857 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2858 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2859 | // Can use 3 operand multiply. |
| 2860 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2861 | } else { |
| 2862 | locations->SetOut(Location::SameAsFirstInput()); |
| 2863 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2864 | break; |
| 2865 | case Primitive::kPrimLong: { |
| 2866 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2867 | locations->SetInAt(1, Location::Any()); |
| 2868 | locations->SetOut(Location::SameAsFirstInput()); |
| 2869 | // Needed for imul on 32bits with 64bits output. |
| 2870 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2871 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2872 | break; |
| 2873 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2874 | case Primitive::kPrimFloat: |
| 2875 | case Primitive::kPrimDouble: { |
| 2876 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2877 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2878 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2879 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2880 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2881 | |
| 2882 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2883 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2888 | LocationSummary* locations = mul->GetLocations(); |
| 2889 | Location first = locations->InAt(0); |
| 2890 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2891 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2892 | |
| 2893 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2894 | case Primitive::kPrimInt: |
| 2895 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2896 | // problems where the output may not be the same as the first operand. |
| 2897 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2898 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2899 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2900 | } else if (second.IsRegister()) { |
| 2901 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2903 | } else { |
| 2904 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2905 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2906 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2907 | } |
| 2908 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2909 | |
| 2910 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2911 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2912 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2913 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2914 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2915 | |
| 2916 | DCHECK_EQ(EAX, eax); |
| 2917 | DCHECK_EQ(EDX, edx); |
| 2918 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2919 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2920 | // output: in1 |
| 2921 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2922 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2923 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2924 | if (second.IsConstant()) { |
| 2925 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2926 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2927 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2928 | int32_t low_value = Low32Bits(value); |
| 2929 | int32_t high_value = High32Bits(value); |
| 2930 | Immediate low(low_value); |
| 2931 | Immediate high(high_value); |
| 2932 | |
| 2933 | __ movl(eax, high); |
| 2934 | // eax <- in1.lo * in2.hi |
| 2935 | __ imull(eax, in1_lo); |
| 2936 | // in1.hi <- in1.hi * in2.lo |
| 2937 | __ imull(in1_hi, low); |
| 2938 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2939 | __ addl(in1_hi, eax); |
| 2940 | // move in2_lo to eax to prepare for double precision |
| 2941 | __ movl(eax, low); |
| 2942 | // edx:eax <- in1.lo * in2.lo |
| 2943 | __ mull(in1_lo); |
| 2944 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2945 | __ addl(in1_hi, edx); |
| 2946 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2947 | __ movl(in1_lo, eax); |
| 2948 | } else if (second.IsRegisterPair()) { |
| 2949 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2950 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2951 | |
| 2952 | __ movl(eax, in2_hi); |
| 2953 | // eax <- in1.lo * in2.hi |
| 2954 | __ imull(eax, in1_lo); |
| 2955 | // in1.hi <- in1.hi * in2.lo |
| 2956 | __ imull(in1_hi, in2_lo); |
| 2957 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2958 | __ addl(in1_hi, eax); |
| 2959 | // move in1_lo to eax to prepare for double precision |
| 2960 | __ movl(eax, in1_lo); |
| 2961 | // edx:eax <- in1.lo * in2.lo |
| 2962 | __ mull(in2_lo); |
| 2963 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2964 | __ addl(in1_hi, edx); |
| 2965 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2966 | __ movl(in1_lo, eax); |
| 2967 | } else { |
| 2968 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2969 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2970 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2971 | |
| 2972 | __ movl(eax, in2_hi); |
| 2973 | // eax <- in1.lo * in2.hi |
| 2974 | __ imull(eax, in1_lo); |
| 2975 | // in1.hi <- in1.hi * in2.lo |
| 2976 | __ imull(in1_hi, in2_lo); |
| 2977 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2978 | __ addl(in1_hi, eax); |
| 2979 | // move in1_lo to eax to prepare for double precision |
| 2980 | __ movl(eax, in1_lo); |
| 2981 | // edx:eax <- in1.lo * in2.lo |
| 2982 | __ mull(in2_lo); |
| 2983 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2984 | __ addl(in1_hi, edx); |
| 2985 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2986 | __ movl(in1_lo, eax); |
| 2987 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2988 | |
| 2989 | break; |
| 2990 | } |
| 2991 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2992 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2993 | DCHECK(first.Equals(locations->Out())); |
| 2994 | if (second.IsFpuRegister()) { |
| 2995 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2996 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2997 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2998 | DCHECK(!const_area->NeedsMaterialization()); |
| 2999 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3000 | codegen_->LiteralFloatAddress( |
| 3001 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3002 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3003 | } else { |
| 3004 | DCHECK(second.IsStackSlot()); |
| 3005 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3006 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3007 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3011 | DCHECK(first.Equals(locations->Out())); |
| 3012 | if (second.IsFpuRegister()) { |
| 3013 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3014 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3015 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3016 | DCHECK(!const_area->NeedsMaterialization()); |
| 3017 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3018 | codegen_->LiteralDoubleAddress( |
| 3019 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3020 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3021 | } else { |
| 3022 | DCHECK(second.IsDoubleStackSlot()); |
| 3023 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3024 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3025 | break; |
| 3026 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3027 | |
| 3028 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3029 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3030 | } |
| 3031 | } |
| 3032 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3033 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3034 | uint32_t temp_offset, |
| 3035 | uint32_t stack_adjustment, |
| 3036 | bool is_fp, |
| 3037 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3038 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3039 | DCHECK(!is_wide); |
| 3040 | if (is_fp) { |
| 3041 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3042 | } else { |
| 3043 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3044 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3045 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3046 | DCHECK(is_wide); |
| 3047 | if (is_fp) { |
| 3048 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3049 | } else { |
| 3050 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3051 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3052 | } else { |
| 3053 | // 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] | 3054 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3055 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3056 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3057 | if (is_fp) { |
| 3058 | __ flds(Address(ESP, temp_offset)); |
| 3059 | } else { |
| 3060 | __ filds(Address(ESP, temp_offset)); |
| 3061 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3062 | } else { |
| 3063 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3064 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3065 | if (is_fp) { |
| 3066 | __ fldl(Address(ESP, temp_offset)); |
| 3067 | } else { |
| 3068 | __ fildl(Address(ESP, temp_offset)); |
| 3069 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3070 | } |
| 3071 | } |
| 3072 | } |
| 3073 | |
| 3074 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3075 | Primitive::Type type = rem->GetResultType(); |
| 3076 | bool is_float = type == Primitive::kPrimFloat; |
| 3077 | size_t elem_size = Primitive::ComponentSize(type); |
| 3078 | LocationSummary* locations = rem->GetLocations(); |
| 3079 | Location first = locations->InAt(0); |
| 3080 | Location second = locations->InAt(1); |
| 3081 | Location out = locations->Out(); |
| 3082 | |
| 3083 | // Create stack space for 2 elements. |
| 3084 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3085 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3086 | |
| 3087 | // 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] | 3088 | const bool is_wide = !is_float; |
| 3089 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3090 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3091 | |
| 3092 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3093 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3094 | __ Bind(&retry); |
| 3095 | __ fprem(); |
| 3096 | |
| 3097 | // Move FP status to AX. |
| 3098 | __ fstsw(); |
| 3099 | |
| 3100 | // And see if the argument reduction is complete. This is signaled by the |
| 3101 | // C2 FPU flag bit set to 0. |
| 3102 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3103 | __ j(kNotEqual, &retry); |
| 3104 | |
| 3105 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3106 | // Store FP top of stack to real stack. |
| 3107 | if (is_float) { |
| 3108 | __ fsts(Address(ESP, 0)); |
| 3109 | } else { |
| 3110 | __ fstl(Address(ESP, 0)); |
| 3111 | } |
| 3112 | |
| 3113 | // Pop the 2 items from the FP stack. |
| 3114 | __ fucompp(); |
| 3115 | |
| 3116 | // Load the value from the stack into an XMM register. |
| 3117 | DCHECK(out.IsFpuRegister()) << out; |
| 3118 | if (is_float) { |
| 3119 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3120 | } else { |
| 3121 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3122 | } |
| 3123 | |
| 3124 | // And remove the temporary stack space we allocated. |
| 3125 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3126 | } |
| 3127 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3128 | |
| 3129 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3130 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3131 | |
| 3132 | LocationSummary* locations = instruction->GetLocations(); |
| 3133 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3134 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3135 | |
| 3136 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3137 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3138 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3139 | |
| 3140 | DCHECK(imm == 1 || imm == -1); |
| 3141 | |
| 3142 | if (instruction->IsRem()) { |
| 3143 | __ xorl(out_register, out_register); |
| 3144 | } else { |
| 3145 | __ movl(out_register, input_register); |
| 3146 | if (imm == -1) { |
| 3147 | __ negl(out_register); |
| 3148 | } |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3153 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3154 | LocationSummary* locations = instruction->GetLocations(); |
| 3155 | |
| 3156 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3157 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3158 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3159 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3160 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3161 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3162 | |
| 3163 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 3164 | __ testl(input_register, input_register); |
| 3165 | __ cmovl(kGreaterEqual, num, input_register); |
| 3166 | int shift = CTZ(imm); |
| 3167 | __ sarl(num, Immediate(shift)); |
| 3168 | |
| 3169 | if (imm < 0) { |
| 3170 | __ negl(num); |
| 3171 | } |
| 3172 | |
| 3173 | __ movl(out_register, num); |
| 3174 | } |
| 3175 | |
| 3176 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3177 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3178 | |
| 3179 | LocationSummary* locations = instruction->GetLocations(); |
| 3180 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3181 | |
| 3182 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3183 | Register out = locations->Out().AsRegister<Register>(); |
| 3184 | Register num; |
| 3185 | Register edx; |
| 3186 | |
| 3187 | if (instruction->IsDiv()) { |
| 3188 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3189 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3190 | } else { |
| 3191 | edx = locations->Out().AsRegister<Register>(); |
| 3192 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3193 | } |
| 3194 | |
| 3195 | DCHECK_EQ(EAX, eax); |
| 3196 | DCHECK_EQ(EDX, edx); |
| 3197 | if (instruction->IsDiv()) { |
| 3198 | DCHECK_EQ(EAX, out); |
| 3199 | } else { |
| 3200 | DCHECK_EQ(EDX, out); |
| 3201 | } |
| 3202 | |
| 3203 | int64_t magic; |
| 3204 | int shift; |
| 3205 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3206 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3207 | NearLabel ndiv; |
| 3208 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3209 | // If numerator is 0, the result is 0, no computation needed. |
| 3210 | __ testl(eax, eax); |
| 3211 | __ j(kNotEqual, &ndiv); |
| 3212 | |
| 3213 | __ xorl(out, out); |
| 3214 | __ jmp(&end); |
| 3215 | |
| 3216 | __ Bind(&ndiv); |
| 3217 | |
| 3218 | // Save the numerator. |
| 3219 | __ movl(num, eax); |
| 3220 | |
| 3221 | // EAX = magic |
| 3222 | __ movl(eax, Immediate(magic)); |
| 3223 | |
| 3224 | // EDX:EAX = magic * numerator |
| 3225 | __ imull(num); |
| 3226 | |
| 3227 | if (imm > 0 && magic < 0) { |
| 3228 | // EDX += num |
| 3229 | __ addl(edx, num); |
| 3230 | } else if (imm < 0 && magic > 0) { |
| 3231 | __ subl(edx, num); |
| 3232 | } |
| 3233 | |
| 3234 | // Shift if needed. |
| 3235 | if (shift != 0) { |
| 3236 | __ sarl(edx, Immediate(shift)); |
| 3237 | } |
| 3238 | |
| 3239 | // EDX += 1 if EDX < 0 |
| 3240 | __ movl(eax, edx); |
| 3241 | __ shrl(edx, Immediate(31)); |
| 3242 | __ addl(edx, eax); |
| 3243 | |
| 3244 | if (instruction->IsRem()) { |
| 3245 | __ movl(eax, num); |
| 3246 | __ imull(edx, Immediate(imm)); |
| 3247 | __ subl(eax, edx); |
| 3248 | __ movl(edx, eax); |
| 3249 | } else { |
| 3250 | __ movl(eax, edx); |
| 3251 | } |
| 3252 | __ Bind(&end); |
| 3253 | } |
| 3254 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3255 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3256 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3257 | |
| 3258 | LocationSummary* locations = instruction->GetLocations(); |
| 3259 | Location out = locations->Out(); |
| 3260 | Location first = locations->InAt(0); |
| 3261 | Location second = locations->InAt(1); |
| 3262 | bool is_div = instruction->IsDiv(); |
| 3263 | |
| 3264 | switch (instruction->GetResultType()) { |
| 3265 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3266 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3267 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3268 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3269 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3270 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3271 | |
| 3272 | if (imm == 0) { |
| 3273 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3274 | } else if (imm == 1 || imm == -1) { |
| 3275 | DivRemOneOrMinusOne(instruction); |
| 3276 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3277 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3278 | } else { |
| 3279 | DCHECK(imm <= -2 || imm >= 2); |
| 3280 | GenerateDivRemWithAnyConstant(instruction); |
| 3281 | } |
| 3282 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3283 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3284 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3285 | is_div); |
| 3286 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3287 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3288 | Register second_reg = second.AsRegister<Register>(); |
| 3289 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3290 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3291 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3292 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3293 | __ cmpl(second_reg, Immediate(-1)); |
| 3294 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3295 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3296 | // edx:eax <- sign-extended of eax |
| 3297 | __ cdq(); |
| 3298 | // eax = quotient, edx = remainder |
| 3299 | __ idivl(second_reg); |
| 3300 | __ Bind(slow_path->GetExitLabel()); |
| 3301 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3302 | break; |
| 3303 | } |
| 3304 | |
| 3305 | case Primitive::kPrimLong: { |
| 3306 | InvokeRuntimeCallingConvention calling_convention; |
| 3307 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3308 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3309 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3310 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3311 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3312 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3313 | |
| 3314 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3315 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3316 | instruction, |
| 3317 | instruction->GetDexPc(), |
| 3318 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3319 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3320 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3321 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3322 | instruction, |
| 3323 | instruction->GetDexPc(), |
| 3324 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3325 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3326 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | default: |
| 3331 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3332 | } |
| 3333 | } |
| 3334 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3335 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3336 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3337 | ? LocationSummary::kCall |
| 3338 | : LocationSummary::kNoCall; |
| 3339 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3340 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3341 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3342 | case Primitive::kPrimInt: { |
| 3343 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3344 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3345 | locations->SetOut(Location::SameAsFirstInput()); |
| 3346 | // Intel uses edx:eax as the dividend. |
| 3347 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3348 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3349 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3350 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3351 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3352 | locations->AddTemp(Location::RequiresRegister()); |
| 3353 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3354 | break; |
| 3355 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3356 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3357 | InvokeRuntimeCallingConvention calling_convention; |
| 3358 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3359 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3360 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3361 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3362 | // Runtime helper puts the result in EAX, EDX. |
| 3363 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3364 | break; |
| 3365 | } |
| 3366 | case Primitive::kPrimFloat: |
| 3367 | case Primitive::kPrimDouble: { |
| 3368 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3369 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3370 | locations->SetOut(Location::SameAsFirstInput()); |
| 3371 | break; |
| 3372 | } |
| 3373 | |
| 3374 | default: |
| 3375 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3376 | } |
| 3377 | } |
| 3378 | |
| 3379 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3380 | LocationSummary* locations = div->GetLocations(); |
| 3381 | Location first = locations->InAt(0); |
| 3382 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3383 | |
| 3384 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3385 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3386 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3387 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3388 | break; |
| 3389 | } |
| 3390 | |
| 3391 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3392 | if (second.IsFpuRegister()) { |
| 3393 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3394 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3395 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3396 | DCHECK(!const_area->NeedsMaterialization()); |
| 3397 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3398 | codegen_->LiteralFloatAddress( |
| 3399 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3400 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3401 | } else { |
| 3402 | DCHECK(second.IsStackSlot()); |
| 3403 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3404 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3405 | break; |
| 3406 | } |
| 3407 | |
| 3408 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3409 | if (second.IsFpuRegister()) { |
| 3410 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3411 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3412 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3413 | DCHECK(!const_area->NeedsMaterialization()); |
| 3414 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3415 | codegen_->LiteralDoubleAddress( |
| 3416 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3417 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3418 | } else { |
| 3419 | DCHECK(second.IsDoubleStackSlot()); |
| 3420 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3421 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3422 | break; |
| 3423 | } |
| 3424 | |
| 3425 | default: |
| 3426 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3427 | } |
| 3428 | } |
| 3429 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3430 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3431 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3432 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3433 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3434 | ? LocationSummary::kCall |
| 3435 | : LocationSummary::kNoCall; |
| 3436 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3437 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3438 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3439 | case Primitive::kPrimInt: { |
| 3440 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3441 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3442 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3443 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3444 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3445 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3446 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3447 | locations->AddTemp(Location::RequiresRegister()); |
| 3448 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3449 | break; |
| 3450 | } |
| 3451 | case Primitive::kPrimLong: { |
| 3452 | InvokeRuntimeCallingConvention calling_convention; |
| 3453 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3454 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3455 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3456 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3457 | // Runtime helper puts the result in EAX, EDX. |
| 3458 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3459 | break; |
| 3460 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3461 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3462 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3463 | locations->SetInAt(0, Location::Any()); |
| 3464 | locations->SetInAt(1, Location::Any()); |
| 3465 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3466 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3467 | break; |
| 3468 | } |
| 3469 | |
| 3470 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3471 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3476 | Primitive::Type type = rem->GetResultType(); |
| 3477 | switch (type) { |
| 3478 | case Primitive::kPrimInt: |
| 3479 | case Primitive::kPrimLong: { |
| 3480 | GenerateDivRemIntegral(rem); |
| 3481 | break; |
| 3482 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3483 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3484 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3485 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3486 | break; |
| 3487 | } |
| 3488 | default: |
| 3489 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3490 | } |
| 3491 | } |
| 3492 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3493 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3494 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3495 | ? LocationSummary::kCallOnSlowPath |
| 3496 | : LocationSummary::kNoCall; |
| 3497 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3498 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3499 | case Primitive::kPrimByte: |
| 3500 | case Primitive::kPrimChar: |
| 3501 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3502 | case Primitive::kPrimInt: { |
| 3503 | locations->SetInAt(0, Location::Any()); |
| 3504 | break; |
| 3505 | } |
| 3506 | case Primitive::kPrimLong: { |
| 3507 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3508 | if (!instruction->IsConstant()) { |
| 3509 | locations->AddTemp(Location::RequiresRegister()); |
| 3510 | } |
| 3511 | break; |
| 3512 | } |
| 3513 | default: |
| 3514 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3515 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3516 | if (instruction->HasUses()) { |
| 3517 | locations->SetOut(Location::SameAsFirstInput()); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3522 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3523 | codegen_->AddSlowPath(slow_path); |
| 3524 | |
| 3525 | LocationSummary* locations = instruction->GetLocations(); |
| 3526 | Location value = locations->InAt(0); |
| 3527 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3528 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3529 | case Primitive::kPrimByte: |
| 3530 | case Primitive::kPrimChar: |
| 3531 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3532 | case Primitive::kPrimInt: { |
| 3533 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3534 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3535 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3536 | } else if (value.IsStackSlot()) { |
| 3537 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3538 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3539 | } else { |
| 3540 | DCHECK(value.IsConstant()) << value; |
| 3541 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3542 | __ jmp(slow_path->GetEntryLabel()); |
| 3543 | } |
| 3544 | } |
| 3545 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3546 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3547 | case Primitive::kPrimLong: { |
| 3548 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3549 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3550 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3551 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3552 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3553 | } else { |
| 3554 | DCHECK(value.IsConstant()) << value; |
| 3555 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3556 | __ jmp(slow_path->GetEntryLabel()); |
| 3557 | } |
| 3558 | } |
| 3559 | break; |
| 3560 | } |
| 3561 | default: |
| 3562 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3563 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3566 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3567 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3568 | |
| 3569 | LocationSummary* locations = |
| 3570 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3571 | |
| 3572 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3573 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3574 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3575 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3576 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3577 | // The shift count needs to be in CL or a constant. |
| 3578 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3579 | locations->SetOut(Location::SameAsFirstInput()); |
| 3580 | break; |
| 3581 | } |
| 3582 | default: |
| 3583 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3588 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3589 | |
| 3590 | LocationSummary* locations = op->GetLocations(); |
| 3591 | Location first = locations->InAt(0); |
| 3592 | Location second = locations->InAt(1); |
| 3593 | DCHECK(first.Equals(locations->Out())); |
| 3594 | |
| 3595 | switch (op->GetResultType()) { |
| 3596 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3597 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3598 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3599 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3600 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3601 | DCHECK_EQ(ECX, second_reg); |
| 3602 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3603 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3604 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3605 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3606 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3607 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3608 | } |
| 3609 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3610 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3611 | if (shift == 0) { |
| 3612 | return; |
| 3613 | } |
| 3614 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3615 | if (op->IsShl()) { |
| 3616 | __ shll(first_reg, imm); |
| 3617 | } else if (op->IsShr()) { |
| 3618 | __ sarl(first_reg, imm); |
| 3619 | } else { |
| 3620 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | break; |
| 3624 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3625 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3626 | if (second.IsRegister()) { |
| 3627 | Register second_reg = second.AsRegister<Register>(); |
| 3628 | DCHECK_EQ(ECX, second_reg); |
| 3629 | if (op->IsShl()) { |
| 3630 | GenerateShlLong(first, second_reg); |
| 3631 | } else if (op->IsShr()) { |
| 3632 | GenerateShrLong(first, second_reg); |
| 3633 | } else { |
| 3634 | GenerateUShrLong(first, second_reg); |
| 3635 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3636 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3637 | // Shift by a constant. |
| 3638 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3639 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3640 | if (shift != 0) { |
| 3641 | if (op->IsShl()) { |
| 3642 | GenerateShlLong(first, shift); |
| 3643 | } else if (op->IsShr()) { |
| 3644 | GenerateShrLong(first, shift); |
| 3645 | } else { |
| 3646 | GenerateUShrLong(first, shift); |
| 3647 | } |
| 3648 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3649 | } |
| 3650 | break; |
| 3651 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3652 | default: |
| 3653 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3654 | } |
| 3655 | } |
| 3656 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3657 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3658 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3659 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3660 | if (shift == 1) { |
| 3661 | // This is just an addition. |
| 3662 | __ addl(low, low); |
| 3663 | __ adcl(high, high); |
| 3664 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3665 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3666 | codegen_->EmitParallelMoves( |
| 3667 | loc.ToLow(), |
| 3668 | loc.ToHigh(), |
| 3669 | Primitive::kPrimInt, |
| 3670 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3671 | loc.ToLow(), |
| 3672 | Primitive::kPrimInt); |
| 3673 | } else if (shift > 32) { |
| 3674 | // Low part becomes 0. High part is low part << (shift-32). |
| 3675 | __ movl(high, low); |
| 3676 | __ shll(high, Immediate(shift - 32)); |
| 3677 | __ xorl(low, low); |
| 3678 | } else { |
| 3679 | // Between 1 and 31. |
| 3680 | __ shld(high, low, Immediate(shift)); |
| 3681 | __ shll(low, Immediate(shift)); |
| 3682 | } |
| 3683 | } |
| 3684 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3685 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3686 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3687 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3688 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3689 | __ testl(shifter, Immediate(32)); |
| 3690 | __ j(kEqual, &done); |
| 3691 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3692 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3693 | __ Bind(&done); |
| 3694 | } |
| 3695 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3696 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3697 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3698 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3699 | if (shift == 32) { |
| 3700 | // Need to copy the sign. |
| 3701 | DCHECK_NE(low, high); |
| 3702 | __ movl(low, high); |
| 3703 | __ sarl(high, Immediate(31)); |
| 3704 | } else if (shift > 32) { |
| 3705 | DCHECK_NE(low, high); |
| 3706 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3707 | __ movl(low, high); |
| 3708 | __ sarl(high, Immediate(31)); |
| 3709 | __ sarl(low, Immediate(shift - 32)); |
| 3710 | } else { |
| 3711 | // Between 1 and 31. |
| 3712 | __ shrd(low, high, Immediate(shift)); |
| 3713 | __ sarl(high, Immediate(shift)); |
| 3714 | } |
| 3715 | } |
| 3716 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3717 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3718 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3719 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3720 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3721 | __ testl(shifter, Immediate(32)); |
| 3722 | __ j(kEqual, &done); |
| 3723 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3724 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3725 | __ Bind(&done); |
| 3726 | } |
| 3727 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3728 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3729 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3730 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3731 | if (shift == 32) { |
| 3732 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3733 | codegen_->EmitParallelMoves( |
| 3734 | loc.ToHigh(), |
| 3735 | loc.ToLow(), |
| 3736 | Primitive::kPrimInt, |
| 3737 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3738 | loc.ToHigh(), |
| 3739 | Primitive::kPrimInt); |
| 3740 | } else if (shift > 32) { |
| 3741 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3742 | __ movl(low, high); |
| 3743 | __ shrl(low, Immediate(shift - 32)); |
| 3744 | __ xorl(high, high); |
| 3745 | } else { |
| 3746 | // Between 1 and 31. |
| 3747 | __ shrd(low, high, Immediate(shift)); |
| 3748 | __ shrl(high, Immediate(shift)); |
| 3749 | } |
| 3750 | } |
| 3751 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3752 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3753 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3754 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3755 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3756 | __ testl(shifter, Immediate(32)); |
| 3757 | __ j(kEqual, &done); |
| 3758 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3759 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3760 | __ Bind(&done); |
| 3761 | } |
| 3762 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame^] | 3763 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3764 | LocationSummary* locations = |
| 3765 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3766 | |
| 3767 | switch (ror->GetResultType()) { |
| 3768 | case Primitive::kPrimLong: |
| 3769 | // Add the temporary needed. |
| 3770 | locations->AddTemp(Location::RequiresRegister()); |
| 3771 | FALLTHROUGH_INTENDED; |
| 3772 | case Primitive::kPrimInt: |
| 3773 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3774 | // The shift count needs to be in CL (unless it is a constant). |
| 3775 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3776 | locations->SetOut(Location::SameAsFirstInput()); |
| 3777 | break; |
| 3778 | default: |
| 3779 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3780 | UNREACHABLE(); |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3785 | LocationSummary* locations = ror->GetLocations(); |
| 3786 | Location first = locations->InAt(0); |
| 3787 | Location second = locations->InAt(1); |
| 3788 | |
| 3789 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3790 | Register first_reg = first.AsRegister<Register>(); |
| 3791 | if (second.IsRegister()) { |
| 3792 | Register second_reg = second.AsRegister<Register>(); |
| 3793 | __ rorl(first_reg, second_reg); |
| 3794 | } else { |
| 3795 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3796 | __ rorl(first_reg, imm); |
| 3797 | } |
| 3798 | return; |
| 3799 | } |
| 3800 | |
| 3801 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3802 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3803 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3804 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3805 | if (second.IsRegister()) { |
| 3806 | Register second_reg = second.AsRegister<Register>(); |
| 3807 | DCHECK_EQ(second_reg, ECX); |
| 3808 | __ movl(temp_reg, first_reg_hi); |
| 3809 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3810 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3811 | __ movl(temp_reg, first_reg_hi); |
| 3812 | __ testl(second_reg, Immediate(32)); |
| 3813 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3814 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3815 | } else { |
| 3816 | int32_t shift_amt = |
| 3817 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3818 | if (shift_amt == 0) { |
| 3819 | // Already fine. |
| 3820 | return; |
| 3821 | } |
| 3822 | if (shift_amt == 32) { |
| 3823 | // Just swap. |
| 3824 | __ movl(temp_reg, first_reg_lo); |
| 3825 | __ movl(first_reg_lo, first_reg_hi); |
| 3826 | __ movl(first_reg_hi, temp_reg); |
| 3827 | return; |
| 3828 | } |
| 3829 | |
| 3830 | Immediate imm(shift_amt); |
| 3831 | // Save the constents of the low value. |
| 3832 | __ movl(temp_reg, first_reg_lo); |
| 3833 | |
| 3834 | // Shift right into low, feeding bits from high. |
| 3835 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3836 | |
| 3837 | // Shift right into high, feeding bits from the original low. |
| 3838 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3839 | |
| 3840 | // Swap if needed. |
| 3841 | if (shift_amt > 32) { |
| 3842 | __ movl(temp_reg, first_reg_lo); |
| 3843 | __ movl(first_reg_lo, first_reg_hi); |
| 3844 | __ movl(first_reg_hi, temp_reg); |
| 3845 | } |
| 3846 | } |
| 3847 | } |
| 3848 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3849 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3850 | HandleShift(shl); |
| 3851 | } |
| 3852 | |
| 3853 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3854 | HandleShift(shl); |
| 3855 | } |
| 3856 | |
| 3857 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3858 | HandleShift(shr); |
| 3859 | } |
| 3860 | |
| 3861 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3862 | HandleShift(shr); |
| 3863 | } |
| 3864 | |
| 3865 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3866 | HandleShift(ushr); |
| 3867 | } |
| 3868 | |
| 3869 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3870 | HandleShift(ushr); |
| 3871 | } |
| 3872 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3873 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3874 | LocationSummary* locations = |
| 3875 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3876 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3877 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3878 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3879 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3883 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3884 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3885 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3886 | instruction, |
| 3887 | instruction->GetDexPc(), |
| 3888 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3889 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3890 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3891 | } |
| 3892 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3893 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3894 | LocationSummary* locations = |
| 3895 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3896 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3897 | InvokeRuntimeCallingConvention calling_convention; |
| 3898 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3899 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3900 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3904 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3905 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3906 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3907 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3908 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3909 | instruction, |
| 3910 | instruction->GetDexPc(), |
| 3911 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3912 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3913 | DCHECK(!codegen_->IsLeafMethod()); |
| 3914 | } |
| 3915 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3916 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3917 | LocationSummary* locations = |
| 3918 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3919 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3920 | if (location.IsStackSlot()) { |
| 3921 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3922 | } else if (location.IsDoubleStackSlot()) { |
| 3923 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3924 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3925 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3926 | } |
| 3927 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3928 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3929 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3930 | } |
| 3931 | |
| 3932 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3933 | LocationSummary* locations = |
| 3934 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3935 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3936 | } |
| 3937 | |
| 3938 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3939 | } |
| 3940 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3941 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3942 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3943 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3944 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3945 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3946 | } |
| 3947 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3948 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3949 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3950 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3951 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3952 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3953 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3954 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3955 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3956 | break; |
| 3957 | |
| 3958 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3959 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3960 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3961 | break; |
| 3962 | |
| 3963 | default: |
| 3964 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3965 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3966 | } |
| 3967 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3968 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3969 | LocationSummary* locations = |
| 3970 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3971 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3972 | locations->SetOut(Location::SameAsFirstInput()); |
| 3973 | } |
| 3974 | |
| 3975 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3976 | LocationSummary* locations = bool_not->GetLocations(); |
| 3977 | Location in = locations->InAt(0); |
| 3978 | Location out = locations->Out(); |
| 3979 | DCHECK(in.Equals(out)); |
| 3980 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3981 | } |
| 3982 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3983 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3984 | LocationSummary* locations = |
| 3985 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3986 | switch (compare->InputAt(0)->GetType()) { |
| 3987 | case Primitive::kPrimLong: { |
| 3988 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3989 | locations->SetInAt(1, Location::Any()); |
| 3990 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3991 | break; |
| 3992 | } |
| 3993 | case Primitive::kPrimFloat: |
| 3994 | case Primitive::kPrimDouble: { |
| 3995 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3996 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3997 | locations->SetOut(Location::RequiresRegister()); |
| 3998 | break; |
| 3999 | } |
| 4000 | default: |
| 4001 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4002 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4003 | } |
| 4004 | |
| 4005 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4006 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4007 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4008 | Location left = locations->InAt(0); |
| 4009 | Location right = locations->InAt(1); |
| 4010 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4011 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4012 | switch (compare->InputAt(0)->GetType()) { |
| 4013 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4014 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4015 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4016 | int32_t val_low = 0; |
| 4017 | int32_t val_high = 0; |
| 4018 | bool right_is_const = false; |
| 4019 | |
| 4020 | if (right.IsConstant()) { |
| 4021 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4022 | right_is_const = true; |
| 4023 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4024 | val_low = Low32Bits(val); |
| 4025 | val_high = High32Bits(val); |
| 4026 | } |
| 4027 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4028 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4029 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4030 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4031 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4032 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4033 | DCHECK(right_is_const) << right; |
| 4034 | if (val_high == 0) { |
| 4035 | __ testl(left_high, left_high); |
| 4036 | } else { |
| 4037 | __ cmpl(left_high, Immediate(val_high)); |
| 4038 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4039 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4040 | __ j(kLess, &less); // Signed compare. |
| 4041 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4042 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4043 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4044 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4045 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4046 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4047 | DCHECK(right_is_const) << right; |
| 4048 | if (val_low == 0) { |
| 4049 | __ testl(left_low, left_low); |
| 4050 | } else { |
| 4051 | __ cmpl(left_low, Immediate(val_low)); |
| 4052 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4053 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4054 | break; |
| 4055 | } |
| 4056 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4057 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4058 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4059 | break; |
| 4060 | } |
| 4061 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4062 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4063 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4064 | break; |
| 4065 | } |
| 4066 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4067 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4068 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4069 | __ movl(out, Immediate(0)); |
| 4070 | __ j(kEqual, &done); |
| 4071 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4072 | |
| 4073 | __ Bind(&greater); |
| 4074 | __ movl(out, Immediate(1)); |
| 4075 | __ jmp(&done); |
| 4076 | |
| 4077 | __ Bind(&less); |
| 4078 | __ movl(out, Immediate(-1)); |
| 4079 | |
| 4080 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4081 | } |
| 4082 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4083 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4084 | LocationSummary* locations = |
| 4085 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4086 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4087 | locations->SetInAt(i, Location::Any()); |
| 4088 | } |
| 4089 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4090 | } |
| 4091 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4092 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4093 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4094 | } |
| 4095 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4096 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 4097 | /* |
| 4098 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4099 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4100 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4101 | */ |
| 4102 | switch (kind) { |
| 4103 | case MemBarrierKind::kAnyAny: { |
| 4104 | __ mfence(); |
| 4105 | break; |
| 4106 | } |
| 4107 | case MemBarrierKind::kAnyStore: |
| 4108 | case MemBarrierKind::kLoadAny: |
| 4109 | case MemBarrierKind::kStoreStore: { |
| 4110 | // nop |
| 4111 | break; |
| 4112 | } |
| 4113 | default: |
| 4114 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4115 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4118 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4119 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4120 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4121 | switch (desired_dispatch_info.code_ptr_location) { |
| 4122 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4123 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4124 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4125 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4126 | return HInvokeStaticOrDirect::DispatchInfo { |
| 4127 | desired_dispatch_info.method_load_kind, |
| 4128 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 4129 | desired_dispatch_info.method_load_data, |
| 4130 | 0u |
| 4131 | }; |
| 4132 | default: |
| 4133 | return desired_dispatch_info; |
| 4134 | } |
| 4135 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4136 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4137 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4138 | Register temp) { |
| 4139 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4140 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4141 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4142 | return location.AsRegister<Register>(); |
| 4143 | } |
| 4144 | // For intrinsics we allow any location, so it may be on the stack. |
| 4145 | if (!location.IsRegister()) { |
| 4146 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4147 | return temp; |
| 4148 | } |
| 4149 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4150 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4151 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4152 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4153 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4154 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4155 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4156 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4157 | __ movl(temp, Address(ESP, stack_offset)); |
| 4158 | return temp; |
| 4159 | } |
| 4160 | return location.AsRegister<Register>(); |
| 4161 | } |
| 4162 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4163 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4164 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4165 | switch (invoke->GetMethodLoadKind()) { |
| 4166 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4167 | // temp = thread->string_init_entrypoint |
| 4168 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4169 | break; |
| 4170 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4171 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4172 | break; |
| 4173 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4174 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4175 | break; |
| 4176 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4177 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4178 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4179 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4180 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4181 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4182 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4183 | temp.AsRegister<Register>()); |
| 4184 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4185 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4186 | // Add the patch entry and bind its label at the end of the instruction. |
| 4187 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4188 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4189 | break; |
| 4190 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4191 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4192 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4193 | Register method_reg; |
| 4194 | Register reg = temp.AsRegister<Register>(); |
| 4195 | if (current_method.IsRegister()) { |
| 4196 | method_reg = current_method.AsRegister<Register>(); |
| 4197 | } else { |
| 4198 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 4199 | DCHECK(!current_method.IsValid()); |
| 4200 | method_reg = reg; |
| 4201 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4202 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4203 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4204 | __ movl(reg, Address(method_reg, |
| 4205 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4206 | // temp = temp[index_in_cache] |
| 4207 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4208 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4209 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4210 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | switch (invoke->GetCodePtrLocation()) { |
| 4214 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4215 | __ call(GetFrameEntryLabel()); |
| 4216 | break; |
| 4217 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4218 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4219 | Label* label = &relative_call_patches_.back().label; |
| 4220 | __ call(label); // Bind to the patch label, override at link time. |
| 4221 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4222 | break; |
| 4223 | } |
| 4224 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4225 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4226 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4227 | LOG(FATAL) << "Unsupported"; |
| 4228 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4229 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4230 | // (callee_method + offset_of_quick_compiled_code)() |
| 4231 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4232 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4233 | kX86WordSize).Int32Value())); |
| 4234 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4238 | } |
| 4239 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4240 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4241 | Register temp = temp_in.AsRegister<Register>(); |
| 4242 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4243 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4244 | |
| 4245 | // Use the calling convention instead of the location of the receiver, as |
| 4246 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4247 | // slow path, the arguments have been moved to the right place, so here we are |
| 4248 | // guaranteed that the receiver is the first register of the calling convention. |
| 4249 | InvokeDexCallingConvention calling_convention; |
| 4250 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4251 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4252 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4253 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4254 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4255 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4256 | // emit a read barrier for the previous class reference load. |
| 4257 | // However this is not required in practice, as this is an |
| 4258 | // intermediate/temporary reference and because the current |
| 4259 | // concurrent copying collector keeps the from-space memory |
| 4260 | // intact/accessible until the end of the marking phase (the |
| 4261 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4262 | __ MaybeUnpoisonHeapReference(temp); |
| 4263 | // temp = temp->GetMethodAt(method_offset); |
| 4264 | __ movl(temp, Address(temp, method_offset)); |
| 4265 | // call temp->GetEntryPoint(); |
| 4266 | __ call(Address( |
| 4267 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4268 | } |
| 4269 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4270 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4271 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4272 | size_t size = |
| 4273 | method_patches_.size() + |
| 4274 | relative_call_patches_.size() + |
| 4275 | pc_relative_dex_cache_patches_.size(); |
| 4276 | linker_patches->reserve(size); |
| 4277 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4278 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4279 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4280 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4281 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4282 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4283 | info.target_method.dex_file, |
| 4284 | info.target_method.dex_method_index)); |
| 4285 | } |
| 4286 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4287 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4288 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4289 | info.target_method.dex_file, |
| 4290 | info.target_method.dex_method_index)); |
| 4291 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4292 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4293 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4294 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4295 | &info.target_dex_file, |
| 4296 | GetMethodAddressOffset(), |
| 4297 | info.element_offset)); |
| 4298 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4299 | } |
| 4300 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4301 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4302 | Register card, |
| 4303 | Register object, |
| 4304 | Register value, |
| 4305 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4306 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4307 | if (value_can_be_null) { |
| 4308 | __ testl(value, value); |
| 4309 | __ j(kEqual, &is_null); |
| 4310 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4311 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4312 | __ movl(temp, object); |
| 4313 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4314 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4315 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4316 | if (value_can_be_null) { |
| 4317 | __ Bind(&is_null); |
| 4318 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4321 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4322 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4323 | |
| 4324 | bool object_field_get_with_read_barrier = |
| 4325 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4326 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4327 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4328 | kEmitCompilerReadBarrier ? |
| 4329 | LocationSummary::kCallOnSlowPath : |
| 4330 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4331 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4332 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4333 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4334 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4335 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4336 | // The output overlaps in case of long: we don't want the low move |
| 4337 | // to overwrite the object's location. Likewise, in the case of |
| 4338 | // an object field get with read barriers enabled, we do not want |
| 4339 | // the move to overwrite the object's location, as we need it to emit |
| 4340 | // the read barrier. |
| 4341 | locations->SetOut( |
| 4342 | Location::RequiresRegister(), |
| 4343 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4344 | Location::kOutputOverlap : |
| 4345 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4346 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4347 | |
| 4348 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4349 | // Long values can be loaded atomically into an XMM using movsd. |
| 4350 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 4351 | // and then copy the XMM into the output 32bits at a time). |
| 4352 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4353 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4354 | } |
| 4355 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4356 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4357 | const FieldInfo& field_info) { |
| 4358 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4359 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4360 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4361 | Location base_loc = locations->InAt(0); |
| 4362 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4363 | Location out = locations->Out(); |
| 4364 | bool is_volatile = field_info.IsVolatile(); |
| 4365 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4366 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4367 | |
| 4368 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4369 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4370 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4371 | break; |
| 4372 | } |
| 4373 | |
| 4374 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4375 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4376 | break; |
| 4377 | } |
| 4378 | |
| 4379 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4380 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4381 | break; |
| 4382 | } |
| 4383 | |
| 4384 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4385 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4386 | break; |
| 4387 | } |
| 4388 | |
| 4389 | case Primitive::kPrimInt: |
| 4390 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4391 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4392 | break; |
| 4393 | } |
| 4394 | |
| 4395 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4396 | if (is_volatile) { |
| 4397 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4398 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4399 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4400 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4401 | __ psrlq(temp, Immediate(32)); |
| 4402 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4403 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4404 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4405 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4406 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4407 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4408 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4409 | break; |
| 4410 | } |
| 4411 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4412 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4413 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4414 | break; |
| 4415 | } |
| 4416 | |
| 4417 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4418 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4419 | break; |
| 4420 | } |
| 4421 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4422 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4423 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4424 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4425 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4426 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4427 | // Longs are handled in the switch. |
| 4428 | if (field_type != Primitive::kPrimLong) { |
| 4429 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4430 | } |
| 4431 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4432 | if (is_volatile) { |
| 4433 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4434 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4435 | |
| 4436 | if (field_type == Primitive::kPrimNot) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4437 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, base_loc, offset); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4438 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4442 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4443 | |
| 4444 | LocationSummary* locations = |
| 4445 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4446 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4447 | bool is_volatile = field_info.IsVolatile(); |
| 4448 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4449 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4450 | || (field_type == Primitive::kPrimByte); |
| 4451 | |
| 4452 | // The register allocator does not support multiple |
| 4453 | // inputs that die at entry with one in a specific register. |
| 4454 | if (is_byte_type) { |
| 4455 | // Ensure the value is in a byte register. |
| 4456 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4457 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4458 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4459 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4460 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4461 | } else { |
| 4462 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4463 | } |
| 4464 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4465 | // 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] | 4466 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4467 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4468 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4469 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4470 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4471 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4472 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4473 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4474 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4475 | } else { |
| 4476 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4477 | |
| 4478 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4479 | // Temporary registers for the write barrier. |
| 4480 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4481 | // Ensure the card is in a byte register. |
| 4482 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4483 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4488 | const FieldInfo& field_info, |
| 4489 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4490 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4491 | |
| 4492 | LocationSummary* locations = instruction->GetLocations(); |
| 4493 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4494 | Location value = locations->InAt(1); |
| 4495 | bool is_volatile = field_info.IsVolatile(); |
| 4496 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4497 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4498 | bool needs_write_barrier = |
| 4499 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4500 | |
| 4501 | if (is_volatile) { |
| 4502 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4503 | } |
| 4504 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4505 | bool maybe_record_implicit_null_check_done = false; |
| 4506 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4507 | switch (field_type) { |
| 4508 | case Primitive::kPrimBoolean: |
| 4509 | case Primitive::kPrimByte: { |
| 4510 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4511 | break; |
| 4512 | } |
| 4513 | |
| 4514 | case Primitive::kPrimShort: |
| 4515 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4516 | if (value.IsConstant()) { |
| 4517 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4518 | __ movw(Address(base, offset), Immediate(v)); |
| 4519 | } else { |
| 4520 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4521 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4522 | break; |
| 4523 | } |
| 4524 | |
| 4525 | case Primitive::kPrimInt: |
| 4526 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4527 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4528 | // Note that in the case where `value` is a null reference, |
| 4529 | // we do not enter this block, as the reference does not |
| 4530 | // need poisoning. |
| 4531 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4532 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4533 | __ movl(temp, value.AsRegister<Register>()); |
| 4534 | __ PoisonHeapReference(temp); |
| 4535 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4536 | } else if (value.IsConstant()) { |
| 4537 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4538 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4539 | } else { |
| 4540 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4541 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4542 | break; |
| 4543 | } |
| 4544 | |
| 4545 | case Primitive::kPrimLong: { |
| 4546 | if (is_volatile) { |
| 4547 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4548 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4549 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4550 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4551 | __ punpckldq(temp1, temp2); |
| 4552 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4553 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4554 | } else if (value.IsConstant()) { |
| 4555 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4556 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4557 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4558 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | } else { |
| 4560 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4561 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4562 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4563 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4564 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | break; |
| 4566 | } |
| 4567 | |
| 4568 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4569 | if (value.IsConstant()) { |
| 4570 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4571 | __ movl(Address(base, offset), Immediate(v)); |
| 4572 | } else { |
| 4573 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4574 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4575 | break; |
| 4576 | } |
| 4577 | |
| 4578 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4579 | if (value.IsConstant()) { |
| 4580 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4581 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4582 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4583 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4584 | maybe_record_implicit_null_check_done = true; |
| 4585 | } else { |
| 4586 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4587 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | break; |
| 4589 | } |
| 4590 | |
| 4591 | case Primitive::kPrimVoid: |
| 4592 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4593 | UNREACHABLE(); |
| 4594 | } |
| 4595 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4596 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4597 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4598 | } |
| 4599 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4600 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4601 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4602 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4603 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4604 | } |
| 4605 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4606 | if (is_volatile) { |
| 4607 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4612 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4613 | } |
| 4614 | |
| 4615 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4616 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4617 | } |
| 4618 | |
| 4619 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4620 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4621 | } |
| 4622 | |
| 4623 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4624 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4628 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4629 | } |
| 4630 | |
| 4631 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4632 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4636 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4637 | } |
| 4638 | |
| 4639 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4640 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4641 | } |
| 4642 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4643 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4644 | HUnresolvedInstanceFieldGet* instruction) { |
| 4645 | FieldAccessCallingConventionX86 calling_convention; |
| 4646 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4647 | instruction, instruction->GetFieldType(), calling_convention); |
| 4648 | } |
| 4649 | |
| 4650 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4651 | HUnresolvedInstanceFieldGet* instruction) { |
| 4652 | FieldAccessCallingConventionX86 calling_convention; |
| 4653 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4654 | instruction->GetFieldType(), |
| 4655 | instruction->GetFieldIndex(), |
| 4656 | instruction->GetDexPc(), |
| 4657 | calling_convention); |
| 4658 | } |
| 4659 | |
| 4660 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4661 | HUnresolvedInstanceFieldSet* instruction) { |
| 4662 | FieldAccessCallingConventionX86 calling_convention; |
| 4663 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4664 | instruction, instruction->GetFieldType(), calling_convention); |
| 4665 | } |
| 4666 | |
| 4667 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4668 | HUnresolvedInstanceFieldSet* instruction) { |
| 4669 | FieldAccessCallingConventionX86 calling_convention; |
| 4670 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4671 | instruction->GetFieldType(), |
| 4672 | instruction->GetFieldIndex(), |
| 4673 | instruction->GetDexPc(), |
| 4674 | calling_convention); |
| 4675 | } |
| 4676 | |
| 4677 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4678 | HUnresolvedStaticFieldGet* instruction) { |
| 4679 | FieldAccessCallingConventionX86 calling_convention; |
| 4680 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4681 | instruction, instruction->GetFieldType(), calling_convention); |
| 4682 | } |
| 4683 | |
| 4684 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4685 | HUnresolvedStaticFieldGet* instruction) { |
| 4686 | FieldAccessCallingConventionX86 calling_convention; |
| 4687 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4688 | instruction->GetFieldType(), |
| 4689 | instruction->GetFieldIndex(), |
| 4690 | instruction->GetDexPc(), |
| 4691 | calling_convention); |
| 4692 | } |
| 4693 | |
| 4694 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4695 | HUnresolvedStaticFieldSet* instruction) { |
| 4696 | FieldAccessCallingConventionX86 calling_convention; |
| 4697 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4698 | instruction, instruction->GetFieldType(), calling_convention); |
| 4699 | } |
| 4700 | |
| 4701 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4702 | HUnresolvedStaticFieldSet* instruction) { |
| 4703 | FieldAccessCallingConventionX86 calling_convention; |
| 4704 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4705 | instruction->GetFieldType(), |
| 4706 | instruction->GetFieldIndex(), |
| 4707 | instruction->GetDexPc(), |
| 4708 | calling_convention); |
| 4709 | } |
| 4710 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4711 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4712 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4713 | ? LocationSummary::kCallOnSlowPath |
| 4714 | : LocationSummary::kNoCall; |
| 4715 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4716 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4717 | ? Location::RequiresRegister() |
| 4718 | : Location::Any(); |
| 4719 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4720 | if (instruction->HasUses()) { |
| 4721 | locations->SetOut(Location::SameAsFirstInput()); |
| 4722 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4723 | } |
| 4724 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4725 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4726 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4727 | return; |
| 4728 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4729 | LocationSummary* locations = instruction->GetLocations(); |
| 4730 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4731 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4732 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4733 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4734 | } |
| 4735 | |
| 4736 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4737 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4738 | codegen_->AddSlowPath(slow_path); |
| 4739 | |
| 4740 | LocationSummary* locations = instruction->GetLocations(); |
| 4741 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4742 | |
| 4743 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4744 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4745 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4746 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4747 | } else { |
| 4748 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4749 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4750 | __ jmp(slow_path->GetEntryLabel()); |
| 4751 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4752 | } |
| 4753 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4754 | } |
| 4755 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4756 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4757 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4758 | GenerateImplicitNullCheck(instruction); |
| 4759 | } else { |
| 4760 | GenerateExplicitNullCheck(instruction); |
| 4761 | } |
| 4762 | } |
| 4763 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4764 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4765 | bool object_array_get_with_read_barrier = |
| 4766 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4767 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4768 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4769 | object_array_get_with_read_barrier ? |
| 4770 | LocationSummary::kCallOnSlowPath : |
| 4771 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4772 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4773 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4774 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4775 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4776 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4777 | // The output overlaps in case of long: we don't want the low move |
| 4778 | // to overwrite the array's location. Likewise, in the case of an |
| 4779 | // object array get with read barriers enabled, we do not want the |
| 4780 | // move to overwrite the array's location, as we need it to emit |
| 4781 | // the read barrier. |
| 4782 | locations->SetOut( |
| 4783 | Location::RequiresRegister(), |
| 4784 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4785 | Location::kOutputOverlap : |
| 4786 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4787 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4791 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4792 | Location obj_loc = locations->InAt(0); |
| 4793 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4794 | Location index = locations->InAt(1); |
| 4795 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4796 | Primitive::Type type = instruction->GetType(); |
| 4797 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4798 | case Primitive::kPrimBoolean: { |
| 4799 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4800 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4801 | if (index.IsConstant()) { |
| 4802 | __ movzxb(out, Address(obj, |
| 4803 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4804 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4805 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4806 | } |
| 4807 | break; |
| 4808 | } |
| 4809 | |
| 4810 | case Primitive::kPrimByte: { |
| 4811 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4812 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4813 | if (index.IsConstant()) { |
| 4814 | __ movsxb(out, Address(obj, |
| 4815 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4816 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4817 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4818 | } |
| 4819 | break; |
| 4820 | } |
| 4821 | |
| 4822 | case Primitive::kPrimShort: { |
| 4823 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4824 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4825 | if (index.IsConstant()) { |
| 4826 | __ movsxw(out, Address(obj, |
| 4827 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4828 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4829 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4830 | } |
| 4831 | break; |
| 4832 | } |
| 4833 | |
| 4834 | case Primitive::kPrimChar: { |
| 4835 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4836 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4837 | if (index.IsConstant()) { |
| 4838 | __ movzxw(out, Address(obj, |
| 4839 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4840 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4841 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4842 | } |
| 4843 | break; |
| 4844 | } |
| 4845 | |
| 4846 | case Primitive::kPrimInt: |
| 4847 | case Primitive::kPrimNot: { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4848 | static_assert( |
| 4849 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4850 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4851 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4852 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4853 | if (index.IsConstant()) { |
| 4854 | __ movl(out, Address(obj, |
| 4855 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4856 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4857 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4858 | } |
| 4859 | break; |
| 4860 | } |
| 4861 | |
| 4862 | case Primitive::kPrimLong: { |
| 4863 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4864 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4865 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4866 | if (index.IsConstant()) { |
| 4867 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4868 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4869 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4870 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4871 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4872 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4873 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4874 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4875 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4876 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4877 | } |
| 4878 | break; |
| 4879 | } |
| 4880 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4881 | case Primitive::kPrimFloat: { |
| 4882 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4883 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4884 | if (index.IsConstant()) { |
| 4885 | __ movss(out, Address(obj, |
| 4886 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4887 | } else { |
| 4888 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4889 | } |
| 4890 | break; |
| 4891 | } |
| 4892 | |
| 4893 | case Primitive::kPrimDouble: { |
| 4894 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4895 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4896 | if (index.IsConstant()) { |
| 4897 | __ movsd(out, Address(obj, |
| 4898 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4899 | } else { |
| 4900 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4901 | } |
| 4902 | break; |
| 4903 | } |
| 4904 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4905 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4906 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4907 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4908 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4909 | |
| 4910 | if (type != Primitive::kPrimLong) { |
| 4911 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4912 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4913 | |
| 4914 | if (type == Primitive::kPrimNot) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4915 | static_assert( |
| 4916 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4917 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4918 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4919 | Location out = locations->Out(); |
| 4920 | if (index.IsConstant()) { |
| 4921 | uint32_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4922 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, offset); |
| 4923 | } else { |
| 4924 | codegen_->MaybeGenerateReadBarrier(instruction, out, out, obj_loc, data_offset, index); |
| 4925 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4926 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4930 | // This location builder might end up asking to up to four registers, which is |
| 4931 | // not currently possible for baseline. The situation in which we need four |
| 4932 | // registers cannot be met by baseline though, because it has not run any |
| 4933 | // optimization. |
| 4934 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4935 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4936 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4937 | bool needs_write_barrier = |
| 4938 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4939 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 4940 | bool object_array_set_with_read_barrier = |
| 4941 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4942 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4943 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4944 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4945 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 4946 | LocationSummary::kCallOnSlowPath : |
| 4947 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4948 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4949 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4950 | || (value_type == Primitive::kPrimByte); |
| 4951 | // We need the inputs to be different than the output in case of long operation. |
| 4952 | // In case of a byte operation, the register allocator does not support multiple |
| 4953 | // inputs that die at entry with one in a specific register. |
| 4954 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4955 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4956 | if (is_byte_type) { |
| 4957 | // Ensure the value is in a byte register. |
| 4958 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 4959 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4960 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4961 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4962 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4963 | } |
| 4964 | if (needs_write_barrier) { |
| 4965 | // Temporary registers for the write barrier. |
| 4966 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4967 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 4968 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4969 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4973 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4974 | Location array_loc = locations->InAt(0); |
| 4975 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4976 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4977 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4978 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4979 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4980 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4981 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4982 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4983 | bool needs_write_barrier = |
| 4984 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4985 | |
| 4986 | switch (value_type) { |
| 4987 | case Primitive::kPrimBoolean: |
| 4988 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4989 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4990 | Address address = index.IsConstant() |
| 4991 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4992 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 4993 | if (value.IsRegister()) { |
| 4994 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4995 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4996 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4997 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4998 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4999 | break; |
| 5000 | } |
| 5001 | |
| 5002 | case Primitive::kPrimShort: |
| 5003 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5004 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5005 | Address address = index.IsConstant() |
| 5006 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5007 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5008 | if (value.IsRegister()) { |
| 5009 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5010 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5011 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5012 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5013 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5014 | break; |
| 5015 | } |
| 5016 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5017 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5018 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5019 | Address address = index.IsConstant() |
| 5020 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5021 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5022 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5023 | if (!value.IsRegister()) { |
| 5024 | // Just setting null. |
| 5025 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5026 | DCHECK(value.IsConstant()) << value; |
| 5027 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5028 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5029 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5030 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5031 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5032 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5033 | |
| 5034 | DCHECK(needs_write_barrier); |
| 5035 | Register register_value = value.AsRegister<Register>(); |
| 5036 | NearLabel done, not_null, do_put; |
| 5037 | SlowPathCode* slow_path = nullptr; |
| 5038 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5039 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5040 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5041 | codegen_->AddSlowPath(slow_path); |
| 5042 | if (instruction->GetValueCanBeNull()) { |
| 5043 | __ testl(register_value, register_value); |
| 5044 | __ j(kNotEqual, ¬_null); |
| 5045 | __ movl(address, Immediate(0)); |
| 5046 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5047 | __ jmp(&done); |
| 5048 | __ Bind(¬_null); |
| 5049 | } |
| 5050 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5051 | if (kEmitCompilerReadBarrier) { |
| 5052 | // When read barriers are enabled, the type checking |
| 5053 | // instrumentation requires two read barriers: |
| 5054 | // |
| 5055 | // __ movl(temp2, temp); |
| 5056 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5057 | // __ movl(temp, Address(temp, component_offset)); |
| 5058 | // codegen_->GenerateReadBarrier( |
| 5059 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5060 | // |
| 5061 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5062 | // __ movl(temp2, Address(register_value, class_offset)); |
| 5063 | // codegen_->GenerateReadBarrier( |
| 5064 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5065 | // |
| 5066 | // __ cmpl(temp, temp2); |
| 5067 | // |
| 5068 | // However, the second read barrier may trash `temp`, as it |
| 5069 | // is a temporary register, and as such would not be saved |
| 5070 | // along with live registers before calling the runtime (nor |
| 5071 | // restored afterwards). So in this case, we bail out and |
| 5072 | // delegate the work to the array set slow path. |
| 5073 | // |
| 5074 | // TODO: Extend the register allocator to support a new |
| 5075 | // "(locally) live temp" location so as to avoid always |
| 5076 | // going into the slow path when read barriers are enabled. |
| 5077 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5078 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5079 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5080 | __ movl(temp, Address(array, class_offset)); |
| 5081 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5082 | __ MaybeUnpoisonHeapReference(temp); |
| 5083 | |
| 5084 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5085 | __ movl(temp, Address(temp, component_offset)); |
| 5086 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5087 | // nor the object reference in `register_value->klass`, as |
| 5088 | // we are comparing two poisoned references. |
| 5089 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5090 | |
| 5091 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5092 | __ j(kEqual, &do_put); |
| 5093 | // If heap poisoning is enabled, the `temp` reference has |
| 5094 | // not been unpoisoned yet; unpoison it now. |
| 5095 | __ MaybeUnpoisonHeapReference(temp); |
| 5096 | |
| 5097 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5098 | __ movl(temp, Address(temp, super_offset)); |
| 5099 | // If heap poisoning is enabled, no need to unpoison |
| 5100 | // `temp`, as we are comparing against null below. |
| 5101 | __ testl(temp, temp); |
| 5102 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5103 | __ Bind(&do_put); |
| 5104 | } else { |
| 5105 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5106 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5107 | } |
| 5108 | } |
| 5109 | |
| 5110 | if (kPoisonHeapReferences) { |
| 5111 | __ movl(temp, register_value); |
| 5112 | __ PoisonHeapReference(temp); |
| 5113 | __ movl(address, temp); |
| 5114 | } else { |
| 5115 | __ movl(address, register_value); |
| 5116 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5117 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5118 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5119 | } |
| 5120 | |
| 5121 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5122 | codegen_->MarkGCCard( |
| 5123 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5124 | __ Bind(&done); |
| 5125 | |
| 5126 | if (slow_path != nullptr) { |
| 5127 | __ Bind(slow_path->GetExitLabel()); |
| 5128 | } |
| 5129 | |
| 5130 | break; |
| 5131 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5132 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5133 | case Primitive::kPrimInt: { |
| 5134 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5135 | Address address = index.IsConstant() |
| 5136 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5137 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5138 | if (value.IsRegister()) { |
| 5139 | __ movl(address, value.AsRegister<Register>()); |
| 5140 | } else { |
| 5141 | DCHECK(value.IsConstant()) << value; |
| 5142 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5143 | __ movl(address, Immediate(v)); |
| 5144 | } |
| 5145 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5146 | break; |
| 5147 | } |
| 5148 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5149 | case Primitive::kPrimLong: { |
| 5150 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5151 | if (index.IsConstant()) { |
| 5152 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5153 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5154 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5155 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5156 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5157 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5158 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5159 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5160 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5161 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5163 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5165 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5166 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5167 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5168 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5169 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5170 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5171 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5172 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5173 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5174 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5175 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5176 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5177 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5178 | Immediate(High32Bits(val))); |
| 5179 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5180 | } |
| 5181 | break; |
| 5182 | } |
| 5183 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5184 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5185 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5186 | Address address = index.IsConstant() |
| 5187 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5188 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5189 | if (value.IsFpuRegister()) { |
| 5190 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5191 | } else { |
| 5192 | DCHECK(value.IsConstant()); |
| 5193 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5194 | __ movl(address, Immediate(v)); |
| 5195 | } |
| 5196 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5197 | break; |
| 5198 | } |
| 5199 | |
| 5200 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5201 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5202 | Address address = index.IsConstant() |
| 5203 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5204 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5205 | if (value.IsFpuRegister()) { |
| 5206 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5207 | } else { |
| 5208 | DCHECK(value.IsConstant()); |
| 5209 | Address address_hi = index.IsConstant() ? |
| 5210 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5211 | offset + kX86WordSize) : |
| 5212 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5213 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5214 | __ movl(address, Immediate(Low32Bits(v))); |
| 5215 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5216 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5217 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5218 | break; |
| 5219 | } |
| 5220 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5221 | case Primitive::kPrimVoid: |
| 5222 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5223 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5228 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5230 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5234 | LocationSummary* locations = instruction->GetLocations(); |
| 5235 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5236 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5237 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5238 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5239 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5243 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5244 | ? LocationSummary::kCallOnSlowPath |
| 5245 | : LocationSummary::kNoCall; |
| 5246 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5247 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5248 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5249 | if (instruction->HasUses()) { |
| 5250 | locations->SetOut(Location::SameAsFirstInput()); |
| 5251 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5255 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5256 | Location index_loc = locations->InAt(0); |
| 5257 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5258 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5259 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5261 | if (length_loc.IsConstant()) { |
| 5262 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5263 | if (index_loc.IsConstant()) { |
| 5264 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5265 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5266 | if (index < 0 || index >= length) { |
| 5267 | codegen_->AddSlowPath(slow_path); |
| 5268 | __ jmp(slow_path->GetEntryLabel()); |
| 5269 | } else { |
| 5270 | // Some optimization after BCE may have generated this, and we should not |
| 5271 | // generate a bounds check if it is a valid range. |
| 5272 | } |
| 5273 | return; |
| 5274 | } |
| 5275 | |
| 5276 | // We have to reverse the jump condition because the length is the constant. |
| 5277 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5278 | __ cmpl(index_reg, Immediate(length)); |
| 5279 | codegen_->AddSlowPath(slow_path); |
| 5280 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5281 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5282 | Register length = length_loc.AsRegister<Register>(); |
| 5283 | if (index_loc.IsConstant()) { |
| 5284 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5285 | __ cmpl(length, Immediate(value)); |
| 5286 | } else { |
| 5287 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5288 | } |
| 5289 | codegen_->AddSlowPath(slow_path); |
| 5290 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5291 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5292 | } |
| 5293 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5294 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5295 | temp->SetLocations(nullptr); |
| 5296 | } |
| 5297 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5298 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5299 | // Nothing to do, this is driven by the code generator. |
| 5300 | } |
| 5301 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5302 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5303 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5307 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5308 | } |
| 5309 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5310 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5311 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5312 | } |
| 5313 | |
| 5314 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5315 | HBasicBlock* block = instruction->GetBlock(); |
| 5316 | if (block->GetLoopInformation() != nullptr) { |
| 5317 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5318 | // The back edge will generate the suspend check. |
| 5319 | return; |
| 5320 | } |
| 5321 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5322 | // The goto will generate the suspend check. |
| 5323 | return; |
| 5324 | } |
| 5325 | GenerateSuspendCheck(instruction, nullptr); |
| 5326 | } |
| 5327 | |
| 5328 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5329 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5330 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5331 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5332 | if (slow_path == nullptr) { |
| 5333 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5334 | instruction->SetSlowPath(slow_path); |
| 5335 | codegen_->AddSlowPath(slow_path); |
| 5336 | if (successor != nullptr) { |
| 5337 | DCHECK(successor->IsLoopHeader()); |
| 5338 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5339 | } |
| 5340 | } else { |
| 5341 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5342 | } |
| 5343 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5344 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5345 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5346 | if (successor == nullptr) { |
| 5347 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5348 | __ Bind(slow_path->GetReturnLabel()); |
| 5349 | } else { |
| 5350 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5351 | __ jmp(slow_path->GetEntryLabel()); |
| 5352 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5355 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5356 | return codegen_->GetAssembler(); |
| 5357 | } |
| 5358 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5359 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5360 | ScratchRegisterScope ensure_scratch( |
| 5361 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5362 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5363 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5364 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5365 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5369 | ScratchRegisterScope ensure_scratch( |
| 5370 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5371 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5372 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5373 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5374 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5375 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5376 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5380 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5381 | Location source = move->GetSource(); |
| 5382 | Location destination = move->GetDestination(); |
| 5383 | |
| 5384 | if (source.IsRegister()) { |
| 5385 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5386 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5387 | } else { |
| 5388 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5389 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5390 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5391 | } else if (source.IsFpuRegister()) { |
| 5392 | if (destination.IsFpuRegister()) { |
| 5393 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5394 | } else if (destination.IsStackSlot()) { |
| 5395 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5396 | } else { |
| 5397 | DCHECK(destination.IsDoubleStackSlot()); |
| 5398 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5399 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5400 | } else if (source.IsStackSlot()) { |
| 5401 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5402 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5403 | } else if (destination.IsFpuRegister()) { |
| 5404 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5405 | } else { |
| 5406 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5407 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5408 | } |
| 5409 | } else if (source.IsDoubleStackSlot()) { |
| 5410 | if (destination.IsFpuRegister()) { |
| 5411 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5412 | } else { |
| 5413 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5414 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5415 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5416 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5417 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5418 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5419 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5420 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5421 | if (value == 0) { |
| 5422 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5423 | } else { |
| 5424 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5425 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5426 | } else { |
| 5427 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5428 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5429 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5430 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5431 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5432 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5433 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5434 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5435 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5436 | if (value == 0) { |
| 5437 | // Easy handling of 0.0. |
| 5438 | __ xorps(dest, dest); |
| 5439 | } else { |
| 5440 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5441 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5442 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5443 | __ movl(temp, Immediate(value)); |
| 5444 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5445 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5446 | } else { |
| 5447 | DCHECK(destination.IsStackSlot()) << destination; |
| 5448 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5449 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5450 | } else if (constant->IsLongConstant()) { |
| 5451 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5452 | int32_t low_value = Low32Bits(value); |
| 5453 | int32_t high_value = High32Bits(value); |
| 5454 | Immediate low(low_value); |
| 5455 | Immediate high(high_value); |
| 5456 | if (destination.IsDoubleStackSlot()) { |
| 5457 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5458 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5459 | } else { |
| 5460 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5461 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5462 | } |
| 5463 | } else { |
| 5464 | DCHECK(constant->IsDoubleConstant()); |
| 5465 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5466 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5467 | int32_t low_value = Low32Bits(value); |
| 5468 | int32_t high_value = High32Bits(value); |
| 5469 | Immediate low(low_value); |
| 5470 | Immediate high(high_value); |
| 5471 | if (destination.IsFpuRegister()) { |
| 5472 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5473 | if (value == 0) { |
| 5474 | // Easy handling of 0.0. |
| 5475 | __ xorpd(dest, dest); |
| 5476 | } else { |
| 5477 | __ pushl(high); |
| 5478 | __ pushl(low); |
| 5479 | __ movsd(dest, Address(ESP, 0)); |
| 5480 | __ addl(ESP, Immediate(8)); |
| 5481 | } |
| 5482 | } else { |
| 5483 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5484 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5485 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5486 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5487 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5488 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5489 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5490 | } |
| 5491 | } |
| 5492 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5493 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5494 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5495 | ScratchRegisterScope ensure_scratch( |
| 5496 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5497 | |
| 5498 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5499 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5500 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5501 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5502 | } |
| 5503 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5504 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5505 | ScratchRegisterScope ensure_scratch( |
| 5506 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5507 | |
| 5508 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5509 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5510 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5511 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5512 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5513 | } |
| 5514 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5515 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5516 | ScratchRegisterScope ensure_scratch1( |
| 5517 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5518 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5519 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5520 | ScratchRegisterScope ensure_scratch2( |
| 5521 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5522 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5523 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5524 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5525 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5526 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5527 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5528 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5532 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5533 | Location source = move->GetSource(); |
| 5534 | Location destination = move->GetDestination(); |
| 5535 | |
| 5536 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5537 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5538 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5539 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5540 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5541 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5542 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5543 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5544 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5545 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5546 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5547 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5548 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5549 | // Use XOR Swap algorithm to avoid a temporary. |
| 5550 | DCHECK_NE(source.reg(), destination.reg()); |
| 5551 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5552 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5553 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5554 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5555 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5556 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5557 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5558 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5559 | // Take advantage of the 16 bytes in the XMM register. |
| 5560 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5561 | Address stack(ESP, destination.GetStackIndex()); |
| 5562 | // Load the double into the high doubleword. |
| 5563 | __ movhpd(reg, stack); |
| 5564 | |
| 5565 | // Store the low double into the destination. |
| 5566 | __ movsd(stack, reg); |
| 5567 | |
| 5568 | // Move the high double to the low double. |
| 5569 | __ psrldq(reg, Immediate(8)); |
| 5570 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5571 | // Take advantage of the 16 bytes in the XMM register. |
| 5572 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5573 | Address stack(ESP, source.GetStackIndex()); |
| 5574 | // Load the double into the high doubleword. |
| 5575 | __ movhpd(reg, stack); |
| 5576 | |
| 5577 | // Store the low double into the destination. |
| 5578 | __ movsd(stack, reg); |
| 5579 | |
| 5580 | // Move the high double to the low double. |
| 5581 | __ psrldq(reg, Immediate(8)); |
| 5582 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5583 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5584 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5585 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5586 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | |
| 5590 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5591 | __ pushl(static_cast<Register>(reg)); |
| 5592 | } |
| 5593 | |
| 5594 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5595 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5596 | } |
| 5597 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5598 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5599 | InvokeRuntimeCallingConvention calling_convention; |
| 5600 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5601 | cls, |
| 5602 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5603 | Location::RegisterLocation(EAX), |
| 5604 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5608 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5609 | if (cls->NeedsAccessCheck()) { |
| 5610 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5611 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5612 | cls, |
| 5613 | cls->GetDexPc(), |
| 5614 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5615 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5616 | return; |
| 5617 | } |
| 5618 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5619 | Location out_loc = locations->Out(); |
| 5620 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5621 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5622 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5623 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5624 | DCHECK(!cls->CanCallRuntime()); |
| 5625 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5626 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 5627 | if (kEmitCompilerReadBarrier) { |
| 5628 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 5629 | __ leal(out, Address(current_method, declaring_class_offset)); |
| 5630 | // /* mirror::Class* */ out = out->Read() |
| 5631 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 5632 | } else { |
| 5633 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5634 | __ movl(out, Address(current_method, declaring_class_offset)); |
| 5635 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5636 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5637 | // /* GcRoot<mirror::Class>[] */ out = |
| 5638 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5639 | __ movl(out, Address(current_method, |
| 5640 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
| 5641 | |
| 5642 | size_t cache_offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex()); |
| 5643 | if (kEmitCompilerReadBarrier) { |
| 5644 | // /* GcRoot<mirror::Class>* */ out = &out[type_index] |
| 5645 | __ leal(out, Address(out, cache_offset)); |
| 5646 | // /* mirror::Class* */ out = out->Read() |
| 5647 | codegen_->GenerateReadBarrierForRoot(cls, out_loc, out_loc); |
| 5648 | } else { |
| 5649 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5650 | __ movl(out, Address(out, cache_offset)); |
| 5651 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5652 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5653 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5654 | DCHECK(cls->CanCallRuntime()); |
| 5655 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5656 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5657 | codegen_->AddSlowPath(slow_path); |
| 5658 | |
| 5659 | if (!cls->IsInDexCache()) { |
| 5660 | __ testl(out, out); |
| 5661 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5662 | } |
| 5663 | |
| 5664 | if (cls->MustGenerateClinitCheck()) { |
| 5665 | GenerateClassInitializationCheck(slow_path, out); |
| 5666 | } else { |
| 5667 | __ Bind(slow_path->GetExitLabel()); |
| 5668 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5669 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5674 | LocationSummary* locations = |
| 5675 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5677 | if (check->HasUses()) { |
| 5678 | locations->SetOut(Location::SameAsFirstInput()); |
| 5679 | } |
| 5680 | } |
| 5681 | |
| 5682 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5683 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5684 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5685 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5686 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5687 | GenerateClassInitializationCheck(slow_path, |
| 5688 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5689 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5690 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5691 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5692 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5693 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5694 | Immediate(mirror::Class::kStatusInitialized)); |
| 5695 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5696 | __ Bind(slow_path->GetExitLabel()); |
| 5697 | // No need for memory fence, thanks to the X86 memory model. |
| 5698 | } |
| 5699 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5700 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 5701 | LocationSummary* locations = |
| 5702 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5703 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5704 | locations->SetOut(Location::RequiresRegister()); |
| 5705 | } |
| 5706 | |
| 5707 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5708 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5709 | codegen_->AddSlowPath(slow_path); |
| 5710 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5711 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5712 | Location out_loc = locations->Out(); |
| 5713 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5714 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5715 | |
| 5716 | uint32_t declaring_class_offset = ArtMethod::DeclaringClassOffset().Int32Value(); |
| 5717 | if (kEmitCompilerReadBarrier) { |
| 5718 | // /* GcRoot<mirror::Class>* */ out = &(current_method->declaring_class_) |
| 5719 | __ leal(out, Address(current_method, declaring_class_offset)); |
| 5720 | // /* mirror::Class* */ out = out->Read() |
| 5721 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 5722 | } else { |
| 5723 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5724 | __ movl(out, Address(current_method, declaring_class_offset)); |
| 5725 | } |
| 5726 | |
| 5727 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5728 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5729 | |
| 5730 | size_t cache_offset = CodeGenerator::GetCacheOffset(load->GetStringIndex()); |
| 5731 | if (kEmitCompilerReadBarrier) { |
| 5732 | // /* GcRoot<mirror::String>* */ out = &out[string_index] |
| 5733 | __ leal(out, Address(out, cache_offset)); |
| 5734 | // /* mirror::String* */ out = out->Read() |
| 5735 | codegen_->GenerateReadBarrierForRoot(load, out_loc, out_loc); |
| 5736 | } else { |
| 5737 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5738 | __ movl(out, Address(out, cache_offset)); |
| 5739 | } |
| 5740 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5741 | __ testl(out, out); |
| 5742 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5743 | __ Bind(slow_path->GetExitLabel()); |
| 5744 | } |
| 5745 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5746 | static Address GetExceptionTlsAddress() { |
| 5747 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5748 | } |
| 5749 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5750 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5751 | LocationSummary* locations = |
| 5752 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5753 | locations->SetOut(Location::RequiresRegister()); |
| 5754 | } |
| 5755 | |
| 5756 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5757 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5758 | } |
| 5759 | |
| 5760 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5761 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5762 | } |
| 5763 | |
| 5764 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5765 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5766 | } |
| 5767 | |
| 5768 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5769 | LocationSummary* locations = |
| 5770 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5771 | InvokeRuntimeCallingConvention calling_convention; |
| 5772 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5773 | } |
| 5774 | |
| 5775 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5776 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5777 | instruction, |
| 5778 | instruction->GetDexPc(), |
| 5779 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5780 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5781 | } |
| 5782 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5783 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5784 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5785 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5786 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5787 | case TypeCheckKind::kExactCheck: |
| 5788 | case TypeCheckKind::kAbstractClassCheck: |
| 5789 | case TypeCheckKind::kClassHierarchyCheck: |
| 5790 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5791 | call_kind = |
| 5792 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5793 | break; |
| 5794 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5795 | case TypeCheckKind::kUnresolvedCheck: |
| 5796 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5797 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5798 | break; |
| 5799 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5800 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5801 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5803 | locations->SetInAt(1, Location::Any()); |
| 5804 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5805 | locations->SetOut(Location::RequiresRegister()); |
| 5806 | // When read barriers are enabled, we need a temporary register for |
| 5807 | // some cases. |
| 5808 | if (kEmitCompilerReadBarrier && |
| 5809 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5810 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5811 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
| 5812 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5813 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5814 | } |
| 5815 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5816 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5817 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5818 | Location obj_loc = locations->InAt(0); |
| 5819 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5820 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5821 | Location out_loc = locations->Out(); |
| 5822 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5823 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5824 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5825 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5826 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5827 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5828 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5829 | |
| 5830 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5831 | // Avoid null check if we know obj is not null. |
| 5832 | if (instruction->MustDoNullCheck()) { |
| 5833 | __ testl(obj, obj); |
| 5834 | __ j(kEqual, &zero); |
| 5835 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5836 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5837 | // /* HeapReference<Class> */ out = obj->klass_ |
| 5838 | __ movl(out, Address(obj, class_offset)); |
| 5839 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5840 | |
| 5841 | switch (instruction->GetTypeCheckKind()) { |
| 5842 | case TypeCheckKind::kExactCheck: { |
| 5843 | if (cls.IsRegister()) { |
| 5844 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5845 | } else { |
| 5846 | DCHECK(cls.IsStackSlot()) << cls; |
| 5847 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5848 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5849 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5850 | // Classes must be equal for the instanceof to succeed. |
| 5851 | __ j(kNotEqual, &zero); |
| 5852 | __ movl(out, Immediate(1)); |
| 5853 | __ jmp(&done); |
| 5854 | break; |
| 5855 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5856 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5857 | case TypeCheckKind::kAbstractClassCheck: { |
| 5858 | // If the class is abstract, we eagerly fetch the super class of the |
| 5859 | // object to avoid doing a comparison we know will fail. |
| 5860 | NearLabel loop; |
| 5861 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5862 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5863 | if (kEmitCompilerReadBarrier) { |
| 5864 | // Save the value of `out` into `temp` before overwriting it |
| 5865 | // in the following move operation, as we will need it for the |
| 5866 | // read barrier below. |
| 5867 | Register temp = temp_loc.AsRegister<Register>(); |
| 5868 | __ movl(temp, out); |
| 5869 | } |
| 5870 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5871 | __ movl(out, Address(out, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5872 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5873 | __ testl(out, out); |
| 5874 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5875 | __ j(kEqual, &done); |
| 5876 | if (cls.IsRegister()) { |
| 5877 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5878 | } else { |
| 5879 | DCHECK(cls.IsStackSlot()) << cls; |
| 5880 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5881 | } |
| 5882 | __ j(kNotEqual, &loop); |
| 5883 | __ movl(out, Immediate(1)); |
| 5884 | if (zero.IsLinked()) { |
| 5885 | __ jmp(&done); |
| 5886 | } |
| 5887 | break; |
| 5888 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5889 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5890 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5891 | // Walk over the class hierarchy to find a match. |
| 5892 | NearLabel loop, success; |
| 5893 | __ Bind(&loop); |
| 5894 | if (cls.IsRegister()) { |
| 5895 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5896 | } else { |
| 5897 | DCHECK(cls.IsStackSlot()) << cls; |
| 5898 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5899 | } |
| 5900 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5901 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5902 | if (kEmitCompilerReadBarrier) { |
| 5903 | // Save the value of `out` into `temp` before overwriting it |
| 5904 | // in the following move operation, as we will need it for the |
| 5905 | // read barrier below. |
| 5906 | Register temp = temp_loc.AsRegister<Register>(); |
| 5907 | __ movl(temp, out); |
| 5908 | } |
| 5909 | // /* HeapReference<Class> */ out = out->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5910 | __ movl(out, Address(out, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5911 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, super_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | __ testl(out, out); |
| 5913 | __ j(kNotEqual, &loop); |
| 5914 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5915 | __ jmp(&done); |
| 5916 | __ Bind(&success); |
| 5917 | __ movl(out, Immediate(1)); |
| 5918 | if (zero.IsLinked()) { |
| 5919 | __ jmp(&done); |
| 5920 | } |
| 5921 | break; |
| 5922 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5923 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5924 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5925 | // Do an exact check. |
| 5926 | NearLabel exact_check; |
| 5927 | if (cls.IsRegister()) { |
| 5928 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5929 | } else { |
| 5930 | DCHECK(cls.IsStackSlot()) << cls; |
| 5931 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5932 | } |
| 5933 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5934 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 5935 | Location temp_loc = kEmitCompilerReadBarrier ? locations->GetTemp(0) : Location::NoLocation(); |
| 5936 | if (kEmitCompilerReadBarrier) { |
| 5937 | // Save the value of `out` into `temp` before overwriting it |
| 5938 | // in the following move operation, as we will need it for the |
| 5939 | // read barrier below. |
| 5940 | Register temp = temp_loc.AsRegister<Register>(); |
| 5941 | __ movl(temp, out); |
| 5942 | } |
| 5943 | // /* HeapReference<Class> */ out = out->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5944 | __ movl(out, Address(out, component_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5945 | codegen_->MaybeGenerateReadBarrier(instruction, out_loc, out_loc, temp_loc, component_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5946 | __ testl(out, out); |
| 5947 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5948 | __ j(kEqual, &done); |
| 5949 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5950 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5951 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5952 | __ movl(out, Immediate(1)); |
| 5953 | __ jmp(&done); |
| 5954 | break; |
| 5955 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | case TypeCheckKind::kArrayCheck: { |
| 5958 | if (cls.IsRegister()) { |
| 5959 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5960 | } else { |
| 5961 | DCHECK(cls.IsStackSlot()) << cls; |
| 5962 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5963 | } |
| 5964 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5965 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 5966 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5967 | codegen_->AddSlowPath(slow_path); |
| 5968 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5969 | __ movl(out, Immediate(1)); |
| 5970 | if (zero.IsLinked()) { |
| 5971 | __ jmp(&done); |
| 5972 | } |
| 5973 | break; |
| 5974 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5975 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5976 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5977 | case TypeCheckKind::kInterfaceCheck: { |
| 5978 | // Note that we indeed only call on slow path, but we always go |
| 5979 | // into the slow path for the unresolved & interface check |
| 5980 | // cases. |
| 5981 | // |
| 5982 | // We cannot directly call the InstanceofNonTrivial runtime |
| 5983 | // entry point without resorting to a type checking slow path |
| 5984 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 5985 | // require to assign fixed registers for the inputs of this |
| 5986 | // HInstanceOf instruction (following the runtime calling |
| 5987 | // convention), which might be cluttered by the potential first |
| 5988 | // read barrier emission at the beginning of this method. |
| 5989 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5990 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 5991 | /* is_fatal */ false); |
| 5992 | codegen_->AddSlowPath(slow_path); |
| 5993 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5994 | if (zero.IsLinked()) { |
| 5995 | __ jmp(&done); |
| 5996 | } |
| 5997 | break; |
| 5998 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5999 | } |
| 6000 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6001 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6002 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6003 | __ xorl(out, out); |
| 6004 | } |
| 6005 | |
| 6006 | if (done.IsLinked()) { |
| 6007 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6008 | } |
| 6009 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6010 | if (slow_path != nullptr) { |
| 6011 | __ Bind(slow_path->GetExitLabel()); |
| 6012 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6013 | } |
| 6014 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6015 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6016 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6017 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6018 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6019 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6020 | case TypeCheckKind::kExactCheck: |
| 6021 | case TypeCheckKind::kAbstractClassCheck: |
| 6022 | case TypeCheckKind::kClassHierarchyCheck: |
| 6023 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6024 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6025 | LocationSummary::kCallOnSlowPath : |
| 6026 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6027 | break; |
| 6028 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6029 | case TypeCheckKind::kUnresolvedCheck: |
| 6030 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6031 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6032 | break; |
| 6033 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6034 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6036 | locations->SetInAt(1, Location::Any()); |
| 6037 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6038 | locations->AddTemp(Location::RequiresRegister()); |
| 6039 | // When read barriers are enabled, we need an additional temporary |
| 6040 | // register for some cases. |
| 6041 | if (kEmitCompilerReadBarrier && |
| 6042 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6043 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6044 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6045 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6046 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 6050 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6051 | Location obj_loc = locations->InAt(0); |
| 6052 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6053 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6054 | Location temp_loc = locations->GetTemp(0); |
| 6055 | Register temp = temp_loc.AsRegister<Register>(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6056 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6057 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6058 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6059 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6060 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6061 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6062 | bool is_type_check_slow_path_fatal = |
| 6063 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6064 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6065 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6066 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6067 | !instruction->CanThrowIntoCatchBlock(); |
| 6068 | SlowPathCode* type_check_slow_path = |
| 6069 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6070 | is_type_check_slow_path_fatal); |
| 6071 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6072 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6073 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6074 | // Avoid null check if we know obj is not null. |
| 6075 | if (instruction->MustDoNullCheck()) { |
| 6076 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6077 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6078 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6079 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6080 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6081 | __ movl(temp, Address(obj, class_offset)); |
| 6082 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6083 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6084 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6085 | case TypeCheckKind::kExactCheck: |
| 6086 | case TypeCheckKind::kArrayCheck: { |
| 6087 | if (cls.IsRegister()) { |
| 6088 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6089 | } else { |
| 6090 | DCHECK(cls.IsStackSlot()) << cls; |
| 6091 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6092 | } |
| 6093 | // Jump to slow path for throwing the exception or doing a |
| 6094 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6095 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6096 | break; |
| 6097 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6098 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6099 | case TypeCheckKind::kAbstractClassCheck: { |
| 6100 | // If the class is abstract, we eagerly fetch the super class of the |
| 6101 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6102 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6103 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6104 | Location temp2_loc = |
| 6105 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 6106 | if (kEmitCompilerReadBarrier) { |
| 6107 | // Save the value of `temp` into `temp2` before overwriting it |
| 6108 | // in the following move operation, as we will need it for the |
| 6109 | // read barrier below. |
| 6110 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 6111 | __ movl(temp2, temp); |
| 6112 | } |
| 6113 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6114 | __ movl(temp, Address(temp, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6115 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 6116 | |
| 6117 | // If the class reference currently in `temp` is not null, jump |
| 6118 | // to the `compare_classes` label to compare it with the checked |
| 6119 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6120 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6121 | __ j(kNotEqual, &compare_classes); |
| 6122 | // Otherwise, jump to the slow path to throw the exception. |
| 6123 | // |
| 6124 | // But before, move back the object's class into `temp` before |
| 6125 | // going into the slow path, as it has been overwritten in the |
| 6126 | // meantime. |
| 6127 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6128 | __ movl(temp, Address(obj, class_offset)); |
| 6129 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 6130 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6131 | |
| 6132 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6133 | if (cls.IsRegister()) { |
| 6134 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6135 | } else { |
| 6136 | DCHECK(cls.IsStackSlot()) << cls; |
| 6137 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6138 | } |
| 6139 | __ j(kNotEqual, &loop); |
| 6140 | break; |
| 6141 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6142 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6144 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6145 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6146 | __ Bind(&loop); |
| 6147 | if (cls.IsRegister()) { |
| 6148 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6149 | } else { |
| 6150 | DCHECK(cls.IsStackSlot()) << cls; |
| 6151 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6152 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6153 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6154 | |
| 6155 | Location temp2_loc = |
| 6156 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 6157 | if (kEmitCompilerReadBarrier) { |
| 6158 | // Save the value of `temp` into `temp2` before overwriting it |
| 6159 | // in the following move operation, as we will need it for the |
| 6160 | // read barrier below. |
| 6161 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 6162 | __ movl(temp2, temp); |
| 6163 | } |
| 6164 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6165 | __ movl(temp, Address(temp, super_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6166 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, temp2_loc, super_offset); |
| 6167 | |
| 6168 | // If the class reference currently in `temp` is not null, jump |
| 6169 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6170 | __ testl(temp, temp); |
| 6171 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6172 | // Otherwise, jump to the slow path to throw the exception. |
| 6173 | // |
| 6174 | // But before, move back the object's class into `temp` before |
| 6175 | // going into the slow path, as it has been overwritten in the |
| 6176 | // meantime. |
| 6177 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6178 | __ movl(temp, Address(obj, class_offset)); |
| 6179 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 6180 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6181 | break; |
| 6182 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6183 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6185 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6186 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6187 | if (cls.IsRegister()) { |
| 6188 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6189 | } else { |
| 6190 | DCHECK(cls.IsStackSlot()) << cls; |
| 6191 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6192 | } |
| 6193 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6194 | |
| 6195 | // Otherwise, we need to check that the object's class is a non-primitive array. |
| 6196 | Location temp2_loc = |
| 6197 | kEmitCompilerReadBarrier ? locations->GetTemp(1) : Location::NoLocation(); |
| 6198 | if (kEmitCompilerReadBarrier) { |
| 6199 | // Save the value of `temp` into `temp2` before overwriting it |
| 6200 | // in the following move operation, as we will need it for the |
| 6201 | // read barrier below. |
| 6202 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 6203 | __ movl(temp2, temp); |
| 6204 | } |
| 6205 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6207 | codegen_->MaybeGenerateReadBarrier( |
| 6208 | instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 6209 | |
| 6210 | // If the component type is not null (i.e. the object is indeed |
| 6211 | // an array), jump to label `check_non_primitive_component_type` |
| 6212 | // to further check that this component type is not a primitive |
| 6213 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6214 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6215 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6216 | // Otherwise, jump to the slow path to throw the exception. |
| 6217 | // |
| 6218 | // But before, move back the object's class into `temp` before |
| 6219 | // going into the slow path, as it has been overwritten in the |
| 6220 | // meantime. |
| 6221 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6222 | __ movl(temp, Address(obj, class_offset)); |
| 6223 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 6224 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6225 | |
| 6226 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6227 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6228 | __ j(kEqual, &done); |
| 6229 | // Same comment as above regarding `temp` and the slow path. |
| 6230 | // /* HeapReference<Class> */ temp = obj->klass_ |
| 6231 | __ movl(temp, Address(obj, class_offset)); |
| 6232 | codegen_->MaybeGenerateReadBarrier(instruction, temp_loc, temp_loc, obj_loc, class_offset); |
| 6233 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6234 | break; |
| 6235 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6236 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6237 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6238 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6239 | // We always go into the type check slow path for the unresolved & |
| 6240 | // interface check cases. |
| 6241 | // |
| 6242 | // We cannot directly call the CheckCast runtime entry point |
| 6243 | // without resorting to a type checking slow path here (i.e. by |
| 6244 | // calling InvokeRuntime directly), as it would require to |
| 6245 | // assign fixed registers for the inputs of this HInstanceOf |
| 6246 | // instruction (following the runtime calling convention), which |
| 6247 | // might be cluttered by the potential first read barrier |
| 6248 | // emission at the beginning of this method. |
| 6249 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6250 | break; |
| 6251 | } |
| 6252 | __ Bind(&done); |
| 6253 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6254 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6255 | } |
| 6256 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6257 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6258 | LocationSummary* locations = |
| 6259 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6260 | InvokeRuntimeCallingConvention calling_convention; |
| 6261 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6262 | } |
| 6263 | |
| 6264 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6265 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6266 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6267 | instruction, |
| 6268 | instruction->GetDexPc(), |
| 6269 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6270 | if (instruction->IsEnter()) { |
| 6271 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6272 | } else { |
| 6273 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6274 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6275 | } |
| 6276 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6277 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6278 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6279 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6280 | |
| 6281 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6282 | LocationSummary* locations = |
| 6283 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6284 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6285 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6286 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6287 | locations->SetInAt(1, Location::Any()); |
| 6288 | locations->SetOut(Location::SameAsFirstInput()); |
| 6289 | } |
| 6290 | |
| 6291 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6292 | HandleBitwiseOperation(instruction); |
| 6293 | } |
| 6294 | |
| 6295 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6296 | HandleBitwiseOperation(instruction); |
| 6297 | } |
| 6298 | |
| 6299 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6300 | HandleBitwiseOperation(instruction); |
| 6301 | } |
| 6302 | |
| 6303 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6304 | LocationSummary* locations = instruction->GetLocations(); |
| 6305 | Location first = locations->InAt(0); |
| 6306 | Location second = locations->InAt(1); |
| 6307 | DCHECK(first.Equals(locations->Out())); |
| 6308 | |
| 6309 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6310 | if (second.IsRegister()) { |
| 6311 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6312 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6313 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6314 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6315 | } else { |
| 6316 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6317 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6318 | } |
| 6319 | } else if (second.IsConstant()) { |
| 6320 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6321 | __ andl(first.AsRegister<Register>(), |
| 6322 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6323 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6324 | __ orl(first.AsRegister<Register>(), |
| 6325 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6326 | } else { |
| 6327 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6328 | __ xorl(first.AsRegister<Register>(), |
| 6329 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6330 | } |
| 6331 | } else { |
| 6332 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6333 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6334 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6335 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6336 | } else { |
| 6337 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6338 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6339 | } |
| 6340 | } |
| 6341 | } else { |
| 6342 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6343 | if (second.IsRegisterPair()) { |
| 6344 | if (instruction->IsAnd()) { |
| 6345 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6346 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6347 | } else if (instruction->IsOr()) { |
| 6348 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6349 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6350 | } else { |
| 6351 | DCHECK(instruction->IsXor()); |
| 6352 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6353 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6354 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6355 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6356 | if (instruction->IsAnd()) { |
| 6357 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6358 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6359 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6360 | } else if (instruction->IsOr()) { |
| 6361 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6362 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6363 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6364 | } else { |
| 6365 | DCHECK(instruction->IsXor()); |
| 6366 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6367 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6368 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6369 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6370 | } else { |
| 6371 | DCHECK(second.IsConstant()) << second; |
| 6372 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6373 | int32_t low_value = Low32Bits(value); |
| 6374 | int32_t high_value = High32Bits(value); |
| 6375 | Immediate low(low_value); |
| 6376 | Immediate high(high_value); |
| 6377 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6378 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6379 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6380 | if (low_value == 0) { |
| 6381 | __ xorl(first_low, first_low); |
| 6382 | } else if (low_value != -1) { |
| 6383 | __ andl(first_low, low); |
| 6384 | } |
| 6385 | if (high_value == 0) { |
| 6386 | __ xorl(first_high, first_high); |
| 6387 | } else if (high_value != -1) { |
| 6388 | __ andl(first_high, high); |
| 6389 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6390 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6391 | if (low_value != 0) { |
| 6392 | __ orl(first_low, low); |
| 6393 | } |
| 6394 | if (high_value != 0) { |
| 6395 | __ orl(first_high, high); |
| 6396 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6397 | } else { |
| 6398 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6399 | if (low_value != 0) { |
| 6400 | __ xorl(first_low, low); |
| 6401 | } |
| 6402 | if (high_value != 0) { |
| 6403 | __ xorl(first_high, high); |
| 6404 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6405 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6406 | } |
| 6407 | } |
| 6408 | } |
| 6409 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6410 | void CodeGeneratorX86::GenerateReadBarrier(HInstruction* instruction, |
| 6411 | Location out, |
| 6412 | Location ref, |
| 6413 | Location obj, |
| 6414 | uint32_t offset, |
| 6415 | Location index) { |
| 6416 | DCHECK(kEmitCompilerReadBarrier); |
| 6417 | |
| 6418 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6419 | // reference will be carried out by the runtime within the slow |
| 6420 | // path. |
| 6421 | // |
| 6422 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6423 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6424 | // not used by the artReadBarrierSlow entry point. |
| 6425 | // |
| 6426 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6427 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6428 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6429 | AddSlowPath(slow_path); |
| 6430 | |
| 6431 | // TODO: When read barrier has a fast path, add it here. |
| 6432 | /* Currently the read barrier call is inserted after the original load. |
| 6433 | * However, if we have a fast path, we need to perform the load of obj.LockWord *before* the |
| 6434 | * original load. This load-load ordering is required by the read barrier. |
| 6435 | * The fast path/slow path (for Baker's algorithm) should look like: |
| 6436 | * |
| 6437 | * bool isGray = obj.LockWord & kReadBarrierMask; |
| 6438 | * lfence; // load fence or artificial data dependence to prevent load-load reordering |
| 6439 | * ref = obj.field; // this is the original load |
| 6440 | * if (isGray) { |
| 6441 | * ref = Mark(ref); // ideally the slow path just does Mark(ref) |
| 6442 | * } |
| 6443 | */ |
| 6444 | |
| 6445 | __ jmp(slow_path->GetEntryLabel()); |
| 6446 | __ Bind(slow_path->GetExitLabel()); |
| 6447 | } |
| 6448 | |
| 6449 | void CodeGeneratorX86::MaybeGenerateReadBarrier(HInstruction* instruction, |
| 6450 | Location out, |
| 6451 | Location ref, |
| 6452 | Location obj, |
| 6453 | uint32_t offset, |
| 6454 | Location index) { |
| 6455 | if (kEmitCompilerReadBarrier) { |
| 6456 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6457 | // by the runtime within the slow path. |
| 6458 | GenerateReadBarrier(instruction, out, ref, obj, offset, index); |
| 6459 | } else if (kPoisonHeapReferences) { |
| 6460 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6461 | } |
| 6462 | } |
| 6463 | |
| 6464 | void CodeGeneratorX86::GenerateReadBarrierForRoot(HInstruction* instruction, |
| 6465 | Location out, |
| 6466 | Location root) { |
| 6467 | DCHECK(kEmitCompilerReadBarrier); |
| 6468 | |
| 6469 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6470 | // not need to do anything special for this here. |
| 6471 | SlowPathCode* slow_path = |
| 6472 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6473 | AddSlowPath(slow_path); |
| 6474 | |
| 6475 | // TODO: Implement a fast path for ReadBarrierForRoot, performing |
| 6476 | // the following operation (for Baker's algorithm): |
| 6477 | // |
| 6478 | // if (thread.tls32_.is_gc_marking) { |
| 6479 | // root = Mark(root); |
| 6480 | // } |
| 6481 | |
| 6482 | __ jmp(slow_path->GetEntryLabel()); |
| 6483 | __ Bind(slow_path->GetExitLabel()); |
| 6484 | } |
| 6485 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6486 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6487 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6488 | LOG(FATAL) << "Unreachable"; |
| 6489 | } |
| 6490 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6491 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6492 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6493 | LOG(FATAL) << "Unreachable"; |
| 6494 | } |
| 6495 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 6496 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 6497 | DCHECK(codegen_->IsBaseline()); |
| 6498 | LocationSummary* locations = |
| 6499 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6500 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 6501 | } |
| 6502 | |
| 6503 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 6504 | DCHECK(codegen_->IsBaseline()); |
| 6505 | // Will be generated at use site. |
| 6506 | } |
| 6507 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6508 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6509 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6510 | LocationSummary* locations = |
| 6511 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6512 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6513 | } |
| 6514 | |
| 6515 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6516 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6517 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 6518 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6519 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6520 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6521 | |
| 6522 | // Create a series of compare/jumps. |
| 6523 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 6524 | for (int i = 0; i < num_entries; i++) { |
| 6525 | int32_t case_value = lower_bound + i; |
| 6526 | if (case_value == 0) { |
| 6527 | __ testl(value_reg, value_reg); |
| 6528 | } else { |
| 6529 | __ cmpl(value_reg, Immediate(case_value)); |
| 6530 | } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6531 | __ j(kEqual, codegen_->GetLabelOf(successors[i])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6532 | } |
| 6533 | |
| 6534 | // And the default for any other value. |
| 6535 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 6536 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 6537 | } |
| 6538 | } |
| 6539 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6540 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6541 | LocationSummary* locations = |
| 6542 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6543 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6544 | |
| 6545 | // Constant area pointer. |
| 6546 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6547 | |
| 6548 | // And the temporary we need. |
| 6549 | locations->AddTemp(Location::RequiresRegister()); |
| 6550 | } |
| 6551 | |
| 6552 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6553 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6554 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 6555 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6556 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6557 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6558 | |
| 6559 | // Optimizing has a jump area. |
| 6560 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6561 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6562 | |
| 6563 | // Remove the bias, if needed. |
| 6564 | if (lower_bound != 0) { |
| 6565 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6566 | value_reg = temp_reg; |
| 6567 | } |
| 6568 | |
| 6569 | // Is the value in range? |
| 6570 | DCHECK_GE(num_entries, 1); |
| 6571 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6572 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6573 | |
| 6574 | // We are in the range of the table. |
| 6575 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6576 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6577 | |
| 6578 | // Compute the actual target address by adding in constant_area. |
| 6579 | __ addl(temp_reg, constant_area); |
| 6580 | |
| 6581 | // And jump. |
| 6582 | __ jmp(temp_reg); |
| 6583 | } |
| 6584 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6585 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6586 | HX86ComputeBaseMethodAddress* insn) { |
| 6587 | LocationSummary* locations = |
| 6588 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6589 | locations->SetOut(Location::RequiresRegister()); |
| 6590 | } |
| 6591 | |
| 6592 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6593 | HX86ComputeBaseMethodAddress* insn) { |
| 6594 | LocationSummary* locations = insn->GetLocations(); |
| 6595 | Register reg = locations->Out().AsRegister<Register>(); |
| 6596 | |
| 6597 | // Generate call to next instruction. |
| 6598 | Label next_instruction; |
| 6599 | __ call(&next_instruction); |
| 6600 | __ Bind(&next_instruction); |
| 6601 | |
| 6602 | // Remember this offset for later use with constant area. |
| 6603 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6604 | |
| 6605 | // Grab the return address off the stack. |
| 6606 | __ popl(reg); |
| 6607 | } |
| 6608 | |
| 6609 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6610 | HX86LoadFromConstantTable* insn) { |
| 6611 | LocationSummary* locations = |
| 6612 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6613 | |
| 6614 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6615 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6616 | |
| 6617 | // If we don't need to be materialized, we only need the inputs to be set. |
| 6618 | if (!insn->NeedsMaterialization()) { |
| 6619 | return; |
| 6620 | } |
| 6621 | |
| 6622 | switch (insn->GetType()) { |
| 6623 | case Primitive::kPrimFloat: |
| 6624 | case Primitive::kPrimDouble: |
| 6625 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6626 | break; |
| 6627 | |
| 6628 | case Primitive::kPrimInt: |
| 6629 | locations->SetOut(Location::RequiresRegister()); |
| 6630 | break; |
| 6631 | |
| 6632 | default: |
| 6633 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 6638 | if (!insn->NeedsMaterialization()) { |
| 6639 | return; |
| 6640 | } |
| 6641 | |
| 6642 | LocationSummary* locations = insn->GetLocations(); |
| 6643 | Location out = locations->Out(); |
| 6644 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 6645 | HConstant *value = insn->GetConstant(); |
| 6646 | |
| 6647 | switch (insn->GetType()) { |
| 6648 | case Primitive::kPrimFloat: |
| 6649 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 6650 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 6651 | break; |
| 6652 | |
| 6653 | case Primitive::kPrimDouble: |
| 6654 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 6655 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 6656 | break; |
| 6657 | |
| 6658 | case Primitive::kPrimInt: |
| 6659 | __ movl(out.AsRegister<Register>(), |
| 6660 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 6661 | break; |
| 6662 | |
| 6663 | default: |
| 6664 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6665 | } |
| 6666 | } |
| 6667 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6668 | /** |
| 6669 | * Class to handle late fixup of offsets into constant area. |
| 6670 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 6671 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6672 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6673 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 6674 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6675 | |
| 6676 | protected: |
| 6677 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6678 | |
| 6679 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6680 | |
| 6681 | private: |
| 6682 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6683 | // Patch the correct offset for the instruction. The place to patch is the |
| 6684 | // last 4 bytes of the instruction. |
| 6685 | // The value to patch is the distance from the offset in the constant area |
| 6686 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6687 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6688 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6689 | |
| 6690 | // Patch in the right value. |
| 6691 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6692 | } |
| 6693 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6694 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6695 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6696 | }; |
| 6697 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6698 | /** |
| 6699 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6700 | * constant area. |
| 6701 | */ |
| 6702 | class JumpTableRIPFixup : public RIPFixup { |
| 6703 | public: |
| 6704 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 6705 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 6706 | |
| 6707 | void CreateJumpTable() { |
| 6708 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 6709 | |
| 6710 | // Ensure that the reference to the jump table has the correct offset. |
| 6711 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6712 | SetOffset(offset_in_constant_table); |
| 6713 | |
| 6714 | // The label values in the jump table are computed relative to the |
| 6715 | // instruction addressing the constant area. |
| 6716 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 6717 | |
| 6718 | // Populate the jump table with the correct values for the jump table. |
| 6719 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6720 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6721 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6722 | // The value that we want is the target offset - the position of the table. |
| 6723 | for (int32_t i = 0; i < num_entries; i++) { |
| 6724 | HBasicBlock* b = successors[i]; |
| 6725 | Label* l = codegen_->GetLabelOf(b); |
| 6726 | DCHECK(l->IsBound()); |
| 6727 | int32_t offset_to_block = l->Position() - relative_offset; |
| 6728 | assembler->AppendInt32(offset_to_block); |
| 6729 | } |
| 6730 | } |
| 6731 | |
| 6732 | private: |
| 6733 | const HX86PackedSwitch* switch_instr_; |
| 6734 | }; |
| 6735 | |
| 6736 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 6737 | // Generate the constant area if needed. |
| 6738 | X86Assembler* assembler = GetAssembler(); |
| 6739 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 6740 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 6741 | // byte values. |
| 6742 | assembler->Align(4, 0); |
| 6743 | constant_area_start_ = assembler->CodeSize(); |
| 6744 | |
| 6745 | // Populate any jump tables. |
| 6746 | for (auto jump_table : fixups_to_jump_tables_) { |
| 6747 | jump_table->CreateJumpTable(); |
| 6748 | } |
| 6749 | |
| 6750 | // And now add the constant area to the generated code. |
| 6751 | assembler->AddConstantArea(); |
| 6752 | } |
| 6753 | |
| 6754 | // And finish up. |
| 6755 | CodeGenerator::Finalize(allocator); |
| 6756 | } |
| 6757 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6758 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 6759 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 6760 | return Address(reg, kDummy32BitOffset, fixup); |
| 6761 | } |
| 6762 | |
| 6763 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 6764 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 6765 | return Address(reg, kDummy32BitOffset, fixup); |
| 6766 | } |
| 6767 | |
| 6768 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 6769 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 6770 | return Address(reg, kDummy32BitOffset, fixup); |
| 6771 | } |
| 6772 | |
| 6773 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 6774 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 6775 | return Address(reg, kDummy32BitOffset, fixup); |
| 6776 | } |
| 6777 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6778 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 6779 | Register reg, |
| 6780 | Register value) { |
| 6781 | // Create a fixup to be used to create and address the jump table. |
| 6782 | JumpTableRIPFixup* table_fixup = |
| 6783 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 6784 | |
| 6785 | // We have to populate the jump tables. |
| 6786 | fixups_to_jump_tables_.push_back(table_fixup); |
| 6787 | |
| 6788 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 6789 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 6790 | } |
| 6791 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6792 | // TODO: target as memory. |
| 6793 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 6794 | if (!target.IsValid()) { |
| 6795 | DCHECK(type == Primitive::kPrimVoid); |
| 6796 | return; |
| 6797 | } |
| 6798 | |
| 6799 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 6800 | |
| 6801 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 6802 | if (target.Equals(return_loc)) { |
| 6803 | return; |
| 6804 | } |
| 6805 | |
| 6806 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 6807 | // with the else branch. |
| 6808 | if (type == Primitive::kPrimLong) { |
| 6809 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6810 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 6811 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 6812 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6813 | } else { |
| 6814 | // Let the parallel move resolver take care of all of this. |
| 6815 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 6816 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 6817 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 6818 | } |
| 6819 | } |
| 6820 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 6821 | #undef __ |
| 6822 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6823 | } // namespace x86 |
| 6824 | } // namespace art |