Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; |
| 47 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 53 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 55 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 60 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 61 | // Live registers will be restored in the catch block if caught. |
| 62 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 63 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 64 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 65 | instruction_, |
| 66 | instruction_->GetDexPc(), |
| 67 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 68 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 71 | bool IsFatal() const OVERRIDE { return true; } |
| 72 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 73 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 74 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 76 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 78 | }; |
| 79 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 80 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | public: |
| 82 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 83 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 84 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 87 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 88 | // Live registers will be restored in the catch block if caught. |
| 89 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 90 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 92 | instruction_, |
| 93 | instruction_->GetDexPc(), |
| 94 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 95 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 98 | bool IsFatal() const OVERRIDE { return true; } |
| 99 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 100 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 101 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | private: |
| 103 | HDivZeroCheck* const instruction_; |
| 104 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 105 | }; |
| 106 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 107 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 108 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 109 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 111 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(reg_); |
| 115 | } else { |
| 116 | __ movl(reg_, Immediate(0)); |
| 117 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | __ jmp(GetExitLabel()); |
| 119 | } |
| 120 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 121 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 122 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | private: |
| 124 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | bool is_div_; |
| 126 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 129 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 133 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 134 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 135 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 136 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 137 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 138 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 139 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 140 | // Live registers will be restored in the catch block if caught. |
| 141 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 142 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 144 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 147 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 148 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 149 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 150 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 151 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 152 | instruction_, |
| 153 | instruction_->GetDexPc(), |
| 154 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 155 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 158 | bool IsFatal() const OVERRIDE { return true; } |
| 159 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 160 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 161 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 163 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 164 | |
| 165 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 166 | }; |
| 167 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 168 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 170 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 171 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 172 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 173 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 174 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 175 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 176 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 177 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 178 | instruction_, |
| 179 | instruction_->GetDexPc(), |
| 180 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 181 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 182 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 183 | if (successor_ == nullptr) { |
| 184 | __ jmp(GetReturnLabel()); |
| 185 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 186 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 187 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 190 | Label* GetReturnLabel() { |
| 191 | DCHECK(successor_ == nullptr); |
| 192 | return &return_label_; |
| 193 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 194 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 195 | HBasicBlock* GetSuccessor() const { |
| 196 | return successor_; |
| 197 | } |
| 198 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 199 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 200 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | private: |
| 202 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 203 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 204 | Label return_label_; |
| 205 | |
| 206 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 207 | }; |
| 208 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 209 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 210 | public: |
| 211 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 212 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 213 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 214 | LocationSummary* locations = instruction_->GetLocations(); |
| 215 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 216 | |
| 217 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 218 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 219 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 220 | |
| 221 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 222 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 223 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 224 | instruction_, |
| 225 | instruction_->GetDexPc(), |
| 226 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 227 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 228 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 229 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | |
| 231 | __ jmp(GetExitLabel()); |
| 232 | } |
| 233 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 234 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 235 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 236 | private: |
| 237 | HLoadString* const instruction_; |
| 238 | |
| 239 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 240 | }; |
| 241 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 242 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 243 | public: |
| 244 | LoadClassSlowPathX86(HLoadClass* cls, |
| 245 | HInstruction* at, |
| 246 | uint32_t dex_pc, |
| 247 | bool do_clinit) |
| 248 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 249 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 250 | } |
| 251 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 252 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | LocationSummary* locations = at_->GetLocations(); |
| 254 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 255 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 256 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | |
| 258 | InvokeRuntimeCallingConvention calling_convention; |
| 259 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 260 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 261 | : QUICK_ENTRY_POINT(pInitializeType), |
| 262 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 263 | if (do_clinit_) { |
| 264 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 265 | } else { |
| 266 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 267 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 268 | |
| 269 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | Location out = locations->Out(); |
| 271 | if (out.IsValid()) { |
| 272 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 273 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 274 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 275 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 276 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | __ jmp(GetExitLabel()); |
| 278 | } |
| 279 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 280 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 281 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 282 | private: |
| 283 | // The class this slow path will load. |
| 284 | HLoadClass* const cls_; |
| 285 | |
| 286 | // The instruction where this slow path is happening. |
| 287 | // (Might be the load class or an initialization check). |
| 288 | HInstruction* const at_; |
| 289 | |
| 290 | // The dex PC of `at_`. |
| 291 | const uint32_t dex_pc_; |
| 292 | |
| 293 | // Whether to initialize the class. |
| 294 | const bool do_clinit_; |
| 295 | |
| 296 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 297 | }; |
| 298 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 299 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 300 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 301 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 302 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 304 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 306 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 307 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 308 | DCHECK(instruction_->IsCheckCast() |
| 309 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 310 | |
| 311 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 312 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 313 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 314 | if (!is_fatal_) { |
| 315 | SaveLiveRegisters(codegen, locations); |
| 316 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 317 | |
| 318 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 319 | // move resolver. |
| 320 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 321 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 322 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 323 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 324 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 325 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 326 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 327 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 329 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 330 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 331 | instruction_, |
| 332 | instruction_->GetDexPc(), |
| 333 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 334 | CheckEntrypointTypes< |
| 335 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 336 | } else { |
| 337 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 338 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 339 | instruction_, |
| 340 | instruction_->GetDexPc(), |
| 341 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 342 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 345 | if (!is_fatal_) { |
| 346 | if (instruction_->IsInstanceOf()) { |
| 347 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 348 | } |
| 349 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | __ jmp(GetExitLabel()); |
| 352 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 355 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 356 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 357 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 358 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 360 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 361 | |
| 362 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 363 | }; |
| 364 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 365 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 366 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 367 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | : instruction_(instruction) {} |
| 369 | |
| 370 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 371 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 372 | __ Bind(GetEntryLabel()); |
| 373 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 374 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 375 | instruction_, |
| 376 | instruction_->GetDexPc(), |
| 377 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 378 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 381 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 382 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 383 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 384 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 386 | }; |
| 387 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 388 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 389 | public: |
| 390 | explicit ArraySetSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
| 391 | |
| 392 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 393 | LocationSummary* locations = instruction_->GetLocations(); |
| 394 | __ Bind(GetEntryLabel()); |
| 395 | SaveLiveRegisters(codegen, locations); |
| 396 | |
| 397 | InvokeRuntimeCallingConvention calling_convention; |
| 398 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 399 | parallel_move.AddMove( |
| 400 | locations->InAt(0), |
| 401 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 402 | Primitive::kPrimNot, |
| 403 | nullptr); |
| 404 | parallel_move.AddMove( |
| 405 | locations->InAt(1), |
| 406 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 407 | Primitive::kPrimInt, |
| 408 | nullptr); |
| 409 | parallel_move.AddMove( |
| 410 | locations->InAt(2), |
| 411 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 412 | Primitive::kPrimNot, |
| 413 | nullptr); |
| 414 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 415 | |
| 416 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 417 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 418 | instruction_, |
| 419 | instruction_->GetDexPc(), |
| 420 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 421 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | RestoreLiveRegisters(codegen, locations); |
| 423 | __ jmp(GetExitLabel()); |
| 424 | } |
| 425 | |
| 426 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 427 | |
| 428 | private: |
| 429 | HInstruction* const instruction_; |
| 430 | |
| 431 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 432 | }; |
| 433 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 434 | // Slow path marking an object during a read barrier. |
| 435 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 436 | public: |
| 437 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
| 438 | : instruction_(instruction), out_(out), obj_(obj) { |
| 439 | DCHECK(kEmitCompilerReadBarrier); |
| 440 | } |
| 441 | |
| 442 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 443 | |
| 444 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 445 | LocationSummary* locations = instruction_->GetLocations(); |
| 446 | Register reg_out = out_.AsRegister<Register>(); |
| 447 | DCHECK(locations->CanCall()); |
| 448 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 449 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 450 | instruction_->IsStaticFieldGet() || |
| 451 | instruction_->IsArrayGet() || |
| 452 | instruction_->IsLoadClass() || |
| 453 | instruction_->IsLoadString() || |
| 454 | instruction_->IsInstanceOf() || |
| 455 | instruction_->IsCheckCast()) |
| 456 | << "Unexpected instruction in read barrier marking slow path: " |
| 457 | << instruction_->DebugName(); |
| 458 | |
| 459 | __ Bind(GetEntryLabel()); |
| 460 | SaveLiveRegisters(codegen, locations); |
| 461 | |
| 462 | InvokeRuntimeCallingConvention calling_convention; |
| 463 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 464 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 465 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 466 | instruction_, |
| 467 | instruction_->GetDexPc(), |
| 468 | this); |
| 469 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 470 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 471 | |
| 472 | RestoreLiveRegisters(codegen, locations); |
| 473 | __ jmp(GetExitLabel()); |
| 474 | } |
| 475 | |
| 476 | private: |
| 477 | HInstruction* const instruction_; |
| 478 | const Location out_; |
| 479 | const Location obj_; |
| 480 | |
| 481 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 482 | }; |
| 483 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 484 | // Slow path generating a read barrier for a heap reference. |
| 485 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 486 | public: |
| 487 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 488 | Location out, |
| 489 | Location ref, |
| 490 | Location obj, |
| 491 | uint32_t offset, |
| 492 | Location index) |
| 493 | : instruction_(instruction), |
| 494 | out_(out), |
| 495 | ref_(ref), |
| 496 | obj_(obj), |
| 497 | offset_(offset), |
| 498 | index_(index) { |
| 499 | DCHECK(kEmitCompilerReadBarrier); |
| 500 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 501 | // has been overwritten by (or after) the heap object reference load |
| 502 | // to be instrumented, e.g.: |
| 503 | // |
| 504 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 505 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 506 | // |
| 507 | // In that case, we have lost the information about the original |
| 508 | // object, and the emitted read barrier cannot work properly. |
| 509 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 510 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 511 | } |
| 512 | |
| 513 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 514 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 515 | LocationSummary* locations = instruction_->GetLocations(); |
| 516 | Register reg_out = out_.AsRegister<Register>(); |
| 517 | DCHECK(locations->CanCall()); |
| 518 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 519 | DCHECK(!instruction_->IsInvoke() || |
| 520 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 521 | instruction_->GetLocations()->Intrinsified())) |
| 522 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 523 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 524 | |
| 525 | __ Bind(GetEntryLabel()); |
| 526 | SaveLiveRegisters(codegen, locations); |
| 527 | |
| 528 | // We may have to change the index's value, but as `index_` is a |
| 529 | // constant member (like other "inputs" of this slow path), |
| 530 | // introduce a copy of it, `index`. |
| 531 | Location index = index_; |
| 532 | if (index_.IsValid()) { |
| 533 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 534 | if (instruction_->IsArrayGet()) { |
| 535 | // Compute the actual memory offset and store it in `index`. |
| 536 | Register index_reg = index_.AsRegister<Register>(); |
| 537 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 538 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 539 | // We are about to change the value of `index_reg` (see the |
| 540 | // calls to art::x86::X86Assembler::shll and |
| 541 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 542 | // not been saved by the previous call to |
| 543 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 544 | // callee-save register -- |
| 545 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 546 | // callee-save registers, as it has been designed with the |
| 547 | // assumption that callee-save registers are supposed to be |
| 548 | // handled by the called function. So, as a callee-save |
| 549 | // register, `index_reg` _would_ eventually be saved onto |
| 550 | // the stack, but it would be too late: we would have |
| 551 | // changed its value earlier. Therefore, we manually save |
| 552 | // it here into another freely available register, |
| 553 | // `free_reg`, chosen of course among the caller-save |
| 554 | // registers (as a callee-save `free_reg` register would |
| 555 | // exhibit the same problem). |
| 556 | // |
| 557 | // Note we could have requested a temporary register from |
| 558 | // the register allocator instead; but we prefer not to, as |
| 559 | // this is a slow path, and we know we can find a |
| 560 | // caller-save register that is available. |
| 561 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 562 | __ movl(free_reg, index_reg); |
| 563 | index_reg = free_reg; |
| 564 | index = Location::RegisterLocation(index_reg); |
| 565 | } else { |
| 566 | // The initial register stored in `index_` has already been |
| 567 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 568 | // (as it is not a callee-save register), so we can freely |
| 569 | // use it. |
| 570 | } |
| 571 | // Shifting the index value contained in `index_reg` by the scale |
| 572 | // factor (2) cannot overflow in practice, as the runtime is |
| 573 | // unable to allocate object arrays with a size larger than |
| 574 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 575 | __ shll(index_reg, Immediate(TIMES_4)); |
| 576 | static_assert( |
| 577 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 578 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 579 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 580 | } else { |
| 581 | DCHECK(instruction_->IsInvoke()); |
| 582 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 583 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 584 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 585 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 586 | DCHECK_EQ(offset_, 0U); |
| 587 | DCHECK(index_.IsRegisterPair()); |
| 588 | // UnsafeGet's offset location is a register pair, the low |
| 589 | // part contains the correct offset. |
| 590 | index = index_.ToLow(); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // We're moving two or three locations to locations that could |
| 595 | // overlap, so we need a parallel move resolver. |
| 596 | InvokeRuntimeCallingConvention calling_convention; |
| 597 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 598 | parallel_move.AddMove(ref_, |
| 599 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 600 | Primitive::kPrimNot, |
| 601 | nullptr); |
| 602 | parallel_move.AddMove(obj_, |
| 603 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 604 | Primitive::kPrimNot, |
| 605 | nullptr); |
| 606 | if (index.IsValid()) { |
| 607 | parallel_move.AddMove(index, |
| 608 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 609 | Primitive::kPrimInt, |
| 610 | nullptr); |
| 611 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 612 | } else { |
| 613 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 614 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 615 | } |
| 616 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 617 | instruction_, |
| 618 | instruction_->GetDexPc(), |
| 619 | this); |
| 620 | CheckEntrypointTypes< |
| 621 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 622 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 623 | |
| 624 | RestoreLiveRegisters(codegen, locations); |
| 625 | __ jmp(GetExitLabel()); |
| 626 | } |
| 627 | |
| 628 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 629 | |
| 630 | private: |
| 631 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 632 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 633 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 634 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 635 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 636 | return static_cast<Register>(i); |
| 637 | } |
| 638 | } |
| 639 | // We shall never fail to find a free caller-save register, as |
| 640 | // there are more than two core caller-save registers on x86 |
| 641 | // (meaning it is possible to find one which is different from |
| 642 | // `ref` and `obj`). |
| 643 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 644 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 645 | UNREACHABLE(); |
| 646 | } |
| 647 | |
| 648 | HInstruction* const instruction_; |
| 649 | const Location out_; |
| 650 | const Location ref_; |
| 651 | const Location obj_; |
| 652 | const uint32_t offset_; |
| 653 | // An additional location containing an index to an array. |
| 654 | // Only used for HArrayGet and the UnsafeGetObject & |
| 655 | // UnsafeGetObjectVolatile intrinsics. |
| 656 | const Location index_; |
| 657 | |
| 658 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 659 | }; |
| 660 | |
| 661 | // Slow path generating a read barrier for a GC root. |
| 662 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 663 | public: |
| 664 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 665 | : instruction_(instruction), out_(out), root_(root) { |
| 666 | DCHECK(kEmitCompilerReadBarrier); |
| 667 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 668 | |
| 669 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 670 | LocationSummary* locations = instruction_->GetLocations(); |
| 671 | Register reg_out = out_.AsRegister<Register>(); |
| 672 | DCHECK(locations->CanCall()); |
| 673 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 674 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 675 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 676 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 677 | |
| 678 | __ Bind(GetEntryLabel()); |
| 679 | SaveLiveRegisters(codegen, locations); |
| 680 | |
| 681 | InvokeRuntimeCallingConvention calling_convention; |
| 682 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 683 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 684 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 685 | instruction_, |
| 686 | instruction_->GetDexPc(), |
| 687 | this); |
| 688 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 689 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 690 | |
| 691 | RestoreLiveRegisters(codegen, locations); |
| 692 | __ jmp(GetExitLabel()); |
| 693 | } |
| 694 | |
| 695 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 696 | |
| 697 | private: |
| 698 | HInstruction* const instruction_; |
| 699 | const Location out_; |
| 700 | const Location root_; |
| 701 | |
| 702 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 703 | }; |
| 704 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 705 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 706 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 707 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 708 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 709 | switch (cond) { |
| 710 | case kCondEQ: return kEqual; |
| 711 | case kCondNE: return kNotEqual; |
| 712 | case kCondLT: return kLess; |
| 713 | case kCondLE: return kLessEqual; |
| 714 | case kCondGT: return kGreater; |
| 715 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 716 | case kCondB: return kBelow; |
| 717 | case kCondBE: return kBelowEqual; |
| 718 | case kCondA: return kAbove; |
| 719 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 720 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 721 | LOG(FATAL) << "Unreachable"; |
| 722 | UNREACHABLE(); |
| 723 | } |
| 724 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 725 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 726 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 727 | switch (cond) { |
| 728 | case kCondEQ: return kEqual; |
| 729 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 730 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 731 | case kCondLT: return kBelow; |
| 732 | case kCondLE: return kBelowEqual; |
| 733 | case kCondGT: return kAbove; |
| 734 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 735 | // Unsigned remain unchanged. |
| 736 | case kCondB: return kBelow; |
| 737 | case kCondBE: return kBelowEqual; |
| 738 | case kCondA: return kAbove; |
| 739 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 740 | } |
| 741 | LOG(FATAL) << "Unreachable"; |
| 742 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 745 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 746 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 750 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 751 | } |
| 752 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 753 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 754 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 755 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 756 | } |
| 757 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 758 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 759 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 760 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 761 | } |
| 762 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 763 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 764 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 765 | return GetFloatingPointSpillSlotSize(); |
| 766 | } |
| 767 | |
| 768 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 769 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 770 | return GetFloatingPointSpillSlotSize(); |
| 771 | } |
| 772 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 773 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 774 | HInstruction* instruction, |
| 775 | uint32_t dex_pc, |
| 776 | SlowPathCode* slow_path) { |
| 777 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 778 | instruction, |
| 779 | dex_pc, |
| 780 | slow_path); |
| 781 | } |
| 782 | |
| 783 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 784 | HInstruction* instruction, |
| 785 | uint32_t dex_pc, |
| 786 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 787 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 788 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 789 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 792 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 793 | const X86InstructionSetFeatures& isa_features, |
| 794 | const CompilerOptions& compiler_options, |
| 795 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 796 | : CodeGenerator(graph, |
| 797 | kNumberOfCpuRegisters, |
| 798 | kNumberOfXmmRegisters, |
| 799 | kNumberOfRegisterPairs, |
| 800 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 801 | arraysize(kCoreCalleeSaves)) |
| 802 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 803 | 0, |
| 804 | compiler_options, |
| 805 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 806 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 807 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 808 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 809 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 810 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 811 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 812 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 813 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 814 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 815 | // Use a fake return address register to mimic Quick. |
| 816 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 817 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 818 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 819 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 820 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 821 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 822 | |
| 823 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 824 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 825 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 826 | UpdateBlockedPairRegisters(); |
| 827 | } |
| 828 | |
| 829 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 830 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 831 | X86ManagedRegister current = |
| 832 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 833 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 834 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 835 | blocked_register_pairs_[i] = true; |
| 836 | } |
| 837 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 838 | } |
| 839 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 840 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 841 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 842 | assembler_(codegen->GetAssembler()), |
| 843 | codegen_(codegen) {} |
| 844 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 845 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 846 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 847 | } |
| 848 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 849 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 850 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 851 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 852 | bool skip_overflow_check = |
| 853 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 854 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 855 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 856 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 857 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 858 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 859 | } |
| 860 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 861 | if (HasEmptyFrame()) { |
| 862 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 863 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 864 | |
| 865 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 866 | Register reg = kCoreCalleeSaves[i]; |
| 867 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 868 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 869 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 870 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 874 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 875 | __ subl(ESP, Immediate(adjust)); |
| 876 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 877 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 881 | __ cfi().RememberState(); |
| 882 | if (!HasEmptyFrame()) { |
| 883 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 884 | __ addl(ESP, Immediate(adjust)); |
| 885 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 886 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 887 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 888 | Register reg = kCoreCalleeSaves[i]; |
| 889 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 890 | __ popl(reg); |
| 891 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 892 | __ cfi().Restore(DWARFReg(reg)); |
| 893 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 894 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 895 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 896 | __ ret(); |
| 897 | __ cfi().RestoreState(); |
| 898 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 901 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 902 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 905 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 906 | switch (load->GetType()) { |
| 907 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 908 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 909 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 910 | |
| 911 | case Primitive::kPrimInt: |
| 912 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 913 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 914 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 915 | |
| 916 | case Primitive::kPrimBoolean: |
| 917 | case Primitive::kPrimByte: |
| 918 | case Primitive::kPrimChar: |
| 919 | case Primitive::kPrimShort: |
| 920 | case Primitive::kPrimVoid: |
| 921 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 922 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 926 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 929 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 930 | switch (type) { |
| 931 | case Primitive::kPrimBoolean: |
| 932 | case Primitive::kPrimByte: |
| 933 | case Primitive::kPrimChar: |
| 934 | case Primitive::kPrimShort: |
| 935 | case Primitive::kPrimInt: |
| 936 | case Primitive::kPrimNot: |
| 937 | return Location::RegisterLocation(EAX); |
| 938 | |
| 939 | case Primitive::kPrimLong: |
| 940 | return Location::RegisterPairLocation(EAX, EDX); |
| 941 | |
| 942 | case Primitive::kPrimVoid: |
| 943 | return Location::NoLocation(); |
| 944 | |
| 945 | case Primitive::kPrimDouble: |
| 946 | case Primitive::kPrimFloat: |
| 947 | return Location::FpuRegisterLocation(XMM0); |
| 948 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 949 | |
| 950 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 954 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 955 | } |
| 956 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 957 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 958 | switch (type) { |
| 959 | case Primitive::kPrimBoolean: |
| 960 | case Primitive::kPrimByte: |
| 961 | case Primitive::kPrimChar: |
| 962 | case Primitive::kPrimShort: |
| 963 | case Primitive::kPrimInt: |
| 964 | case Primitive::kPrimNot: { |
| 965 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 966 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 967 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 968 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 969 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 970 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 971 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 972 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 973 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 974 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 975 | uint32_t index = gp_index_; |
| 976 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 977 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 978 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 979 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 980 | calling_convention.GetRegisterPairAt(index)); |
| 981 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 982 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 983 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 988 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 989 | stack_index_++; |
| 990 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 991 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 992 | } else { |
| 993 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 998 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 999 | stack_index_ += 2; |
| 1000 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1001 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1002 | } else { |
| 1003 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1007 | case Primitive::kPrimVoid: |
| 1008 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1009 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1010 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1011 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1012 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1013 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1014 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1015 | if (source.Equals(destination)) { |
| 1016 | return; |
| 1017 | } |
| 1018 | if (destination.IsRegister()) { |
| 1019 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1020 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1021 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1022 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1023 | } else { |
| 1024 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1025 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1026 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1027 | } else if (destination.IsFpuRegister()) { |
| 1028 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1029 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1030 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1031 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1032 | } else { |
| 1033 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1034 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1035 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1036 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1037 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1038 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1039 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1040 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1041 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1042 | } else if (source.IsConstant()) { |
| 1043 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1044 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1045 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1046 | } else { |
| 1047 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1048 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1049 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1055 | if (source.Equals(destination)) { |
| 1056 | return; |
| 1057 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1058 | if (destination.IsRegisterPair()) { |
| 1059 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1060 | EmitParallelMoves( |
| 1061 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1062 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1063 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1064 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1065 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1066 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1067 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1068 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1069 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1070 | __ psrlq(src_reg, Immediate(32)); |
| 1071 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1072 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1073 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1074 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1075 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1076 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1077 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1078 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1079 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1080 | if (source.IsFpuRegister()) { |
| 1081 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1082 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1083 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1084 | } else if (source.IsRegisterPair()) { |
| 1085 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1086 | // Create stack space for 2 elements. |
| 1087 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1088 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1089 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1090 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1091 | // And remove the temporary stack space we allocated. |
| 1092 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1093 | } else { |
| 1094 | LOG(FATAL) << "Unimplemented"; |
| 1095 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1096 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1097 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1098 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1099 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1100 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1101 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1102 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1103 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1104 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1105 | } else if (source.IsConstant()) { |
| 1106 | HConstant* constant = source.GetConstant(); |
| 1107 | int64_t value; |
| 1108 | if (constant->IsLongConstant()) { |
| 1109 | value = constant->AsLongConstant()->GetValue(); |
| 1110 | } else { |
| 1111 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1112 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1113 | } |
| 1114 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1115 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1116 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1117 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1118 | EmitParallelMoves( |
| 1119 | Location::StackSlot(source.GetStackIndex()), |
| 1120 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1121 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1122 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1123 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1124 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1129 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1130 | DCHECK(location.IsRegister()); |
| 1131 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1132 | } |
| 1133 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1134 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1135 | HParallelMove move(GetGraph()->GetArena()); |
| 1136 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1137 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1138 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1139 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1140 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1141 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1142 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1146 | if (location.IsRegister()) { |
| 1147 | locations->AddTemp(location); |
| 1148 | } else if (location.IsRegisterPair()) { |
| 1149 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1150 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1151 | } else { |
| 1152 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1153 | } |
| 1154 | } |
| 1155 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1156 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1157 | DCHECK(!successor->IsExitBlock()); |
| 1158 | |
| 1159 | HBasicBlock* block = got->GetBlock(); |
| 1160 | HInstruction* previous = got->GetPrevious(); |
| 1161 | |
| 1162 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1163 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1164 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1165 | return; |
| 1166 | } |
| 1167 | |
| 1168 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1169 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1170 | } |
| 1171 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1172 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1176 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1177 | got->SetLocations(nullptr); |
| 1178 | } |
| 1179 | |
| 1180 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1181 | HandleGoto(got, got->GetSuccessor()); |
| 1182 | } |
| 1183 | |
| 1184 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1185 | try_boundary->SetLocations(nullptr); |
| 1186 | } |
| 1187 | |
| 1188 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1189 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1190 | if (!successor->IsExitBlock()) { |
| 1191 | HandleGoto(try_boundary, successor); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1195 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1196 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1199 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1202 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1203 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1204 | LabelType* true_label, |
| 1205 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1206 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1207 | __ j(kUnordered, true_label); |
| 1208 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1209 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1210 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1211 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1214 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1215 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1216 | LabelType* true_label, |
| 1217 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1218 | LocationSummary* locations = cond->GetLocations(); |
| 1219 | Location left = locations->InAt(0); |
| 1220 | Location right = locations->InAt(1); |
| 1221 | IfCondition if_cond = cond->GetCondition(); |
| 1222 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1223 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1224 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1225 | IfCondition true_high_cond = if_cond; |
| 1226 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1227 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1228 | |
| 1229 | // Set the conditions for the test, remembering that == needs to be |
| 1230 | // decided using the low words. |
| 1231 | switch (if_cond) { |
| 1232 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1233 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1234 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1235 | break; |
| 1236 | case kCondLT: |
| 1237 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1238 | break; |
| 1239 | case kCondLE: |
| 1240 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1241 | break; |
| 1242 | case kCondGT: |
| 1243 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1244 | break; |
| 1245 | case kCondGE: |
| 1246 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1247 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1248 | case kCondB: |
| 1249 | false_high_cond = kCondA; |
| 1250 | break; |
| 1251 | case kCondBE: |
| 1252 | true_high_cond = kCondB; |
| 1253 | break; |
| 1254 | case kCondA: |
| 1255 | false_high_cond = kCondB; |
| 1256 | break; |
| 1257 | case kCondAE: |
| 1258 | true_high_cond = kCondA; |
| 1259 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | if (right.IsConstant()) { |
| 1263 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1264 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1265 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1266 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1267 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1268 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1269 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1270 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1271 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1272 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1273 | __ j(X86Condition(true_high_cond), true_label); |
| 1274 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | } |
| 1276 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1277 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1278 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1279 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1280 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1281 | |
| 1282 | __ cmpl(left_high, right_high); |
| 1283 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1284 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1285 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1286 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1287 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1288 | __ j(X86Condition(true_high_cond), true_label); |
| 1289 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1290 | } |
| 1291 | // Must be equal high, so compare the lows. |
| 1292 | __ cmpl(left_low, right_low); |
| 1293 | } |
| 1294 | // The last comparison might be unsigned. |
| 1295 | __ j(final_condition, true_label); |
| 1296 | } |
| 1297 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1298 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1299 | Location rhs, |
| 1300 | HInstruction* insn, |
| 1301 | bool is_double) { |
| 1302 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1303 | if (is_double) { |
| 1304 | if (rhs.IsFpuRegister()) { |
| 1305 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1306 | } else if (const_area != nullptr) { |
| 1307 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1308 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1309 | codegen_->LiteralDoubleAddress( |
| 1310 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1311 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1312 | } else { |
| 1313 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1314 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1315 | } |
| 1316 | } else { |
| 1317 | if (rhs.IsFpuRegister()) { |
| 1318 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1319 | } else if (const_area != nullptr) { |
| 1320 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1321 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1322 | codegen_->LiteralFloatAddress( |
| 1323 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1324 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1325 | } else { |
| 1326 | DCHECK(rhs.IsStackSlot()); |
| 1327 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1332 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1333 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1334 | LabelType* true_target_in, |
| 1335 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1336 | // Generated branching requires both targets to be explicit. If either of the |
| 1337 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1338 | LabelType fallthrough_target; |
| 1339 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1340 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1341 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1342 | LocationSummary* locations = condition->GetLocations(); |
| 1343 | Location left = locations->InAt(0); |
| 1344 | Location right = locations->InAt(1); |
| 1345 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1346 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1347 | switch (type) { |
| 1348 | case Primitive::kPrimLong: |
| 1349 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1350 | break; |
| 1351 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1352 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1353 | GenerateFPJumps(condition, true_target, false_target); |
| 1354 | break; |
| 1355 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1356 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1357 | GenerateFPJumps(condition, true_target, false_target); |
| 1358 | break; |
| 1359 | default: |
| 1360 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1361 | } |
| 1362 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1363 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1364 | __ jmp(false_target); |
| 1365 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1366 | |
| 1367 | if (fallthrough_target.IsLinked()) { |
| 1368 | __ Bind(&fallthrough_target); |
| 1369 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1372 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1373 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1374 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1375 | // conditions if they are materialized due to the complex branching. |
| 1376 | return cond->IsCondition() && |
| 1377 | cond->GetNext() == branch && |
| 1378 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1379 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1380 | } |
| 1381 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1382 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1383 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1384 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1385 | LabelType* true_target, |
| 1386 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1387 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1388 | |
| 1389 | if (true_target == nullptr && false_target == nullptr) { |
| 1390 | // Nothing to do. The code always falls through. |
| 1391 | return; |
| 1392 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1393 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1394 | if (cond->AsIntConstant()->IsOne()) { |
| 1395 | if (true_target != nullptr) { |
| 1396 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1397 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1398 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1399 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1400 | if (false_target != nullptr) { |
| 1401 | __ jmp(false_target); |
| 1402 | } |
| 1403 | } |
| 1404 | return; |
| 1405 | } |
| 1406 | |
| 1407 | // The following code generates these patterns: |
| 1408 | // (1) true_target == nullptr && false_target != nullptr |
| 1409 | // - opposite condition true => branch to false_target |
| 1410 | // (2) true_target != nullptr && false_target == nullptr |
| 1411 | // - condition true => branch to true_target |
| 1412 | // (3) true_target != nullptr && false_target != nullptr |
| 1413 | // - condition true => branch to true_target |
| 1414 | // - branch to false_target |
| 1415 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1416 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1417 | if (true_target == nullptr) { |
| 1418 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1419 | } else { |
| 1420 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1421 | } |
| 1422 | } else { |
| 1423 | // Materialized condition, compare against 0. |
| 1424 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1425 | if (lhs.IsRegister()) { |
| 1426 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1427 | } else { |
| 1428 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1429 | } |
| 1430 | if (true_target == nullptr) { |
| 1431 | __ j(kEqual, false_target); |
| 1432 | } else { |
| 1433 | __ j(kNotEqual, true_target); |
| 1434 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1435 | } |
| 1436 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1437 | // Condition has not been materialized, use its inputs as the comparison and |
| 1438 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1439 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1440 | |
| 1441 | // If this is a long or FP comparison that has been folded into |
| 1442 | // the HCondition, generate the comparison directly. |
| 1443 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1444 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1445 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1446 | return; |
| 1447 | } |
| 1448 | |
| 1449 | Location lhs = condition->GetLocations()->InAt(0); |
| 1450 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1451 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1452 | if (rhs.IsRegister()) { |
| 1453 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1454 | } else if (rhs.IsConstant()) { |
| 1455 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1456 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1457 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1458 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1459 | } |
| 1460 | if (true_target == nullptr) { |
| 1461 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1462 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1463 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1464 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1465 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1466 | |
| 1467 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1468 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1469 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1470 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1474 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1475 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1476 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1477 | locations->SetInAt(0, Location::Any()); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1482 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1483 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1484 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1485 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1486 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1487 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1488 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1492 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1493 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1494 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1495 | locations->SetInAt(0, Location::Any()); |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1500 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1501 | GenerateTestAndBranch<Label>(deoptimize, |
| 1502 | /* condition_input_index */ 0, |
| 1503 | slow_path->GetEntryLabel(), |
| 1504 | /* false_target */ nullptr); |
| 1505 | } |
| 1506 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1507 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1508 | // There are no conditional move instructions for XMMs. |
| 1509 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1510 | return false; |
| 1511 | } |
| 1512 | |
| 1513 | // A FP condition doesn't generate the single CC that we need. |
| 1514 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1515 | HInstruction* condition = select->GetCondition(); |
| 1516 | if (condition->IsCondition()) { |
| 1517 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1518 | if (compare_type == Primitive::kPrimLong || |
| 1519 | Primitive::IsFloatingPointType(compare_type)) { |
| 1520 | return false; |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | // We can generate a CMOV for this Select. |
| 1525 | return true; |
| 1526 | } |
| 1527 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1528 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1529 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1530 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1531 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1532 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1533 | } else { |
| 1534 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1535 | if (SelectCanUseCMOV(select)) { |
| 1536 | if (select->InputAt(1)->IsConstant()) { |
| 1537 | // Cmov can't handle a constant value. |
| 1538 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1539 | } else { |
| 1540 | locations->SetInAt(1, Location::Any()); |
| 1541 | } |
| 1542 | } else { |
| 1543 | locations->SetInAt(1, Location::Any()); |
| 1544 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1545 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1546 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1547 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1548 | } |
| 1549 | locations->SetOut(Location::SameAsFirstInput()); |
| 1550 | } |
| 1551 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1552 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1553 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1554 | if (rhs.IsConstant()) { |
| 1555 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1556 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1557 | } else if (rhs.IsStackSlot()) { |
| 1558 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1559 | } else { |
| 1560 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1561 | } |
| 1562 | } |
| 1563 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1564 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1565 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1566 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1567 | if (SelectCanUseCMOV(select)) { |
| 1568 | // If both the condition and the source types are integer, we can generate |
| 1569 | // a CMOV to implement Select. |
| 1570 | |
| 1571 | HInstruction* select_condition = select->GetCondition(); |
| 1572 | Condition cond = kNotEqual; |
| 1573 | |
| 1574 | // Figure out how to test the 'condition'. |
| 1575 | if (select_condition->IsCondition()) { |
| 1576 | HCondition* condition = select_condition->AsCondition(); |
| 1577 | if (!condition->IsEmittedAtUseSite()) { |
| 1578 | // This was a previously materialized condition. |
| 1579 | // Can we use the existing condition code? |
| 1580 | if (AreEflagsSetFrom(condition, select)) { |
| 1581 | // Materialization was the previous instruction. Condition codes are right. |
| 1582 | cond = X86Condition(condition->GetCondition()); |
| 1583 | } else { |
| 1584 | // No, we have to recreate the condition code. |
| 1585 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1586 | __ testl(cond_reg, cond_reg); |
| 1587 | } |
| 1588 | } else { |
| 1589 | // We can't handle FP or long here. |
| 1590 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1591 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1592 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1593 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1594 | cond = X86Condition(condition->GetCondition()); |
| 1595 | } |
| 1596 | } else { |
| 1597 | // Must be a boolean condition, which needs to be compared to 0. |
| 1598 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1599 | __ testl(cond_reg, cond_reg); |
| 1600 | } |
| 1601 | |
| 1602 | // If the condition is true, overwrite the output, which already contains false. |
| 1603 | Location false_loc = locations->InAt(0); |
| 1604 | Location true_loc = locations->InAt(1); |
| 1605 | if (select->GetType() == Primitive::kPrimLong) { |
| 1606 | // 64 bit conditional move. |
| 1607 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1608 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1609 | if (true_loc.IsRegisterPair()) { |
| 1610 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1611 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1612 | } else { |
| 1613 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1614 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1615 | } |
| 1616 | } else { |
| 1617 | // 32 bit conditional move. |
| 1618 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1619 | if (true_loc.IsRegister()) { |
| 1620 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1621 | } else { |
| 1622 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1623 | } |
| 1624 | } |
| 1625 | } else { |
| 1626 | NearLabel false_target; |
| 1627 | GenerateTestAndBranch<NearLabel>( |
| 1628 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1629 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1630 | __ Bind(&false_target); |
| 1631 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1634 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1635 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1636 | } |
| 1637 | |
| 1638 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1639 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1640 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1641 | __ nop(); |
| 1642 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1643 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1644 | } |
| 1645 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1646 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1647 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1650 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1651 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1652 | } |
| 1653 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1654 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1655 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1658 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1659 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1660 | } |
| 1661 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1662 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1663 | LocationSummary* locations = |
| 1664 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1665 | switch (store->InputAt(1)->GetType()) { |
| 1666 | case Primitive::kPrimBoolean: |
| 1667 | case Primitive::kPrimByte: |
| 1668 | case Primitive::kPrimChar: |
| 1669 | case Primitive::kPrimShort: |
| 1670 | case Primitive::kPrimInt: |
| 1671 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1672 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1673 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1674 | break; |
| 1675 | |
| 1676 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1677 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1678 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1679 | break; |
| 1680 | |
| 1681 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1682 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1683 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1686 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1689 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1690 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1691 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1692 | // Handle the long/FP comparisons made in instruction simplification. |
| 1693 | switch (cond->InputAt(0)->GetType()) { |
| 1694 | case Primitive::kPrimLong: { |
| 1695 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1696 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1697 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1698 | locations->SetOut(Location::RequiresRegister()); |
| 1699 | } |
| 1700 | break; |
| 1701 | } |
| 1702 | case Primitive::kPrimFloat: |
| 1703 | case Primitive::kPrimDouble: { |
| 1704 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1705 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1706 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1707 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1708 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1709 | } else { |
| 1710 | locations->SetInAt(1, Location::Any()); |
| 1711 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1712 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1713 | locations->SetOut(Location::RequiresRegister()); |
| 1714 | } |
| 1715 | break; |
| 1716 | } |
| 1717 | default: |
| 1718 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1719 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1720 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1721 | // We need a byte register. |
| 1722 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1723 | } |
| 1724 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1725 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1728 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1729 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1730 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1731 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1732 | |
| 1733 | LocationSummary* locations = cond->GetLocations(); |
| 1734 | Location lhs = locations->InAt(0); |
| 1735 | Location rhs = locations->InAt(1); |
| 1736 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1737 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1738 | |
| 1739 | switch (cond->InputAt(0)->GetType()) { |
| 1740 | default: { |
| 1741 | // Integer case. |
| 1742 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1743 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1744 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 1745 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1746 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1747 | return; |
| 1748 | } |
| 1749 | case Primitive::kPrimLong: |
| 1750 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1751 | break; |
| 1752 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1753 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1754 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1755 | break; |
| 1756 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1757 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1758 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1759 | break; |
| 1760 | } |
| 1761 | |
| 1762 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1763 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1764 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1765 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1766 | __ Bind(&false_label); |
| 1767 | __ xorl(reg, reg); |
| 1768 | __ jmp(&done_label); |
| 1769 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1770 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1771 | __ Bind(&true_label); |
| 1772 | __ movl(reg, Immediate(1)); |
| 1773 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1777 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1781 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1797 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1801 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1805 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1809 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1817 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1824 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1825 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1829 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1833 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1837 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1841 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1845 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1849 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1853 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1856 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1857 | LocationSummary* locations = |
| 1858 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1859 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1862 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1863 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1866 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1867 | LocationSummary* locations = |
| 1868 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1869 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1870 | } |
| 1871 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1872 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1873 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1876 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1877 | LocationSummary* locations = |
| 1878 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1879 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1880 | } |
| 1881 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1882 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1883 | // Will be generated at use site. |
| 1884 | } |
| 1885 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1886 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1887 | LocationSummary* locations = |
| 1888 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1889 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1890 | } |
| 1891 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1892 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1893 | // Will be generated at use site. |
| 1894 | } |
| 1895 | |
| 1896 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1897 | LocationSummary* locations = |
| 1898 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1899 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1900 | } |
| 1901 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1902 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1903 | // Will be generated at use site. |
| 1904 | } |
| 1905 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1906 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1907 | memory_barrier->SetLocations(nullptr); |
| 1908 | } |
| 1909 | |
| 1910 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1911 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1912 | } |
| 1913 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1914 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1915 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1918 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1919 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1922 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1923 | LocationSummary* locations = |
| 1924 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1925 | switch (ret->InputAt(0)->GetType()) { |
| 1926 | case Primitive::kPrimBoolean: |
| 1927 | case Primitive::kPrimByte: |
| 1928 | case Primitive::kPrimChar: |
| 1929 | case Primitive::kPrimShort: |
| 1930 | case Primitive::kPrimInt: |
| 1931 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1932 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1933 | break; |
| 1934 | |
| 1935 | case Primitive::kPrimLong: |
| 1936 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1937 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1938 | break; |
| 1939 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1940 | case Primitive::kPrimFloat: |
| 1941 | case Primitive::kPrimDouble: |
| 1942 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1943 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1944 | break; |
| 1945 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1946 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1947 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1948 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1951 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1952 | if (kIsDebugBuild) { |
| 1953 | switch (ret->InputAt(0)->GetType()) { |
| 1954 | case Primitive::kPrimBoolean: |
| 1955 | case Primitive::kPrimByte: |
| 1956 | case Primitive::kPrimChar: |
| 1957 | case Primitive::kPrimShort: |
| 1958 | case Primitive::kPrimInt: |
| 1959 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1960 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1961 | break; |
| 1962 | |
| 1963 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1964 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1965 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1966 | break; |
| 1967 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1968 | case Primitive::kPrimFloat: |
| 1969 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1970 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1971 | break; |
| 1972 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1973 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1974 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1975 | } |
| 1976 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1977 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1980 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1981 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1982 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1983 | // the method_idx. |
| 1984 | HandleInvoke(invoke); |
| 1985 | } |
| 1986 | |
| 1987 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1988 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1989 | } |
| 1990 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1991 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1992 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1993 | // art::PrepareForRegisterAllocation. |
| 1994 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1995 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1996 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1997 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1998 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1999 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2000 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2001 | return; |
| 2002 | } |
| 2003 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2004 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2005 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2006 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2007 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2008 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2009 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2010 | } |
| 2011 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2012 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2013 | if (invoke->GetLocations()->Intrinsified()) { |
| 2014 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2015 | intrinsic.Dispatch(invoke); |
| 2016 | return true; |
| 2017 | } |
| 2018 | return false; |
| 2019 | } |
| 2020 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2021 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2022 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2023 | // art::PrepareForRegisterAllocation. |
| 2024 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2025 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2026 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2027 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2028 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2029 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2030 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2031 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2032 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2033 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2037 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2038 | if (intrinsic.TryDispatch(invoke)) { |
| 2039 | return; |
| 2040 | } |
| 2041 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2042 | HandleInvoke(invoke); |
| 2043 | } |
| 2044 | |
| 2045 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2046 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2047 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2050 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2051 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2052 | return; |
| 2053 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2054 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2055 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2056 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2057 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2060 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2061 | // This call to HandleInvoke allocates a temporary (core) register |
| 2062 | // which is also used to transfer the hidden argument from FP to |
| 2063 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2064 | HandleInvoke(invoke); |
| 2065 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2066 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2070 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2071 | LocationSummary* locations = invoke->GetLocations(); |
| 2072 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2073 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2074 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2075 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2076 | Location receiver = locations->InAt(0); |
| 2077 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2078 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2079 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2080 | // won't be modified thereafter, before the `call` instruction. |
| 2081 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2082 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2083 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2084 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2085 | if (receiver.IsStackSlot()) { |
| 2086 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2087 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2088 | __ movl(temp, Address(temp, class_offset)); |
| 2089 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2090 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2091 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2092 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2093 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2094 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2095 | // emit a read barrier for the previous class reference load. |
| 2096 | // However this is not required in practice, as this is an |
| 2097 | // intermediate/temporary reference and because the current |
| 2098 | // concurrent copying collector keeps the from-space memory |
| 2099 | // intact/accessible until the end of the marking phase (the |
| 2100 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2101 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2102 | // temp = temp->GetImtEntryAt(method_offset); |
| 2103 | __ movl(temp, Address(temp, method_offset)); |
| 2104 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2105 | __ call(Address(temp, |
| 2106 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2107 | |
| 2108 | DCHECK(!codegen_->IsLeafMethod()); |
| 2109 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2110 | } |
| 2111 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2112 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2113 | LocationSummary* locations = |
| 2114 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2115 | switch (neg->GetResultType()) { |
| 2116 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2117 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2118 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2119 | locations->SetOut(Location::SameAsFirstInput()); |
| 2120 | break; |
| 2121 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2122 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2123 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2124 | locations->SetOut(Location::SameAsFirstInput()); |
| 2125 | locations->AddTemp(Location::RequiresRegister()); |
| 2126 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2127 | break; |
| 2128 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2129 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2130 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2131 | locations->SetOut(Location::SameAsFirstInput()); |
| 2132 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2133 | break; |
| 2134 | |
| 2135 | default: |
| 2136 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2141 | LocationSummary* locations = neg->GetLocations(); |
| 2142 | Location out = locations->Out(); |
| 2143 | Location in = locations->InAt(0); |
| 2144 | switch (neg->GetResultType()) { |
| 2145 | case Primitive::kPrimInt: |
| 2146 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2147 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2148 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2149 | break; |
| 2150 | |
| 2151 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2152 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2153 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2154 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2155 | // Negation is similar to subtraction from zero. The least |
| 2156 | // significant byte triggers a borrow when it is different from |
| 2157 | // zero; to take it into account, add 1 to the most significant |
| 2158 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2159 | // operation. |
| 2160 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2161 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2162 | break; |
| 2163 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2164 | case Primitive::kPrimFloat: { |
| 2165 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2166 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2167 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2168 | // Implement float negation with an exclusive or with value |
| 2169 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2170 | // single-precision floating-point number). |
| 2171 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2172 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2173 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2174 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2175 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2176 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2177 | case Primitive::kPrimDouble: { |
| 2178 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2179 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2180 | // Implement double negation with an exclusive or with value |
| 2181 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2182 | // a double-precision floating-point number). |
| 2183 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2184 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2185 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2186 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2187 | |
| 2188 | default: |
| 2189 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2190 | } |
| 2191 | } |
| 2192 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2193 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2194 | LocationSummary* locations = |
| 2195 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2196 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2197 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2198 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2199 | locations->SetOut(Location::SameAsFirstInput()); |
| 2200 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2201 | } |
| 2202 | |
| 2203 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2204 | LocationSummary* locations = neg->GetLocations(); |
| 2205 | Location out = locations->Out(); |
| 2206 | DCHECK(locations->InAt(0).Equals(out)); |
| 2207 | |
| 2208 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2209 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2210 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2211 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2212 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2213 | } else { |
| 2214 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2215 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2216 | } |
| 2217 | } |
| 2218 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2219 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2220 | Primitive::Type result_type = conversion->GetResultType(); |
| 2221 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2222 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2223 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2224 | // The float-to-long and double-to-long type conversions rely on a |
| 2225 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2226 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2227 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2228 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2229 | ? LocationSummary::kCall |
| 2230 | : LocationSummary::kNoCall; |
| 2231 | LocationSummary* locations = |
| 2232 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2233 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2234 | // The Java language does not allow treating boolean as an integral type but |
| 2235 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2236 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2237 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2238 | case Primitive::kPrimByte: |
| 2239 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2240 | case Primitive::kPrimLong: { |
| 2241 | // Type conversion from long to byte is a result of code transformations. |
| 2242 | HInstruction* input = conversion->InputAt(0); |
| 2243 | Location input_location = input->IsConstant() |
| 2244 | ? Location::ConstantLocation(input->AsConstant()) |
| 2245 | : Location::RegisterPairLocation(EAX, EDX); |
| 2246 | locations->SetInAt(0, input_location); |
| 2247 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2248 | // the validation of the linear scan implementation |
| 2249 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2250 | break; |
| 2251 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2252 | case Primitive::kPrimBoolean: |
| 2253 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2254 | case Primitive::kPrimShort: |
| 2255 | case Primitive::kPrimInt: |
| 2256 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2257 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2258 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2259 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2260 | // the validation of the linear scan implementation |
| 2261 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | |
| 2264 | default: |
| 2265 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2266 | << " to " << result_type; |
| 2267 | } |
| 2268 | break; |
| 2269 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimShort: |
| 2271 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimLong: |
| 2273 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2274 | case Primitive::kPrimBoolean: |
| 2275 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimByte: |
| 2277 | case Primitive::kPrimInt: |
| 2278 | case Primitive::kPrimChar: |
| 2279 | // Processing a Dex `int-to-short' instruction. |
| 2280 | locations->SetInAt(0, Location::Any()); |
| 2281 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2282 | break; |
| 2283 | |
| 2284 | default: |
| 2285 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2286 | << " to " << result_type; |
| 2287 | } |
| 2288 | break; |
| 2289 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimInt: |
| 2291 | switch (input_type) { |
| 2292 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2293 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2294 | locations->SetInAt(0, Location::Any()); |
| 2295 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2296 | break; |
| 2297 | |
| 2298 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2299 | // Processing a Dex `float-to-int' instruction. |
| 2300 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2301 | locations->SetOut(Location::RequiresRegister()); |
| 2302 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2303 | break; |
| 2304 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2305 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2306 | // Processing a Dex `double-to-int' instruction. |
| 2307 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2308 | locations->SetOut(Location::RequiresRegister()); |
| 2309 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2310 | break; |
| 2311 | |
| 2312 | default: |
| 2313 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2314 | << " to " << result_type; |
| 2315 | } |
| 2316 | break; |
| 2317 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimLong: |
| 2319 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2320 | case Primitive::kPrimBoolean: |
| 2321 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2322 | case Primitive::kPrimByte: |
| 2323 | case Primitive::kPrimShort: |
| 2324 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2325 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2326 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2327 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2328 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2329 | break; |
| 2330 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2333 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2334 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2335 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2336 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2337 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2338 | // The runtime helper puts the result in EAX, EDX. |
| 2339 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2340 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2341 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2342 | |
| 2343 | default: |
| 2344 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2345 | << " to " << result_type; |
| 2346 | } |
| 2347 | break; |
| 2348 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimChar: |
| 2350 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2351 | case Primitive::kPrimLong: |
| 2352 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2353 | case Primitive::kPrimBoolean: |
| 2354 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2355 | case Primitive::kPrimByte: |
| 2356 | case Primitive::kPrimShort: |
| 2357 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2358 | // Processing a Dex `int-to-char' instruction. |
| 2359 | locations->SetInAt(0, Location::Any()); |
| 2360 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2361 | break; |
| 2362 | |
| 2363 | default: |
| 2364 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2365 | << " to " << result_type; |
| 2366 | } |
| 2367 | break; |
| 2368 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2369 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2370 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2371 | case Primitive::kPrimBoolean: |
| 2372 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2373 | case Primitive::kPrimByte: |
| 2374 | case Primitive::kPrimShort: |
| 2375 | case Primitive::kPrimInt: |
| 2376 | case Primitive::kPrimChar: |
| 2377 | // Processing a Dex `int-to-float' instruction. |
| 2378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2379 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2380 | break; |
| 2381 | |
| 2382 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2383 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2384 | locations->SetInAt(0, Location::Any()); |
| 2385 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2388 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2389 | // Processing a Dex `double-to-float' instruction. |
| 2390 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2391 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2392 | break; |
| 2393 | |
| 2394 | default: |
| 2395 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2396 | << " to " << result_type; |
| 2397 | }; |
| 2398 | break; |
| 2399 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2400 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2401 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2402 | case Primitive::kPrimBoolean: |
| 2403 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimByte: |
| 2405 | case Primitive::kPrimShort: |
| 2406 | case Primitive::kPrimInt: |
| 2407 | case Primitive::kPrimChar: |
| 2408 | // Processing a Dex `int-to-double' instruction. |
| 2409 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2410 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2411 | break; |
| 2412 | |
| 2413 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2414 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2415 | locations->SetInAt(0, Location::Any()); |
| 2416 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2417 | break; |
| 2418 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2419 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2420 | // Processing a Dex `float-to-double' instruction. |
| 2421 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2422 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | |
| 2425 | default: |
| 2426 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2427 | << " to " << result_type; |
| 2428 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2429 | break; |
| 2430 | |
| 2431 | default: |
| 2432 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2433 | << " to " << result_type; |
| 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2438 | LocationSummary* locations = conversion->GetLocations(); |
| 2439 | Location out = locations->Out(); |
| 2440 | Location in = locations->InAt(0); |
| 2441 | Primitive::Type result_type = conversion->GetResultType(); |
| 2442 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2443 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2444 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2445 | case Primitive::kPrimByte: |
| 2446 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2447 | case Primitive::kPrimLong: |
| 2448 | // Type conversion from long to byte is a result of code transformations. |
| 2449 | if (in.IsRegisterPair()) { |
| 2450 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2451 | } else { |
| 2452 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2453 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2454 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2455 | } |
| 2456 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2457 | case Primitive::kPrimBoolean: |
| 2458 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2459 | case Primitive::kPrimShort: |
| 2460 | case Primitive::kPrimInt: |
| 2461 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2462 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2463 | if (in.IsRegister()) { |
| 2464 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2465 | } else { |
| 2466 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2467 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2468 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2469 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2470 | break; |
| 2471 | |
| 2472 | default: |
| 2473 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2474 | << " to " << result_type; |
| 2475 | } |
| 2476 | break; |
| 2477 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2478 | case Primitive::kPrimShort: |
| 2479 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2480 | case Primitive::kPrimLong: |
| 2481 | // Type conversion from long to short is a result of code transformations. |
| 2482 | if (in.IsRegisterPair()) { |
| 2483 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2484 | } else if (in.IsDoubleStackSlot()) { |
| 2485 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2486 | } else { |
| 2487 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2488 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2489 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2490 | } |
| 2491 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimBoolean: |
| 2493 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimByte: |
| 2495 | case Primitive::kPrimInt: |
| 2496 | case Primitive::kPrimChar: |
| 2497 | // Processing a Dex `int-to-short' instruction. |
| 2498 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2499 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2500 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2501 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2502 | } else { |
| 2503 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2504 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2505 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2506 | } |
| 2507 | break; |
| 2508 | |
| 2509 | default: |
| 2510 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2511 | << " to " << result_type; |
| 2512 | } |
| 2513 | break; |
| 2514 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2515 | case Primitive::kPrimInt: |
| 2516 | switch (input_type) { |
| 2517 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2518 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2519 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2520 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2521 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2522 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2523 | } else { |
| 2524 | DCHECK(in.IsConstant()); |
| 2525 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2526 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2527 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2528 | } |
| 2529 | break; |
| 2530 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimFloat: { |
| 2532 | // Processing a Dex `float-to-int' instruction. |
| 2533 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2534 | Register output = out.AsRegister<Register>(); |
| 2535 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2536 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2537 | |
| 2538 | __ movl(output, Immediate(kPrimIntMax)); |
| 2539 | // temp = int-to-float(output) |
| 2540 | __ cvtsi2ss(temp, output); |
| 2541 | // if input >= temp goto done |
| 2542 | __ comiss(input, temp); |
| 2543 | __ j(kAboveEqual, &done); |
| 2544 | // if input == NaN goto nan |
| 2545 | __ j(kUnordered, &nan); |
| 2546 | // output = float-to-int-truncate(input) |
| 2547 | __ cvttss2si(output, input); |
| 2548 | __ jmp(&done); |
| 2549 | __ Bind(&nan); |
| 2550 | // output = 0 |
| 2551 | __ xorl(output, output); |
| 2552 | __ Bind(&done); |
| 2553 | break; |
| 2554 | } |
| 2555 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimDouble: { |
| 2557 | // Processing a Dex `double-to-int' instruction. |
| 2558 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2559 | Register output = out.AsRegister<Register>(); |
| 2560 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2561 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2562 | |
| 2563 | __ movl(output, Immediate(kPrimIntMax)); |
| 2564 | // temp = int-to-double(output) |
| 2565 | __ cvtsi2sd(temp, output); |
| 2566 | // if input >= temp goto done |
| 2567 | __ comisd(input, temp); |
| 2568 | __ j(kAboveEqual, &done); |
| 2569 | // if input == NaN goto nan |
| 2570 | __ j(kUnordered, &nan); |
| 2571 | // output = double-to-int-truncate(input) |
| 2572 | __ cvttsd2si(output, input); |
| 2573 | __ jmp(&done); |
| 2574 | __ Bind(&nan); |
| 2575 | // output = 0 |
| 2576 | __ xorl(output, output); |
| 2577 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2578 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2579 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2580 | |
| 2581 | default: |
| 2582 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2583 | << " to " << result_type; |
| 2584 | } |
| 2585 | break; |
| 2586 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimLong: |
| 2588 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2589 | case Primitive::kPrimBoolean: |
| 2590 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2591 | case Primitive::kPrimByte: |
| 2592 | case Primitive::kPrimShort: |
| 2593 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2594 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2595 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2596 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2597 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2598 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2599 | __ cdq(); |
| 2600 | break; |
| 2601 | |
| 2602 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2603 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2604 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2605 | conversion, |
| 2606 | conversion->GetDexPc(), |
| 2607 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2608 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2609 | break; |
| 2610 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2612 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2613 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2614 | conversion, |
| 2615 | conversion->GetDexPc(), |
| 2616 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2617 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2618 | break; |
| 2619 | |
| 2620 | default: |
| 2621 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2622 | << " to " << result_type; |
| 2623 | } |
| 2624 | break; |
| 2625 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimChar: |
| 2627 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2628 | case Primitive::kPrimLong: |
| 2629 | // Type conversion from long to short is a result of code transformations. |
| 2630 | if (in.IsRegisterPair()) { |
| 2631 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2632 | } else if (in.IsDoubleStackSlot()) { |
| 2633 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2634 | } else { |
| 2635 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2636 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2637 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2638 | } |
| 2639 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2640 | case Primitive::kPrimBoolean: |
| 2641 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimByte: |
| 2643 | case Primitive::kPrimShort: |
| 2644 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2645 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2646 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2647 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2648 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2649 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2650 | } else { |
| 2651 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2652 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2653 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2654 | } |
| 2655 | break; |
| 2656 | |
| 2657 | default: |
| 2658 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2659 | << " to " << result_type; |
| 2660 | } |
| 2661 | break; |
| 2662 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2663 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2665 | case Primitive::kPrimBoolean: |
| 2666 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | case Primitive::kPrimByte: |
| 2668 | case Primitive::kPrimShort: |
| 2669 | case Primitive::kPrimInt: |
| 2670 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2671 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2672 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2673 | break; |
| 2674 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimLong: { |
| 2676 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2677 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2678 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2679 | // Create stack space for the call to |
| 2680 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2681 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2682 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2683 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2684 | __ subl(ESP, Immediate(adjustment)); |
| 2685 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2686 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2687 | // Load the value to the FP stack, using temporaries if needed. |
| 2688 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2689 | |
| 2690 | if (out.IsStackSlot()) { |
| 2691 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2692 | } else { |
| 2693 | __ fstps(Address(ESP, 0)); |
| 2694 | Location stack_temp = Location::StackSlot(0); |
| 2695 | codegen_->Move32(out, stack_temp); |
| 2696 | } |
| 2697 | |
| 2698 | // Remove the temporary stack space we allocated. |
| 2699 | if (adjustment != 0) { |
| 2700 | __ addl(ESP, Immediate(adjustment)); |
| 2701 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2702 | break; |
| 2703 | } |
| 2704 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2705 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2706 | // Processing a Dex `double-to-float' instruction. |
| 2707 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2708 | break; |
| 2709 | |
| 2710 | default: |
| 2711 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2712 | << " to " << result_type; |
| 2713 | }; |
| 2714 | break; |
| 2715 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2716 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2717 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimBoolean: |
| 2719 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | case Primitive::kPrimByte: |
| 2721 | case Primitive::kPrimShort: |
| 2722 | case Primitive::kPrimInt: |
| 2723 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2724 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2725 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2726 | break; |
| 2727 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2728 | case Primitive::kPrimLong: { |
| 2729 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2730 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2731 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2732 | // Create stack space for the call to |
| 2733 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2734 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2735 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2736 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2737 | __ subl(ESP, Immediate(adjustment)); |
| 2738 | } |
| 2739 | |
| 2740 | // Load the value to the FP stack, using temporaries if needed. |
| 2741 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2742 | |
| 2743 | if (out.IsDoubleStackSlot()) { |
| 2744 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2745 | } else { |
| 2746 | __ fstpl(Address(ESP, 0)); |
| 2747 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2748 | codegen_->Move64(out, stack_temp); |
| 2749 | } |
| 2750 | |
| 2751 | // Remove the temporary stack space we allocated. |
| 2752 | if (adjustment != 0) { |
| 2753 | __ addl(ESP, Immediate(adjustment)); |
| 2754 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | } |
| 2757 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2758 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2759 | // Processing a Dex `float-to-double' instruction. |
| 2760 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2761 | break; |
| 2762 | |
| 2763 | default: |
| 2764 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2765 | << " to " << result_type; |
| 2766 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2767 | break; |
| 2768 | |
| 2769 | default: |
| 2770 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2771 | << " to " << result_type; |
| 2772 | } |
| 2773 | } |
| 2774 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2775 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2776 | LocationSummary* locations = |
| 2777 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2778 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2779 | case Primitive::kPrimInt: { |
| 2780 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2781 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2782 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2783 | break; |
| 2784 | } |
| 2785 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2786 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2787 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2788 | locations->SetInAt(1, Location::Any()); |
| 2789 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2790 | break; |
| 2791 | } |
| 2792 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2793 | case Primitive::kPrimFloat: |
| 2794 | case Primitive::kPrimDouble: { |
| 2795 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2796 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2797 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2798 | } else if (add->InputAt(1)->IsConstant()) { |
| 2799 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2800 | } else { |
| 2801 | locations->SetInAt(1, Location::Any()); |
| 2802 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2803 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2804 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2805 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2806 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2807 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2808 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2809 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2810 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2811 | } |
| 2812 | |
| 2813 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2814 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2815 | Location first = locations->InAt(0); |
| 2816 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2817 | Location out = locations->Out(); |
| 2818 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2819 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2820 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2821 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2822 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2823 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2824 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2825 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2826 | } else { |
| 2827 | __ leal(out.AsRegister<Register>(), Address( |
| 2828 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2829 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2830 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2831 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2832 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2833 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2834 | } else { |
| 2835 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2836 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2837 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2838 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2839 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2840 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2841 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2845 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2846 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2847 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2848 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2849 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2850 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2851 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2852 | } else { |
| 2853 | DCHECK(second.IsConstant()) << second; |
| 2854 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2855 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2856 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2857 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2858 | break; |
| 2859 | } |
| 2860 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2861 | case Primitive::kPrimFloat: { |
| 2862 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2863 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2864 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2865 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2866 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2867 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2868 | codegen_->LiteralFloatAddress( |
| 2869 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2870 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2871 | } else { |
| 2872 | DCHECK(second.IsStackSlot()); |
| 2873 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2874 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2875 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | case Primitive::kPrimDouble: { |
| 2879 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2880 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2881 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2882 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2883 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2884 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2885 | codegen_->LiteralDoubleAddress( |
| 2886 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2887 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2888 | } else { |
| 2889 | DCHECK(second.IsDoubleStackSlot()); |
| 2890 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2891 | } |
| 2892 | break; |
| 2893 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2894 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2895 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2896 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2897 | } |
| 2898 | } |
| 2899 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2900 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2901 | LocationSummary* locations = |
| 2902 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2903 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2904 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2905 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2906 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2907 | locations->SetInAt(1, Location::Any()); |
| 2908 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2909 | break; |
| 2910 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2911 | case Primitive::kPrimFloat: |
| 2912 | case Primitive::kPrimDouble: { |
| 2913 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2914 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2915 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2916 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2917 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2918 | } else { |
| 2919 | locations->SetInAt(1, Location::Any()); |
| 2920 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2921 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2922 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2923 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2924 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2925 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2926 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2927 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2931 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2932 | Location first = locations->InAt(0); |
| 2933 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2934 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2935 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2936 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2937 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2938 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2939 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2940 | __ subl(first.AsRegister<Register>(), |
| 2941 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2942 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2943 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2944 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2945 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2949 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2950 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2951 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2952 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2953 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2954 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2955 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2956 | } else { |
| 2957 | DCHECK(second.IsConstant()) << second; |
| 2958 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2959 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2960 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2961 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2962 | break; |
| 2963 | } |
| 2964 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2965 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2966 | if (second.IsFpuRegister()) { |
| 2967 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2968 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2969 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2970 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2971 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2972 | codegen_->LiteralFloatAddress( |
| 2973 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2974 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2975 | } else { |
| 2976 | DCHECK(second.IsStackSlot()); |
| 2977 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2978 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2979 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2983 | if (second.IsFpuRegister()) { |
| 2984 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2985 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2986 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2987 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2988 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2989 | codegen_->LiteralDoubleAddress( |
| 2990 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2991 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2992 | } else { |
| 2993 | DCHECK(second.IsDoubleStackSlot()); |
| 2994 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2995 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2996 | break; |
| 2997 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2998 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2999 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3000 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3004 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3005 | LocationSummary* locations = |
| 3006 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3007 | switch (mul->GetResultType()) { |
| 3008 | case Primitive::kPrimInt: |
| 3009 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3010 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3011 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3012 | // Can use 3 operand multiply. |
| 3013 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3014 | } else { |
| 3015 | locations->SetOut(Location::SameAsFirstInput()); |
| 3016 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3017 | break; |
| 3018 | case Primitive::kPrimLong: { |
| 3019 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3020 | locations->SetInAt(1, Location::Any()); |
| 3021 | locations->SetOut(Location::SameAsFirstInput()); |
| 3022 | // Needed for imul on 32bits with 64bits output. |
| 3023 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3024 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3025 | break; |
| 3026 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3027 | case Primitive::kPrimFloat: |
| 3028 | case Primitive::kPrimDouble: { |
| 3029 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3030 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3031 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3032 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3033 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3034 | } else { |
| 3035 | locations->SetInAt(1, Location::Any()); |
| 3036 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3037 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3038 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3039 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3040 | |
| 3041 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3042 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3047 | LocationSummary* locations = mul->GetLocations(); |
| 3048 | Location first = locations->InAt(0); |
| 3049 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3050 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3051 | |
| 3052 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3053 | case Primitive::kPrimInt: |
| 3054 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3055 | // problems where the output may not be the same as the first operand. |
| 3056 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3057 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3058 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3059 | } else if (second.IsRegister()) { |
| 3060 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3061 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3062 | } else { |
| 3063 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3064 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3065 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3066 | } |
| 3067 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3068 | |
| 3069 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3070 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3071 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3072 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3073 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3074 | |
| 3075 | DCHECK_EQ(EAX, eax); |
| 3076 | DCHECK_EQ(EDX, edx); |
| 3077 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3078 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3079 | // output: in1 |
| 3080 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3081 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3082 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3083 | if (second.IsConstant()) { |
| 3084 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3085 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3086 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3087 | int32_t low_value = Low32Bits(value); |
| 3088 | int32_t high_value = High32Bits(value); |
| 3089 | Immediate low(low_value); |
| 3090 | Immediate high(high_value); |
| 3091 | |
| 3092 | __ movl(eax, high); |
| 3093 | // eax <- in1.lo * in2.hi |
| 3094 | __ imull(eax, in1_lo); |
| 3095 | // in1.hi <- in1.hi * in2.lo |
| 3096 | __ imull(in1_hi, low); |
| 3097 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3098 | __ addl(in1_hi, eax); |
| 3099 | // move in2_lo to eax to prepare for double precision |
| 3100 | __ movl(eax, low); |
| 3101 | // edx:eax <- in1.lo * in2.lo |
| 3102 | __ mull(in1_lo); |
| 3103 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3104 | __ addl(in1_hi, edx); |
| 3105 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3106 | __ movl(in1_lo, eax); |
| 3107 | } else if (second.IsRegisterPair()) { |
| 3108 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3109 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3110 | |
| 3111 | __ movl(eax, in2_hi); |
| 3112 | // eax <- in1.lo * in2.hi |
| 3113 | __ imull(eax, in1_lo); |
| 3114 | // in1.hi <- in1.hi * in2.lo |
| 3115 | __ imull(in1_hi, in2_lo); |
| 3116 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3117 | __ addl(in1_hi, eax); |
| 3118 | // move in1_lo to eax to prepare for double precision |
| 3119 | __ movl(eax, in1_lo); |
| 3120 | // edx:eax <- in1.lo * in2.lo |
| 3121 | __ mull(in2_lo); |
| 3122 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3123 | __ addl(in1_hi, edx); |
| 3124 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3125 | __ movl(in1_lo, eax); |
| 3126 | } else { |
| 3127 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3128 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3129 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3130 | |
| 3131 | __ movl(eax, in2_hi); |
| 3132 | // eax <- in1.lo * in2.hi |
| 3133 | __ imull(eax, in1_lo); |
| 3134 | // in1.hi <- in1.hi * in2.lo |
| 3135 | __ imull(in1_hi, in2_lo); |
| 3136 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3137 | __ addl(in1_hi, eax); |
| 3138 | // move in1_lo to eax to prepare for double precision |
| 3139 | __ movl(eax, in1_lo); |
| 3140 | // edx:eax <- in1.lo * in2.lo |
| 3141 | __ mull(in2_lo); |
| 3142 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3143 | __ addl(in1_hi, edx); |
| 3144 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3145 | __ movl(in1_lo, eax); |
| 3146 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3147 | |
| 3148 | break; |
| 3149 | } |
| 3150 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3151 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3152 | DCHECK(first.Equals(locations->Out())); |
| 3153 | if (second.IsFpuRegister()) { |
| 3154 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3155 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3156 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3157 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3158 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3159 | codegen_->LiteralFloatAddress( |
| 3160 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3161 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3162 | } else { |
| 3163 | DCHECK(second.IsStackSlot()); |
| 3164 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3165 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3166 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3170 | DCHECK(first.Equals(locations->Out())); |
| 3171 | if (second.IsFpuRegister()) { |
| 3172 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3173 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3174 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3175 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3176 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3177 | codegen_->LiteralDoubleAddress( |
| 3178 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3179 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3180 | } else { |
| 3181 | DCHECK(second.IsDoubleStackSlot()); |
| 3182 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3183 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3184 | break; |
| 3185 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3186 | |
| 3187 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3188 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3192 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3193 | uint32_t temp_offset, |
| 3194 | uint32_t stack_adjustment, |
| 3195 | bool is_fp, |
| 3196 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3197 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3198 | DCHECK(!is_wide); |
| 3199 | if (is_fp) { |
| 3200 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3201 | } else { |
| 3202 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3203 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3204 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3205 | DCHECK(is_wide); |
| 3206 | if (is_fp) { |
| 3207 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3208 | } else { |
| 3209 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3210 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3211 | } else { |
| 3212 | // 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] | 3213 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3214 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3215 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3216 | if (is_fp) { |
| 3217 | __ flds(Address(ESP, temp_offset)); |
| 3218 | } else { |
| 3219 | __ filds(Address(ESP, temp_offset)); |
| 3220 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3221 | } else { |
| 3222 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3223 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3224 | if (is_fp) { |
| 3225 | __ fldl(Address(ESP, temp_offset)); |
| 3226 | } else { |
| 3227 | __ fildl(Address(ESP, temp_offset)); |
| 3228 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3234 | Primitive::Type type = rem->GetResultType(); |
| 3235 | bool is_float = type == Primitive::kPrimFloat; |
| 3236 | size_t elem_size = Primitive::ComponentSize(type); |
| 3237 | LocationSummary* locations = rem->GetLocations(); |
| 3238 | Location first = locations->InAt(0); |
| 3239 | Location second = locations->InAt(1); |
| 3240 | Location out = locations->Out(); |
| 3241 | |
| 3242 | // Create stack space for 2 elements. |
| 3243 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3244 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3245 | |
| 3246 | // 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] | 3247 | const bool is_wide = !is_float; |
| 3248 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3249 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3250 | |
| 3251 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3252 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3253 | __ Bind(&retry); |
| 3254 | __ fprem(); |
| 3255 | |
| 3256 | // Move FP status to AX. |
| 3257 | __ fstsw(); |
| 3258 | |
| 3259 | // And see if the argument reduction is complete. This is signaled by the |
| 3260 | // C2 FPU flag bit set to 0. |
| 3261 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3262 | __ j(kNotEqual, &retry); |
| 3263 | |
| 3264 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3265 | // Store FP top of stack to real stack. |
| 3266 | if (is_float) { |
| 3267 | __ fsts(Address(ESP, 0)); |
| 3268 | } else { |
| 3269 | __ fstl(Address(ESP, 0)); |
| 3270 | } |
| 3271 | |
| 3272 | // Pop the 2 items from the FP stack. |
| 3273 | __ fucompp(); |
| 3274 | |
| 3275 | // Load the value from the stack into an XMM register. |
| 3276 | DCHECK(out.IsFpuRegister()) << out; |
| 3277 | if (is_float) { |
| 3278 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3279 | } else { |
| 3280 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3281 | } |
| 3282 | |
| 3283 | // And remove the temporary stack space we allocated. |
| 3284 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3285 | } |
| 3286 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3287 | |
| 3288 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3289 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3290 | |
| 3291 | LocationSummary* locations = instruction->GetLocations(); |
| 3292 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3293 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3294 | |
| 3295 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3296 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3297 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3298 | |
| 3299 | DCHECK(imm == 1 || imm == -1); |
| 3300 | |
| 3301 | if (instruction->IsRem()) { |
| 3302 | __ xorl(out_register, out_register); |
| 3303 | } else { |
| 3304 | __ movl(out_register, input_register); |
| 3305 | if (imm == -1) { |
| 3306 | __ negl(out_register); |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3312 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3313 | LocationSummary* locations = instruction->GetLocations(); |
| 3314 | |
| 3315 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3316 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3317 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3318 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3319 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3320 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3321 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3322 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3323 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3324 | __ testl(input_register, input_register); |
| 3325 | __ cmovl(kGreaterEqual, num, input_register); |
| 3326 | int shift = CTZ(imm); |
| 3327 | __ sarl(num, Immediate(shift)); |
| 3328 | |
| 3329 | if (imm < 0) { |
| 3330 | __ negl(num); |
| 3331 | } |
| 3332 | |
| 3333 | __ movl(out_register, num); |
| 3334 | } |
| 3335 | |
| 3336 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3337 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3338 | |
| 3339 | LocationSummary* locations = instruction->GetLocations(); |
| 3340 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3341 | |
| 3342 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3343 | Register out = locations->Out().AsRegister<Register>(); |
| 3344 | Register num; |
| 3345 | Register edx; |
| 3346 | |
| 3347 | if (instruction->IsDiv()) { |
| 3348 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3349 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3350 | } else { |
| 3351 | edx = locations->Out().AsRegister<Register>(); |
| 3352 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3353 | } |
| 3354 | |
| 3355 | DCHECK_EQ(EAX, eax); |
| 3356 | DCHECK_EQ(EDX, edx); |
| 3357 | if (instruction->IsDiv()) { |
| 3358 | DCHECK_EQ(EAX, out); |
| 3359 | } else { |
| 3360 | DCHECK_EQ(EDX, out); |
| 3361 | } |
| 3362 | |
| 3363 | int64_t magic; |
| 3364 | int shift; |
| 3365 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3366 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3367 | NearLabel ndiv; |
| 3368 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3369 | // If numerator is 0, the result is 0, no computation needed. |
| 3370 | __ testl(eax, eax); |
| 3371 | __ j(kNotEqual, &ndiv); |
| 3372 | |
| 3373 | __ xorl(out, out); |
| 3374 | __ jmp(&end); |
| 3375 | |
| 3376 | __ Bind(&ndiv); |
| 3377 | |
| 3378 | // Save the numerator. |
| 3379 | __ movl(num, eax); |
| 3380 | |
| 3381 | // EAX = magic |
| 3382 | __ movl(eax, Immediate(magic)); |
| 3383 | |
| 3384 | // EDX:EAX = magic * numerator |
| 3385 | __ imull(num); |
| 3386 | |
| 3387 | if (imm > 0 && magic < 0) { |
| 3388 | // EDX += num |
| 3389 | __ addl(edx, num); |
| 3390 | } else if (imm < 0 && magic > 0) { |
| 3391 | __ subl(edx, num); |
| 3392 | } |
| 3393 | |
| 3394 | // Shift if needed. |
| 3395 | if (shift != 0) { |
| 3396 | __ sarl(edx, Immediate(shift)); |
| 3397 | } |
| 3398 | |
| 3399 | // EDX += 1 if EDX < 0 |
| 3400 | __ movl(eax, edx); |
| 3401 | __ shrl(edx, Immediate(31)); |
| 3402 | __ addl(edx, eax); |
| 3403 | |
| 3404 | if (instruction->IsRem()) { |
| 3405 | __ movl(eax, num); |
| 3406 | __ imull(edx, Immediate(imm)); |
| 3407 | __ subl(eax, edx); |
| 3408 | __ movl(edx, eax); |
| 3409 | } else { |
| 3410 | __ movl(eax, edx); |
| 3411 | } |
| 3412 | __ Bind(&end); |
| 3413 | } |
| 3414 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3415 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3416 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3417 | |
| 3418 | LocationSummary* locations = instruction->GetLocations(); |
| 3419 | Location out = locations->Out(); |
| 3420 | Location first = locations->InAt(0); |
| 3421 | Location second = locations->InAt(1); |
| 3422 | bool is_div = instruction->IsDiv(); |
| 3423 | |
| 3424 | switch (instruction->GetResultType()) { |
| 3425 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3426 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3427 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3428 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3429 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3430 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3431 | |
| 3432 | if (imm == 0) { |
| 3433 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3434 | } else if (imm == 1 || imm == -1) { |
| 3435 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3436 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3437 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3438 | } else { |
| 3439 | DCHECK(imm <= -2 || imm >= 2); |
| 3440 | GenerateDivRemWithAnyConstant(instruction); |
| 3441 | } |
| 3442 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3443 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3444 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3445 | is_div); |
| 3446 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3447 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3448 | Register second_reg = second.AsRegister<Register>(); |
| 3449 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3450 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3451 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3452 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | __ cmpl(second_reg, Immediate(-1)); |
| 3454 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3455 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3456 | // edx:eax <- sign-extended of eax |
| 3457 | __ cdq(); |
| 3458 | // eax = quotient, edx = remainder |
| 3459 | __ idivl(second_reg); |
| 3460 | __ Bind(slow_path->GetExitLabel()); |
| 3461 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3462 | break; |
| 3463 | } |
| 3464 | |
| 3465 | case Primitive::kPrimLong: { |
| 3466 | InvokeRuntimeCallingConvention calling_convention; |
| 3467 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3468 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3469 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3470 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3471 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3472 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3473 | |
| 3474 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3475 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3476 | instruction, |
| 3477 | instruction->GetDexPc(), |
| 3478 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3479 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3480 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3481 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3482 | instruction, |
| 3483 | instruction->GetDexPc(), |
| 3484 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3485 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3486 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3487 | break; |
| 3488 | } |
| 3489 | |
| 3490 | default: |
| 3491 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3492 | } |
| 3493 | } |
| 3494 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3495 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3496 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3497 | ? LocationSummary::kCall |
| 3498 | : LocationSummary::kNoCall; |
| 3499 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3500 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3501 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3502 | case Primitive::kPrimInt: { |
| 3503 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3504 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3505 | locations->SetOut(Location::SameAsFirstInput()); |
| 3506 | // Intel uses edx:eax as the dividend. |
| 3507 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3508 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3509 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3510 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3511 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3512 | locations->AddTemp(Location::RequiresRegister()); |
| 3513 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3514 | break; |
| 3515 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3516 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3517 | InvokeRuntimeCallingConvention calling_convention; |
| 3518 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3519 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3520 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3521 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3522 | // Runtime helper puts the result in EAX, EDX. |
| 3523 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3524 | break; |
| 3525 | } |
| 3526 | case Primitive::kPrimFloat: |
| 3527 | case Primitive::kPrimDouble: { |
| 3528 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3529 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3530 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3531 | } else if (div->InputAt(1)->IsConstant()) { |
| 3532 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3533 | } else { |
| 3534 | locations->SetInAt(1, Location::Any()); |
| 3535 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3536 | locations->SetOut(Location::SameAsFirstInput()); |
| 3537 | break; |
| 3538 | } |
| 3539 | |
| 3540 | default: |
| 3541 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3546 | LocationSummary* locations = div->GetLocations(); |
| 3547 | Location first = locations->InAt(0); |
| 3548 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3549 | |
| 3550 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3551 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3552 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | } |
| 3556 | |
| 3557 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3558 | if (second.IsFpuRegister()) { |
| 3559 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3560 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3561 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3562 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3563 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3564 | codegen_->LiteralFloatAddress( |
| 3565 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3566 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3567 | } else { |
| 3568 | DCHECK(second.IsStackSlot()); |
| 3569 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3570 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3571 | break; |
| 3572 | } |
| 3573 | |
| 3574 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3575 | if (second.IsFpuRegister()) { |
| 3576 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3577 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3578 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3579 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3580 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3581 | codegen_->LiteralDoubleAddress( |
| 3582 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3583 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3584 | } else { |
| 3585 | DCHECK(second.IsDoubleStackSlot()); |
| 3586 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3587 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3588 | break; |
| 3589 | } |
| 3590 | |
| 3591 | default: |
| 3592 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3593 | } |
| 3594 | } |
| 3595 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3596 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3597 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3598 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3599 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3600 | ? LocationSummary::kCall |
| 3601 | : LocationSummary::kNoCall; |
| 3602 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3603 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3604 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | case Primitive::kPrimInt: { |
| 3606 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3607 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3609 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3610 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3611 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3612 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3613 | locations->AddTemp(Location::RequiresRegister()); |
| 3614 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | } |
| 3617 | case Primitive::kPrimLong: { |
| 3618 | InvokeRuntimeCallingConvention calling_convention; |
| 3619 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3620 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3621 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3622 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3623 | // Runtime helper puts the result in EAX, EDX. |
| 3624 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3625 | break; |
| 3626 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3627 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3628 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3629 | locations->SetInAt(0, Location::Any()); |
| 3630 | locations->SetInAt(1, Location::Any()); |
| 3631 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3632 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3633 | break; |
| 3634 | } |
| 3635 | |
| 3636 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3637 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3642 | Primitive::Type type = rem->GetResultType(); |
| 3643 | switch (type) { |
| 3644 | case Primitive::kPrimInt: |
| 3645 | case Primitive::kPrimLong: { |
| 3646 | GenerateDivRemIntegral(rem); |
| 3647 | break; |
| 3648 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3649 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3650 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3651 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3652 | break; |
| 3653 | } |
| 3654 | default: |
| 3655 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3656 | } |
| 3657 | } |
| 3658 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3659 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3660 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3661 | ? LocationSummary::kCallOnSlowPath |
| 3662 | : LocationSummary::kNoCall; |
| 3663 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3664 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3665 | case Primitive::kPrimByte: |
| 3666 | case Primitive::kPrimChar: |
| 3667 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3668 | case Primitive::kPrimInt: { |
| 3669 | locations->SetInAt(0, Location::Any()); |
| 3670 | break; |
| 3671 | } |
| 3672 | case Primitive::kPrimLong: { |
| 3673 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3674 | if (!instruction->IsConstant()) { |
| 3675 | locations->AddTemp(Location::RequiresRegister()); |
| 3676 | } |
| 3677 | break; |
| 3678 | } |
| 3679 | default: |
| 3680 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3681 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3682 | if (instruction->HasUses()) { |
| 3683 | locations->SetOut(Location::SameAsFirstInput()); |
| 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3688 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3689 | codegen_->AddSlowPath(slow_path); |
| 3690 | |
| 3691 | LocationSummary* locations = instruction->GetLocations(); |
| 3692 | Location value = locations->InAt(0); |
| 3693 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3694 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3695 | case Primitive::kPrimByte: |
| 3696 | case Primitive::kPrimChar: |
| 3697 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3698 | case Primitive::kPrimInt: { |
| 3699 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3700 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3701 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3702 | } else if (value.IsStackSlot()) { |
| 3703 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3704 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3705 | } else { |
| 3706 | DCHECK(value.IsConstant()) << value; |
| 3707 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3708 | __ jmp(slow_path->GetEntryLabel()); |
| 3709 | } |
| 3710 | } |
| 3711 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3712 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3713 | case Primitive::kPrimLong: { |
| 3714 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3715 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3716 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3717 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3718 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3719 | } else { |
| 3720 | DCHECK(value.IsConstant()) << value; |
| 3721 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3722 | __ jmp(slow_path->GetEntryLabel()); |
| 3723 | } |
| 3724 | } |
| 3725 | break; |
| 3726 | } |
| 3727 | default: |
| 3728 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3729 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3732 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3733 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3734 | |
| 3735 | LocationSummary* locations = |
| 3736 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3737 | |
| 3738 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3739 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3740 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3741 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3742 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3743 | // The shift count needs to be in CL or a constant. |
| 3744 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3745 | locations->SetOut(Location::SameAsFirstInput()); |
| 3746 | break; |
| 3747 | } |
| 3748 | default: |
| 3749 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3750 | } |
| 3751 | } |
| 3752 | |
| 3753 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3754 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3755 | |
| 3756 | LocationSummary* locations = op->GetLocations(); |
| 3757 | Location first = locations->InAt(0); |
| 3758 | Location second = locations->InAt(1); |
| 3759 | DCHECK(first.Equals(locations->Out())); |
| 3760 | |
| 3761 | switch (op->GetResultType()) { |
| 3762 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3763 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3764 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3765 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3766 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3767 | DCHECK_EQ(ECX, second_reg); |
| 3768 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3769 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3770 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3771 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3772 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3773 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3774 | } |
| 3775 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3776 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3777 | if (shift == 0) { |
| 3778 | return; |
| 3779 | } |
| 3780 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3781 | if (op->IsShl()) { |
| 3782 | __ shll(first_reg, imm); |
| 3783 | } else if (op->IsShr()) { |
| 3784 | __ sarl(first_reg, imm); |
| 3785 | } else { |
| 3786 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | break; |
| 3790 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3791 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3792 | if (second.IsRegister()) { |
| 3793 | Register second_reg = second.AsRegister<Register>(); |
| 3794 | DCHECK_EQ(ECX, second_reg); |
| 3795 | if (op->IsShl()) { |
| 3796 | GenerateShlLong(first, second_reg); |
| 3797 | } else if (op->IsShr()) { |
| 3798 | GenerateShrLong(first, second_reg); |
| 3799 | } else { |
| 3800 | GenerateUShrLong(first, second_reg); |
| 3801 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3802 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3803 | // Shift by a constant. |
| 3804 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3805 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3806 | if (shift != 0) { |
| 3807 | if (op->IsShl()) { |
| 3808 | GenerateShlLong(first, shift); |
| 3809 | } else if (op->IsShr()) { |
| 3810 | GenerateShrLong(first, shift); |
| 3811 | } else { |
| 3812 | GenerateUShrLong(first, shift); |
| 3813 | } |
| 3814 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3815 | } |
| 3816 | break; |
| 3817 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3818 | default: |
| 3819 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3820 | } |
| 3821 | } |
| 3822 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3823 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3824 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3825 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3826 | if (shift == 1) { |
| 3827 | // This is just an addition. |
| 3828 | __ addl(low, low); |
| 3829 | __ adcl(high, high); |
| 3830 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3831 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3832 | codegen_->EmitParallelMoves( |
| 3833 | loc.ToLow(), |
| 3834 | loc.ToHigh(), |
| 3835 | Primitive::kPrimInt, |
| 3836 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3837 | loc.ToLow(), |
| 3838 | Primitive::kPrimInt); |
| 3839 | } else if (shift > 32) { |
| 3840 | // Low part becomes 0. High part is low part << (shift-32). |
| 3841 | __ movl(high, low); |
| 3842 | __ shll(high, Immediate(shift - 32)); |
| 3843 | __ xorl(low, low); |
| 3844 | } else { |
| 3845 | // Between 1 and 31. |
| 3846 | __ shld(high, low, Immediate(shift)); |
| 3847 | __ shll(low, Immediate(shift)); |
| 3848 | } |
| 3849 | } |
| 3850 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3851 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3852 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3853 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3854 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3855 | __ testl(shifter, Immediate(32)); |
| 3856 | __ j(kEqual, &done); |
| 3857 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3858 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3859 | __ Bind(&done); |
| 3860 | } |
| 3861 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3862 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3863 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3864 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3865 | if (shift == 32) { |
| 3866 | // Need to copy the sign. |
| 3867 | DCHECK_NE(low, high); |
| 3868 | __ movl(low, high); |
| 3869 | __ sarl(high, Immediate(31)); |
| 3870 | } else if (shift > 32) { |
| 3871 | DCHECK_NE(low, high); |
| 3872 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3873 | __ movl(low, high); |
| 3874 | __ sarl(high, Immediate(31)); |
| 3875 | __ sarl(low, Immediate(shift - 32)); |
| 3876 | } else { |
| 3877 | // Between 1 and 31. |
| 3878 | __ shrd(low, high, Immediate(shift)); |
| 3879 | __ sarl(high, Immediate(shift)); |
| 3880 | } |
| 3881 | } |
| 3882 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3883 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3884 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3885 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3886 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3887 | __ testl(shifter, Immediate(32)); |
| 3888 | __ j(kEqual, &done); |
| 3889 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3890 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3891 | __ Bind(&done); |
| 3892 | } |
| 3893 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3894 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3895 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3896 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3897 | if (shift == 32) { |
| 3898 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3899 | codegen_->EmitParallelMoves( |
| 3900 | loc.ToHigh(), |
| 3901 | loc.ToLow(), |
| 3902 | Primitive::kPrimInt, |
| 3903 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3904 | loc.ToHigh(), |
| 3905 | Primitive::kPrimInt); |
| 3906 | } else if (shift > 32) { |
| 3907 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3908 | __ movl(low, high); |
| 3909 | __ shrl(low, Immediate(shift - 32)); |
| 3910 | __ xorl(high, high); |
| 3911 | } else { |
| 3912 | // Between 1 and 31. |
| 3913 | __ shrd(low, high, Immediate(shift)); |
| 3914 | __ shrl(high, Immediate(shift)); |
| 3915 | } |
| 3916 | } |
| 3917 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3918 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3919 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3920 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3921 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3922 | __ testl(shifter, Immediate(32)); |
| 3923 | __ j(kEqual, &done); |
| 3924 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3925 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3926 | __ Bind(&done); |
| 3927 | } |
| 3928 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3929 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3930 | LocationSummary* locations = |
| 3931 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3932 | |
| 3933 | switch (ror->GetResultType()) { |
| 3934 | case Primitive::kPrimLong: |
| 3935 | // Add the temporary needed. |
| 3936 | locations->AddTemp(Location::RequiresRegister()); |
| 3937 | FALLTHROUGH_INTENDED; |
| 3938 | case Primitive::kPrimInt: |
| 3939 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3940 | // The shift count needs to be in CL (unless it is a constant). |
| 3941 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3942 | locations->SetOut(Location::SameAsFirstInput()); |
| 3943 | break; |
| 3944 | default: |
| 3945 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3946 | UNREACHABLE(); |
| 3947 | } |
| 3948 | } |
| 3949 | |
| 3950 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3951 | LocationSummary* locations = ror->GetLocations(); |
| 3952 | Location first = locations->InAt(0); |
| 3953 | Location second = locations->InAt(1); |
| 3954 | |
| 3955 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3956 | Register first_reg = first.AsRegister<Register>(); |
| 3957 | if (second.IsRegister()) { |
| 3958 | Register second_reg = second.AsRegister<Register>(); |
| 3959 | __ rorl(first_reg, second_reg); |
| 3960 | } else { |
| 3961 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3962 | __ rorl(first_reg, imm); |
| 3963 | } |
| 3964 | return; |
| 3965 | } |
| 3966 | |
| 3967 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3968 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3969 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3970 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3971 | if (second.IsRegister()) { |
| 3972 | Register second_reg = second.AsRegister<Register>(); |
| 3973 | DCHECK_EQ(second_reg, ECX); |
| 3974 | __ movl(temp_reg, first_reg_hi); |
| 3975 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3976 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3977 | __ movl(temp_reg, first_reg_hi); |
| 3978 | __ testl(second_reg, Immediate(32)); |
| 3979 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3980 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3981 | } else { |
| 3982 | int32_t shift_amt = |
| 3983 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3984 | if (shift_amt == 0) { |
| 3985 | // Already fine. |
| 3986 | return; |
| 3987 | } |
| 3988 | if (shift_amt == 32) { |
| 3989 | // Just swap. |
| 3990 | __ movl(temp_reg, first_reg_lo); |
| 3991 | __ movl(first_reg_lo, first_reg_hi); |
| 3992 | __ movl(first_reg_hi, temp_reg); |
| 3993 | return; |
| 3994 | } |
| 3995 | |
| 3996 | Immediate imm(shift_amt); |
| 3997 | // Save the constents of the low value. |
| 3998 | __ movl(temp_reg, first_reg_lo); |
| 3999 | |
| 4000 | // Shift right into low, feeding bits from high. |
| 4001 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4002 | |
| 4003 | // Shift right into high, feeding bits from the original low. |
| 4004 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4005 | |
| 4006 | // Swap if needed. |
| 4007 | if (shift_amt > 32) { |
| 4008 | __ movl(temp_reg, first_reg_lo); |
| 4009 | __ movl(first_reg_lo, first_reg_hi); |
| 4010 | __ movl(first_reg_hi, temp_reg); |
| 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4015 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4016 | HandleShift(shl); |
| 4017 | } |
| 4018 | |
| 4019 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4020 | HandleShift(shl); |
| 4021 | } |
| 4022 | |
| 4023 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4024 | HandleShift(shr); |
| 4025 | } |
| 4026 | |
| 4027 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4028 | HandleShift(shr); |
| 4029 | } |
| 4030 | |
| 4031 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4032 | HandleShift(ushr); |
| 4033 | } |
| 4034 | |
| 4035 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4036 | HandleShift(ushr); |
| 4037 | } |
| 4038 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4039 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4040 | LocationSummary* locations = |
| 4041 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4042 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4043 | if (instruction->IsStringAlloc()) { |
| 4044 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4045 | } else { |
| 4046 | InvokeRuntimeCallingConvention calling_convention; |
| 4047 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4048 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4049 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4050 | } |
| 4051 | |
| 4052 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4053 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4054 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4055 | if (instruction->IsStringAlloc()) { |
| 4056 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4057 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4058 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4059 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4060 | __ call(Address(temp, code_offset.Int32Value())); |
| 4061 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4062 | } else { |
| 4063 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4064 | instruction, |
| 4065 | instruction->GetDexPc(), |
| 4066 | nullptr); |
| 4067 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4068 | DCHECK(!codegen_->IsLeafMethod()); |
| 4069 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4072 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4073 | LocationSummary* locations = |
| 4074 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4075 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4076 | InvokeRuntimeCallingConvention calling_convention; |
| 4077 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4078 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4079 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4083 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4084 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4085 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4086 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4087 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4088 | instruction, |
| 4089 | instruction->GetDexPc(), |
| 4090 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4091 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4092 | DCHECK(!codegen_->IsLeafMethod()); |
| 4093 | } |
| 4094 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4095 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4096 | LocationSummary* locations = |
| 4097 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4098 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4099 | if (location.IsStackSlot()) { |
| 4100 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4101 | } else if (location.IsDoubleStackSlot()) { |
| 4102 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4103 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4104 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4105 | } |
| 4106 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4107 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4108 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4109 | } |
| 4110 | |
| 4111 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4112 | LocationSummary* locations = |
| 4113 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4114 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4115 | } |
| 4116 | |
| 4117 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4120 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4121 | LocationSummary* locations = |
| 4122 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4123 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4124 | locations->SetOut(Location::RequiresRegister()); |
| 4125 | } |
| 4126 | |
| 4127 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4128 | LocationSummary* locations = instruction->GetLocations(); |
| 4129 | uint32_t method_offset = 0; |
| 4130 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4131 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4132 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4133 | } else { |
| 4134 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4135 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4136 | } |
| 4137 | __ movl(locations->Out().AsRegister<Register>(), |
| 4138 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4139 | } |
| 4140 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4141 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4142 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4143 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4144 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4145 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4146 | } |
| 4147 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4148 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4149 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4150 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4151 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4152 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4153 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4154 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4155 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4156 | break; |
| 4157 | |
| 4158 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4159 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4160 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4161 | break; |
| 4162 | |
| 4163 | default: |
| 4164 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4165 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4166 | } |
| 4167 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4168 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4169 | LocationSummary* locations = |
| 4170 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4171 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4172 | locations->SetOut(Location::SameAsFirstInput()); |
| 4173 | } |
| 4174 | |
| 4175 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4176 | LocationSummary* locations = bool_not->GetLocations(); |
| 4177 | Location in = locations->InAt(0); |
| 4178 | Location out = locations->Out(); |
| 4179 | DCHECK(in.Equals(out)); |
| 4180 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4181 | } |
| 4182 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4183 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4184 | LocationSummary* locations = |
| 4185 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4186 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4187 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4188 | case Primitive::kPrimLong: { |
| 4189 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4190 | locations->SetInAt(1, Location::Any()); |
| 4191 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4192 | break; |
| 4193 | } |
| 4194 | case Primitive::kPrimFloat: |
| 4195 | case Primitive::kPrimDouble: { |
| 4196 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4197 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4198 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4199 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4200 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4201 | } else { |
| 4202 | locations->SetInAt(1, Location::Any()); |
| 4203 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4204 | locations->SetOut(Location::RequiresRegister()); |
| 4205 | break; |
| 4206 | } |
| 4207 | default: |
| 4208 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4209 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4213 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4214 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4215 | Location left = locations->InAt(0); |
| 4216 | Location right = locations->InAt(1); |
| 4217 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4218 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4219 | Condition less_cond = kLess; |
| 4220 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4221 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4222 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame^] | 4223 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4224 | break; |
| 4225 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4226 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4227 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4228 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4229 | int32_t val_low = 0; |
| 4230 | int32_t val_high = 0; |
| 4231 | bool right_is_const = false; |
| 4232 | |
| 4233 | if (right.IsConstant()) { |
| 4234 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4235 | right_is_const = true; |
| 4236 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4237 | val_low = Low32Bits(val); |
| 4238 | val_high = High32Bits(val); |
| 4239 | } |
| 4240 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4241 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4242 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4243 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4244 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4245 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4246 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4247 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4248 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4249 | __ j(kLess, &less); // Signed compare. |
| 4250 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4251 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4252 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4253 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4254 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4255 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4256 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4257 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4258 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4259 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4260 | break; |
| 4261 | } |
| 4262 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4263 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4264 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4265 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4266 | break; |
| 4267 | } |
| 4268 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4269 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4270 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4271 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4272 | break; |
| 4273 | } |
| 4274 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4275 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4276 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4277 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4278 | __ movl(out, Immediate(0)); |
| 4279 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4280 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4281 | |
| 4282 | __ Bind(&greater); |
| 4283 | __ movl(out, Immediate(1)); |
| 4284 | __ jmp(&done); |
| 4285 | |
| 4286 | __ Bind(&less); |
| 4287 | __ movl(out, Immediate(-1)); |
| 4288 | |
| 4289 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4290 | } |
| 4291 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4292 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4293 | LocationSummary* locations = |
| 4294 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4295 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4296 | locations->SetInAt(i, Location::Any()); |
| 4297 | } |
| 4298 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4299 | } |
| 4300 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4301 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4302 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4305 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4306 | /* |
| 4307 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4308 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4309 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4310 | */ |
| 4311 | switch (kind) { |
| 4312 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4313 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4314 | break; |
| 4315 | } |
| 4316 | case MemBarrierKind::kAnyStore: |
| 4317 | case MemBarrierKind::kLoadAny: |
| 4318 | case MemBarrierKind::kStoreStore: { |
| 4319 | // nop |
| 4320 | break; |
| 4321 | } |
| 4322 | default: |
| 4323 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4324 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4325 | } |
| 4326 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4327 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4328 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4329 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4330 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4331 | |
| 4332 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4333 | // is incompatible with it. |
| 4334 | if (GetGraph()->HasIrreducibleLoops() && |
| 4335 | (dispatch_info.method_load_kind == |
| 4336 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4337 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4338 | } |
| 4339 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4340 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4341 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4342 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4343 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4344 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4345 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4346 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4347 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4348 | 0u |
| 4349 | }; |
| 4350 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4351 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4352 | } |
| 4353 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4354 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4355 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4356 | Register temp) { |
| 4357 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4358 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4359 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4360 | return location.AsRegister<Register>(); |
| 4361 | } |
| 4362 | // For intrinsics we allow any location, so it may be on the stack. |
| 4363 | if (!location.IsRegister()) { |
| 4364 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4365 | return temp; |
| 4366 | } |
| 4367 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4368 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4369 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4370 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4371 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4372 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4373 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4374 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4375 | __ movl(temp, Address(ESP, stack_offset)); |
| 4376 | return temp; |
| 4377 | } |
| 4378 | return location.AsRegister<Register>(); |
| 4379 | } |
| 4380 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4381 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4382 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4383 | switch (invoke->GetMethodLoadKind()) { |
| 4384 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4385 | // temp = thread->string_init_entrypoint |
| 4386 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4387 | break; |
| 4388 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4389 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4390 | break; |
| 4391 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4392 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4393 | break; |
| 4394 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4395 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4396 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4397 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4398 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4399 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4400 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4401 | temp.AsRegister<Register>()); |
| 4402 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4403 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4404 | // Add the patch entry and bind its label at the end of the instruction. |
| 4405 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4406 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4407 | break; |
| 4408 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4409 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4410 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4411 | Register method_reg; |
| 4412 | Register reg = temp.AsRegister<Register>(); |
| 4413 | if (current_method.IsRegister()) { |
| 4414 | method_reg = current_method.AsRegister<Register>(); |
| 4415 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4416 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4417 | DCHECK(!current_method.IsValid()); |
| 4418 | method_reg = reg; |
| 4419 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4420 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4421 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4422 | __ movl(reg, Address(method_reg, |
| 4423 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4424 | // temp = temp[index_in_cache] |
| 4425 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4426 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4427 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4428 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | switch (invoke->GetCodePtrLocation()) { |
| 4432 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4433 | __ call(GetFrameEntryLabel()); |
| 4434 | break; |
| 4435 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4436 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4437 | Label* label = &relative_call_patches_.back().label; |
| 4438 | __ call(label); // Bind to the patch label, override at link time. |
| 4439 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4440 | break; |
| 4441 | } |
| 4442 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4443 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4444 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4445 | LOG(FATAL) << "Unsupported"; |
| 4446 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4447 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4448 | // (callee_method + offset_of_quick_compiled_code)() |
| 4449 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4450 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4451 | kX86WordSize).Int32Value())); |
| 4452 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4456 | } |
| 4457 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4458 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4459 | Register temp = temp_in.AsRegister<Register>(); |
| 4460 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4461 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4462 | |
| 4463 | // Use the calling convention instead of the location of the receiver, as |
| 4464 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4465 | // slow path, the arguments have been moved to the right place, so here we are |
| 4466 | // guaranteed that the receiver is the first register of the calling convention. |
| 4467 | InvokeDexCallingConvention calling_convention; |
| 4468 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4469 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4470 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4471 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4472 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4473 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4474 | // emit a read barrier for the previous class reference load. |
| 4475 | // However this is not required in practice, as this is an |
| 4476 | // intermediate/temporary reference and because the current |
| 4477 | // concurrent copying collector keeps the from-space memory |
| 4478 | // intact/accessible until the end of the marking phase (the |
| 4479 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4480 | __ MaybeUnpoisonHeapReference(temp); |
| 4481 | // temp = temp->GetMethodAt(method_offset); |
| 4482 | __ movl(temp, Address(temp, method_offset)); |
| 4483 | // call temp->GetEntryPoint(); |
| 4484 | __ call(Address( |
| 4485 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4486 | } |
| 4487 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4488 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4489 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4490 | size_t size = |
| 4491 | method_patches_.size() + |
| 4492 | relative_call_patches_.size() + |
| 4493 | pc_relative_dex_cache_patches_.size(); |
| 4494 | linker_patches->reserve(size); |
| 4495 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4496 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4497 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4498 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4499 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4500 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4501 | info.target_method.dex_file, |
| 4502 | info.target_method.dex_method_index)); |
| 4503 | } |
| 4504 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4505 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4506 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4507 | info.target_method.dex_file, |
| 4508 | info.target_method.dex_method_index)); |
| 4509 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4510 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4511 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4512 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4513 | &info.target_dex_file, |
| 4514 | GetMethodAddressOffset(), |
| 4515 | info.element_offset)); |
| 4516 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4517 | } |
| 4518 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4519 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4520 | Register card, |
| 4521 | Register object, |
| 4522 | Register value, |
| 4523 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4524 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4525 | if (value_can_be_null) { |
| 4526 | __ testl(value, value); |
| 4527 | __ j(kEqual, &is_null); |
| 4528 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4529 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4530 | __ movl(temp, object); |
| 4531 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4532 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4533 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4534 | if (value_can_be_null) { |
| 4535 | __ Bind(&is_null); |
| 4536 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4537 | } |
| 4538 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4539 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4540 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4541 | |
| 4542 | bool object_field_get_with_read_barrier = |
| 4543 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4544 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4545 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4546 | kEmitCompilerReadBarrier ? |
| 4547 | LocationSummary::kCallOnSlowPath : |
| 4548 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4549 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4550 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4551 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4552 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4553 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4554 | // The output overlaps in case of long: we don't want the low move |
| 4555 | // to overwrite the object's location. Likewise, in the case of |
| 4556 | // an object field get with read barriers enabled, we do not want |
| 4557 | // the move to overwrite the object's location, as we need it to emit |
| 4558 | // the read barrier. |
| 4559 | locations->SetOut( |
| 4560 | Location::RequiresRegister(), |
| 4561 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4562 | Location::kOutputOverlap : |
| 4563 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4564 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | |
| 4566 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4567 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4568 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4569 | // load the temp into the XMM and then copy the XMM into the |
| 4570 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4571 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4572 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4573 | // We need a temporary register for the read barrier marking slow |
| 4574 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4575 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4576 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4577 | } |
| 4578 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4579 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4580 | const FieldInfo& field_info) { |
| 4581 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4582 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4583 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4584 | Location base_loc = locations->InAt(0); |
| 4585 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4586 | Location out = locations->Out(); |
| 4587 | bool is_volatile = field_info.IsVolatile(); |
| 4588 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4589 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4590 | |
| 4591 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4592 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4593 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4594 | break; |
| 4595 | } |
| 4596 | |
| 4597 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4598 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4599 | break; |
| 4600 | } |
| 4601 | |
| 4602 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4603 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4604 | break; |
| 4605 | } |
| 4606 | |
| 4607 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4608 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4609 | break; |
| 4610 | } |
| 4611 | |
| 4612 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4613 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4614 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4615 | |
| 4616 | case Primitive::kPrimNot: { |
| 4617 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4618 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4619 | Location temp_loc = locations->GetTemp(0); |
| 4620 | // Note that a potential implicit null check is handled in this |
| 4621 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4622 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4623 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4624 | if (is_volatile) { |
| 4625 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4626 | } |
| 4627 | } else { |
| 4628 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4629 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4630 | if (is_volatile) { |
| 4631 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4632 | } |
| 4633 | // If read barriers are enabled, emit read barriers other than |
| 4634 | // Baker's using a slow path (and also unpoison the loaded |
| 4635 | // reference, if heap poisoning is enabled). |
| 4636 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4637 | } |
| 4638 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | if (is_volatile) { |
| 4643 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4644 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4645 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4647 | __ psrlq(temp, Immediate(32)); |
| 4648 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4649 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4650 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4651 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4652 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4653 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4654 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4655 | break; |
| 4656 | } |
| 4657 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4658 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4660 | break; |
| 4661 | } |
| 4662 | |
| 4663 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4664 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4665 | break; |
| 4666 | } |
| 4667 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4668 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4669 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4670 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4671 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4673 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4674 | // Potential implicit null checks, in the case of reference or |
| 4675 | // long fields, are handled in the previous switch statement. |
| 4676 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4677 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4678 | } |
| 4679 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4680 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4681 | if (field_type == Primitive::kPrimNot) { |
| 4682 | // Memory barriers, in the case of references, are also handled |
| 4683 | // in the previous switch statement. |
| 4684 | } else { |
| 4685 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4686 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4687 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4691 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4692 | |
| 4693 | LocationSummary* locations = |
| 4694 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4695 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4696 | bool is_volatile = field_info.IsVolatile(); |
| 4697 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4698 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4699 | || (field_type == Primitive::kPrimByte); |
| 4700 | |
| 4701 | // The register allocator does not support multiple |
| 4702 | // inputs that die at entry with one in a specific register. |
| 4703 | if (is_byte_type) { |
| 4704 | // Ensure the value is in a byte register. |
| 4705 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4706 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4707 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4708 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4709 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4710 | } else { |
| 4711 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4712 | } |
| 4713 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4714 | // 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] | 4715 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4716 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4717 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4718 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4719 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4720 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4721 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4722 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4723 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4724 | } else { |
| 4725 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4726 | |
| 4727 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4728 | // Temporary registers for the write barrier. |
| 4729 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4730 | // Ensure the card is in a byte register. |
| 4731 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4732 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | |
| 4736 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4737 | const FieldInfo& field_info, |
| 4738 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4739 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4740 | |
| 4741 | LocationSummary* locations = instruction->GetLocations(); |
| 4742 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4743 | Location value = locations->InAt(1); |
| 4744 | bool is_volatile = field_info.IsVolatile(); |
| 4745 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4746 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4747 | bool needs_write_barrier = |
| 4748 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4749 | |
| 4750 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4751 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4752 | } |
| 4753 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4754 | bool maybe_record_implicit_null_check_done = false; |
| 4755 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4756 | switch (field_type) { |
| 4757 | case Primitive::kPrimBoolean: |
| 4758 | case Primitive::kPrimByte: { |
| 4759 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4760 | break; |
| 4761 | } |
| 4762 | |
| 4763 | case Primitive::kPrimShort: |
| 4764 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4765 | if (value.IsConstant()) { |
| 4766 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4767 | __ movw(Address(base, offset), Immediate(v)); |
| 4768 | } else { |
| 4769 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4770 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | |
| 4774 | case Primitive::kPrimInt: |
| 4775 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4776 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4777 | // Note that in the case where `value` is a null reference, |
| 4778 | // we do not enter this block, as the reference does not |
| 4779 | // need poisoning. |
| 4780 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4781 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4782 | __ movl(temp, value.AsRegister<Register>()); |
| 4783 | __ PoisonHeapReference(temp); |
| 4784 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4785 | } else if (value.IsConstant()) { |
| 4786 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4787 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4788 | } else { |
| 4789 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4790 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4791 | break; |
| 4792 | } |
| 4793 | |
| 4794 | case Primitive::kPrimLong: { |
| 4795 | if (is_volatile) { |
| 4796 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4797 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4798 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4799 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4800 | __ punpckldq(temp1, temp2); |
| 4801 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4802 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4803 | } else if (value.IsConstant()) { |
| 4804 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4805 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4806 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4807 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4808 | } else { |
| 4809 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4810 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4811 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4812 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4813 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4814 | break; |
| 4815 | } |
| 4816 | |
| 4817 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4818 | if (value.IsConstant()) { |
| 4819 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4820 | __ movl(Address(base, offset), Immediate(v)); |
| 4821 | } else { |
| 4822 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4823 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4824 | break; |
| 4825 | } |
| 4826 | |
| 4827 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4828 | if (value.IsConstant()) { |
| 4829 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4830 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4831 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4832 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4833 | maybe_record_implicit_null_check_done = true; |
| 4834 | } else { |
| 4835 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4836 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4837 | break; |
| 4838 | } |
| 4839 | |
| 4840 | case Primitive::kPrimVoid: |
| 4841 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4842 | UNREACHABLE(); |
| 4843 | } |
| 4844 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4845 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4846 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4847 | } |
| 4848 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4849 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4850 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4851 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4852 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4853 | } |
| 4854 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4855 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4856 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4857 | } |
| 4858 | } |
| 4859 | |
| 4860 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4861 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4862 | } |
| 4863 | |
| 4864 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4865 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4866 | } |
| 4867 | |
| 4868 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4869 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4870 | } |
| 4871 | |
| 4872 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4873 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4877 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4878 | } |
| 4879 | |
| 4880 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4881 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4885 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4886 | } |
| 4887 | |
| 4888 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4889 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4890 | } |
| 4891 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4892 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4893 | HUnresolvedInstanceFieldGet* instruction) { |
| 4894 | FieldAccessCallingConventionX86 calling_convention; |
| 4895 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4896 | instruction, instruction->GetFieldType(), calling_convention); |
| 4897 | } |
| 4898 | |
| 4899 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4900 | HUnresolvedInstanceFieldGet* instruction) { |
| 4901 | FieldAccessCallingConventionX86 calling_convention; |
| 4902 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4903 | instruction->GetFieldType(), |
| 4904 | instruction->GetFieldIndex(), |
| 4905 | instruction->GetDexPc(), |
| 4906 | calling_convention); |
| 4907 | } |
| 4908 | |
| 4909 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4910 | HUnresolvedInstanceFieldSet* instruction) { |
| 4911 | FieldAccessCallingConventionX86 calling_convention; |
| 4912 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4913 | instruction, instruction->GetFieldType(), calling_convention); |
| 4914 | } |
| 4915 | |
| 4916 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4917 | HUnresolvedInstanceFieldSet* instruction) { |
| 4918 | FieldAccessCallingConventionX86 calling_convention; |
| 4919 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4920 | instruction->GetFieldType(), |
| 4921 | instruction->GetFieldIndex(), |
| 4922 | instruction->GetDexPc(), |
| 4923 | calling_convention); |
| 4924 | } |
| 4925 | |
| 4926 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4927 | HUnresolvedStaticFieldGet* instruction) { |
| 4928 | FieldAccessCallingConventionX86 calling_convention; |
| 4929 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4930 | instruction, instruction->GetFieldType(), calling_convention); |
| 4931 | } |
| 4932 | |
| 4933 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4934 | HUnresolvedStaticFieldGet* instruction) { |
| 4935 | FieldAccessCallingConventionX86 calling_convention; |
| 4936 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4937 | instruction->GetFieldType(), |
| 4938 | instruction->GetFieldIndex(), |
| 4939 | instruction->GetDexPc(), |
| 4940 | calling_convention); |
| 4941 | } |
| 4942 | |
| 4943 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4944 | HUnresolvedStaticFieldSet* instruction) { |
| 4945 | FieldAccessCallingConventionX86 calling_convention; |
| 4946 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4947 | instruction, instruction->GetFieldType(), calling_convention); |
| 4948 | } |
| 4949 | |
| 4950 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4951 | HUnresolvedStaticFieldSet* instruction) { |
| 4952 | FieldAccessCallingConventionX86 calling_convention; |
| 4953 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4954 | instruction->GetFieldType(), |
| 4955 | instruction->GetFieldIndex(), |
| 4956 | instruction->GetDexPc(), |
| 4957 | calling_convention); |
| 4958 | } |
| 4959 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4960 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4961 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4962 | ? LocationSummary::kCallOnSlowPath |
| 4963 | : LocationSummary::kNoCall; |
| 4964 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4965 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4966 | ? Location::RequiresRegister() |
| 4967 | : Location::Any(); |
| 4968 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4969 | if (instruction->HasUses()) { |
| 4970 | locations->SetOut(Location::SameAsFirstInput()); |
| 4971 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4972 | } |
| 4973 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4974 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4975 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4976 | return; |
| 4977 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4978 | LocationSummary* locations = instruction->GetLocations(); |
| 4979 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4980 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4981 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4982 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4983 | } |
| 4984 | |
| 4985 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4986 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4987 | codegen_->AddSlowPath(slow_path); |
| 4988 | |
| 4989 | LocationSummary* locations = instruction->GetLocations(); |
| 4990 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4991 | |
| 4992 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4993 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4994 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4995 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4996 | } else { |
| 4997 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4998 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4999 | __ jmp(slow_path->GetEntryLabel()); |
| 5000 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5001 | } |
| 5002 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5003 | } |
| 5004 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5005 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5006 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5007 | GenerateImplicitNullCheck(instruction); |
| 5008 | } else { |
| 5009 | GenerateExplicitNullCheck(instruction); |
| 5010 | } |
| 5011 | } |
| 5012 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5013 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5014 | bool object_array_get_with_read_barrier = |
| 5015 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5016 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5017 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5018 | object_array_get_with_read_barrier ? |
| 5019 | LocationSummary::kCallOnSlowPath : |
| 5020 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5021 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5022 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5023 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5024 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5025 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5026 | // The output overlaps in case of long: we don't want the low move |
| 5027 | // to overwrite the array's location. Likewise, in the case of an |
| 5028 | // object array get with read barriers enabled, we do not want the |
| 5029 | // move to overwrite the array's location, as we need it to emit |
| 5030 | // the read barrier. |
| 5031 | locations->SetOut( |
| 5032 | Location::RequiresRegister(), |
| 5033 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5034 | Location::kOutputOverlap : |
| 5035 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5036 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5037 | // We need a temporary register for the read barrier marking slow |
| 5038 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5039 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5040 | locations->AddTemp(Location::RequiresRegister()); |
| 5041 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5045 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5046 | Location obj_loc = locations->InAt(0); |
| 5047 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5048 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5049 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5050 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5051 | Primitive::Type type = instruction->GetType(); |
| 5052 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5053 | case Primitive::kPrimBoolean: { |
| 5054 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5055 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5056 | if (index.IsConstant()) { |
| 5057 | __ movzxb(out, Address(obj, |
| 5058 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5059 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5060 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5061 | } |
| 5062 | break; |
| 5063 | } |
| 5064 | |
| 5065 | case Primitive::kPrimByte: { |
| 5066 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5067 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | if (index.IsConstant()) { |
| 5069 | __ movsxb(out, Address(obj, |
| 5070 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5071 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5072 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5073 | } |
| 5074 | break; |
| 5075 | } |
| 5076 | |
| 5077 | case Primitive::kPrimShort: { |
| 5078 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5079 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5080 | if (index.IsConstant()) { |
| 5081 | __ movsxw(out, Address(obj, |
| 5082 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5083 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5084 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5085 | } |
| 5086 | break; |
| 5087 | } |
| 5088 | |
| 5089 | case Primitive::kPrimChar: { |
| 5090 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5091 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | if (index.IsConstant()) { |
| 5093 | __ movzxw(out, Address(obj, |
| 5094 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5095 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5096 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5097 | } |
| 5098 | break; |
| 5099 | } |
| 5100 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5101 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5102 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5103 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | if (index.IsConstant()) { |
| 5105 | __ movl(out, Address(obj, |
| 5106 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5107 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5108 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5109 | } |
| 5110 | break; |
| 5111 | } |
| 5112 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5113 | case Primitive::kPrimNot: { |
| 5114 | static_assert( |
| 5115 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5116 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5117 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5118 | // /* HeapReference<Object> */ out = |
| 5119 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5120 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5121 | Location temp = locations->GetTemp(0); |
| 5122 | // Note that a potential implicit null check is handled in this |
| 5123 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5124 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5125 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5126 | } else { |
| 5127 | Register out = out_loc.AsRegister<Register>(); |
| 5128 | if (index.IsConstant()) { |
| 5129 | uint32_t offset = |
| 5130 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5131 | __ movl(out, Address(obj, offset)); |
| 5132 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5133 | // If read barriers are enabled, emit read barriers other than |
| 5134 | // Baker's using a slow path (and also unpoison the loaded |
| 5135 | // reference, if heap poisoning is enabled). |
| 5136 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5137 | } else { |
| 5138 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5139 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5140 | // If read barriers are enabled, emit read barriers other than |
| 5141 | // Baker's using a slow path (and also unpoison the loaded |
| 5142 | // reference, if heap poisoning is enabled). |
| 5143 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5144 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5145 | } |
| 5146 | } |
| 5147 | break; |
| 5148 | } |
| 5149 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5150 | case Primitive::kPrimLong: { |
| 5151 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5152 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | if (index.IsConstant()) { |
| 5154 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5155 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5156 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5157 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5158 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5159 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5160 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5161 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5162 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5163 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5164 | } |
| 5165 | break; |
| 5166 | } |
| 5167 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5168 | case Primitive::kPrimFloat: { |
| 5169 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5170 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5171 | if (index.IsConstant()) { |
| 5172 | __ movss(out, Address(obj, |
| 5173 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5174 | } else { |
| 5175 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5176 | } |
| 5177 | break; |
| 5178 | } |
| 5179 | |
| 5180 | case Primitive::kPrimDouble: { |
| 5181 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5182 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5183 | if (index.IsConstant()) { |
| 5184 | __ movsd(out, Address(obj, |
| 5185 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5186 | } else { |
| 5187 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5188 | } |
| 5189 | break; |
| 5190 | } |
| 5191 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5192 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5193 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5194 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5195 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5196 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5197 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5198 | // Potential implicit null checks, in the case of reference or |
| 5199 | // long arrays, are handled in the previous switch statement. |
| 5200 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5201 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5202 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5206 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5207 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5208 | bool needs_write_barrier = |
| 5209 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5210 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5211 | bool object_array_set_with_read_barrier = |
| 5212 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5213 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5214 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5215 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5216 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5217 | LocationSummary::kCallOnSlowPath : |
| 5218 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5219 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5220 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5221 | || (value_type == Primitive::kPrimByte); |
| 5222 | // We need the inputs to be different than the output in case of long operation. |
| 5223 | // In case of a byte operation, the register allocator does not support multiple |
| 5224 | // inputs that die at entry with one in a specific register. |
| 5225 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5226 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5227 | if (is_byte_type) { |
| 5228 | // Ensure the value is in a byte register. |
| 5229 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5230 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5231 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5232 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5233 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5234 | } |
| 5235 | if (needs_write_barrier) { |
| 5236 | // Temporary registers for the write barrier. |
| 5237 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5238 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5239 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5240 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5244 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5245 | Location array_loc = locations->InAt(0); |
| 5246 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5248 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5249 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5250 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5251 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5252 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5253 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5254 | bool needs_write_barrier = |
| 5255 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | |
| 5257 | switch (value_type) { |
| 5258 | case Primitive::kPrimBoolean: |
| 5259 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5260 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5261 | Address address = index.IsConstant() |
| 5262 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5263 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5264 | if (value.IsRegister()) { |
| 5265 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5266 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5267 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5268 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5269 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5270 | break; |
| 5271 | } |
| 5272 | |
| 5273 | case Primitive::kPrimShort: |
| 5274 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5275 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5276 | Address address = index.IsConstant() |
| 5277 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5278 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5279 | if (value.IsRegister()) { |
| 5280 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5281 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5282 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5283 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5284 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5285 | break; |
| 5286 | } |
| 5287 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5288 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5289 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5290 | Address address = index.IsConstant() |
| 5291 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5292 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5293 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5294 | if (!value.IsRegister()) { |
| 5295 | // Just setting null. |
| 5296 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5297 | DCHECK(value.IsConstant()) << value; |
| 5298 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5299 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5300 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5301 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5302 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5303 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5304 | |
| 5305 | DCHECK(needs_write_barrier); |
| 5306 | Register register_value = value.AsRegister<Register>(); |
| 5307 | NearLabel done, not_null, do_put; |
| 5308 | SlowPathCode* slow_path = nullptr; |
| 5309 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5310 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5311 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5312 | codegen_->AddSlowPath(slow_path); |
| 5313 | if (instruction->GetValueCanBeNull()) { |
| 5314 | __ testl(register_value, register_value); |
| 5315 | __ j(kNotEqual, ¬_null); |
| 5316 | __ movl(address, Immediate(0)); |
| 5317 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5318 | __ jmp(&done); |
| 5319 | __ Bind(¬_null); |
| 5320 | } |
| 5321 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5322 | if (kEmitCompilerReadBarrier) { |
| 5323 | // When read barriers are enabled, the type checking |
| 5324 | // instrumentation requires two read barriers: |
| 5325 | // |
| 5326 | // __ movl(temp2, temp); |
| 5327 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5328 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5329 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5330 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5331 | // |
| 5332 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5333 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5334 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5335 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5336 | // |
| 5337 | // __ cmpl(temp, temp2); |
| 5338 | // |
| 5339 | // However, the second read barrier may trash `temp`, as it |
| 5340 | // is a temporary register, and as such would not be saved |
| 5341 | // along with live registers before calling the runtime (nor |
| 5342 | // restored afterwards). So in this case, we bail out and |
| 5343 | // delegate the work to the array set slow path. |
| 5344 | // |
| 5345 | // TODO: Extend the register allocator to support a new |
| 5346 | // "(locally) live temp" location so as to avoid always |
| 5347 | // going into the slow path when read barriers are enabled. |
| 5348 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5349 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5350 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5351 | __ movl(temp, Address(array, class_offset)); |
| 5352 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5353 | __ MaybeUnpoisonHeapReference(temp); |
| 5354 | |
| 5355 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5356 | __ movl(temp, Address(temp, component_offset)); |
| 5357 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5358 | // nor the object reference in `register_value->klass`, as |
| 5359 | // we are comparing two poisoned references. |
| 5360 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5361 | |
| 5362 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5363 | __ j(kEqual, &do_put); |
| 5364 | // If heap poisoning is enabled, the `temp` reference has |
| 5365 | // not been unpoisoned yet; unpoison it now. |
| 5366 | __ MaybeUnpoisonHeapReference(temp); |
| 5367 | |
| 5368 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5369 | __ movl(temp, Address(temp, super_offset)); |
| 5370 | // If heap poisoning is enabled, no need to unpoison |
| 5371 | // `temp`, as we are comparing against null below. |
| 5372 | __ testl(temp, temp); |
| 5373 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5374 | __ Bind(&do_put); |
| 5375 | } else { |
| 5376 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5377 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5378 | } |
| 5379 | } |
| 5380 | |
| 5381 | if (kPoisonHeapReferences) { |
| 5382 | __ movl(temp, register_value); |
| 5383 | __ PoisonHeapReference(temp); |
| 5384 | __ movl(address, temp); |
| 5385 | } else { |
| 5386 | __ movl(address, register_value); |
| 5387 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5388 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5389 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5390 | } |
| 5391 | |
| 5392 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5393 | codegen_->MarkGCCard( |
| 5394 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5395 | __ Bind(&done); |
| 5396 | |
| 5397 | if (slow_path != nullptr) { |
| 5398 | __ Bind(slow_path->GetExitLabel()); |
| 5399 | } |
| 5400 | |
| 5401 | break; |
| 5402 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5403 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | case Primitive::kPrimInt: { |
| 5405 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5406 | Address address = index.IsConstant() |
| 5407 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5408 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5409 | if (value.IsRegister()) { |
| 5410 | __ movl(address, value.AsRegister<Register>()); |
| 5411 | } else { |
| 5412 | DCHECK(value.IsConstant()) << value; |
| 5413 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5414 | __ movl(address, Immediate(v)); |
| 5415 | } |
| 5416 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5417 | break; |
| 5418 | } |
| 5419 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5420 | case Primitive::kPrimLong: { |
| 5421 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5422 | if (index.IsConstant()) { |
| 5423 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5424 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5425 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5427 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5428 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5429 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5430 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5431 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5432 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5433 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5434 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5436 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5437 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5438 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5439 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5440 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5441 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5442 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5443 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5444 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5445 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5446 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5447 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5448 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5449 | Immediate(High32Bits(val))); |
| 5450 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5451 | } |
| 5452 | break; |
| 5453 | } |
| 5454 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5455 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5456 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5457 | Address address = index.IsConstant() |
| 5458 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5459 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5460 | if (value.IsFpuRegister()) { |
| 5461 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5462 | } else { |
| 5463 | DCHECK(value.IsConstant()); |
| 5464 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5465 | __ movl(address, Immediate(v)); |
| 5466 | } |
| 5467 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5468 | break; |
| 5469 | } |
| 5470 | |
| 5471 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5472 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5473 | Address address = index.IsConstant() |
| 5474 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5475 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5476 | if (value.IsFpuRegister()) { |
| 5477 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5478 | } else { |
| 5479 | DCHECK(value.IsConstant()); |
| 5480 | Address address_hi = index.IsConstant() ? |
| 5481 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5482 | offset + kX86WordSize) : |
| 5483 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5484 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5485 | __ movl(address, Immediate(Low32Bits(v))); |
| 5486 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5487 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5488 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5489 | break; |
| 5490 | } |
| 5491 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5492 | case Primitive::kPrimVoid: |
| 5493 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5494 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5495 | } |
| 5496 | } |
| 5497 | |
| 5498 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5499 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5500 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5501 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5505 | LocationSummary* locations = instruction->GetLocations(); |
| 5506 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5507 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5508 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5509 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5510 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5514 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5515 | ? LocationSummary::kCallOnSlowPath |
| 5516 | : LocationSummary::kNoCall; |
| 5517 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5518 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5519 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5520 | if (instruction->HasUses()) { |
| 5521 | locations->SetOut(Location::SameAsFirstInput()); |
| 5522 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5523 | } |
| 5524 | |
| 5525 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5526 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5527 | Location index_loc = locations->InAt(0); |
| 5528 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5529 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5530 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5531 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5532 | if (length_loc.IsConstant()) { |
| 5533 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5534 | if (index_loc.IsConstant()) { |
| 5535 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5536 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5537 | if (index < 0 || index >= length) { |
| 5538 | codegen_->AddSlowPath(slow_path); |
| 5539 | __ jmp(slow_path->GetEntryLabel()); |
| 5540 | } else { |
| 5541 | // Some optimization after BCE may have generated this, and we should not |
| 5542 | // generate a bounds check if it is a valid range. |
| 5543 | } |
| 5544 | return; |
| 5545 | } |
| 5546 | |
| 5547 | // We have to reverse the jump condition because the length is the constant. |
| 5548 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5549 | __ cmpl(index_reg, Immediate(length)); |
| 5550 | codegen_->AddSlowPath(slow_path); |
| 5551 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5552 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5553 | Register length = length_loc.AsRegister<Register>(); |
| 5554 | if (index_loc.IsConstant()) { |
| 5555 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5556 | __ cmpl(length, Immediate(value)); |
| 5557 | } else { |
| 5558 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5559 | } |
| 5560 | codegen_->AddSlowPath(slow_path); |
| 5561 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5562 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5563 | } |
| 5564 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5565 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5566 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5570 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5571 | } |
| 5572 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5573 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5574 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5575 | } |
| 5576 | |
| 5577 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5578 | HBasicBlock* block = instruction->GetBlock(); |
| 5579 | if (block->GetLoopInformation() != nullptr) { |
| 5580 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5581 | // The back edge will generate the suspend check. |
| 5582 | return; |
| 5583 | } |
| 5584 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5585 | // The goto will generate the suspend check. |
| 5586 | return; |
| 5587 | } |
| 5588 | GenerateSuspendCheck(instruction, nullptr); |
| 5589 | } |
| 5590 | |
| 5591 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5592 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5593 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5594 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5595 | if (slow_path == nullptr) { |
| 5596 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5597 | instruction->SetSlowPath(slow_path); |
| 5598 | codegen_->AddSlowPath(slow_path); |
| 5599 | if (successor != nullptr) { |
| 5600 | DCHECK(successor->IsLoopHeader()); |
| 5601 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5602 | } |
| 5603 | } else { |
| 5604 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5605 | } |
| 5606 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5607 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5608 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5609 | if (successor == nullptr) { |
| 5610 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5611 | __ Bind(slow_path->GetReturnLabel()); |
| 5612 | } else { |
| 5613 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5614 | __ jmp(slow_path->GetEntryLabel()); |
| 5615 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5616 | } |
| 5617 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5618 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5619 | return codegen_->GetAssembler(); |
| 5620 | } |
| 5621 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5622 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5623 | ScratchRegisterScope ensure_scratch( |
| 5624 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5625 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5626 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5627 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5628 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5629 | } |
| 5630 | |
| 5631 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5632 | ScratchRegisterScope ensure_scratch( |
| 5633 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5634 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5635 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5636 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5637 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5638 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5639 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5643 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5644 | Location source = move->GetSource(); |
| 5645 | Location destination = move->GetDestination(); |
| 5646 | |
| 5647 | if (source.IsRegister()) { |
| 5648 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5649 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5650 | } else if (destination.IsFpuRegister()) { |
| 5651 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5652 | } else { |
| 5653 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5654 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5655 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5656 | } else if (source.IsRegisterPair()) { |
| 5657 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5658 | // Create stack space for 2 elements. |
| 5659 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5660 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5661 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5662 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5663 | // And remove the temporary stack space we allocated. |
| 5664 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5665 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5666 | if (destination.IsRegister()) { |
| 5667 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5668 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5669 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5670 | } else if (destination.IsRegisterPair()) { |
| 5671 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5672 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5673 | __ psrlq(src_reg, Immediate(32)); |
| 5674 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5675 | } else if (destination.IsStackSlot()) { |
| 5676 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5677 | } else { |
| 5678 | DCHECK(destination.IsDoubleStackSlot()); |
| 5679 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5680 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5681 | } else if (source.IsStackSlot()) { |
| 5682 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5683 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5684 | } else if (destination.IsFpuRegister()) { |
| 5685 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5686 | } else { |
| 5687 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5688 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5689 | } |
| 5690 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5691 | if (destination.IsRegisterPair()) { |
| 5692 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5693 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5694 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5695 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5696 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5697 | } else { |
| 5698 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5699 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5700 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5701 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5702 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5703 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5704 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5705 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5706 | if (value == 0) { |
| 5707 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5708 | } else { |
| 5709 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5710 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5711 | } else { |
| 5712 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5713 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5714 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5715 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5716 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5717 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5718 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5719 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5720 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5721 | if (value == 0) { |
| 5722 | // Easy handling of 0.0. |
| 5723 | __ xorps(dest, dest); |
| 5724 | } else { |
| 5725 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5726 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5727 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5728 | __ movl(temp, Immediate(value)); |
| 5729 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5730 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5731 | } else { |
| 5732 | DCHECK(destination.IsStackSlot()) << destination; |
| 5733 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5734 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5735 | } else if (constant->IsLongConstant()) { |
| 5736 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5737 | int32_t low_value = Low32Bits(value); |
| 5738 | int32_t high_value = High32Bits(value); |
| 5739 | Immediate low(low_value); |
| 5740 | Immediate high(high_value); |
| 5741 | if (destination.IsDoubleStackSlot()) { |
| 5742 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5743 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5744 | } else { |
| 5745 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5746 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5747 | } |
| 5748 | } else { |
| 5749 | DCHECK(constant->IsDoubleConstant()); |
| 5750 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5751 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5752 | int32_t low_value = Low32Bits(value); |
| 5753 | int32_t high_value = High32Bits(value); |
| 5754 | Immediate low(low_value); |
| 5755 | Immediate high(high_value); |
| 5756 | if (destination.IsFpuRegister()) { |
| 5757 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5758 | if (value == 0) { |
| 5759 | // Easy handling of 0.0. |
| 5760 | __ xorpd(dest, dest); |
| 5761 | } else { |
| 5762 | __ pushl(high); |
| 5763 | __ pushl(low); |
| 5764 | __ movsd(dest, Address(ESP, 0)); |
| 5765 | __ addl(ESP, Immediate(8)); |
| 5766 | } |
| 5767 | } else { |
| 5768 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5769 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5770 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5771 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5772 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5773 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5774 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5775 | } |
| 5776 | } |
| 5777 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5778 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5779 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5780 | ScratchRegisterScope ensure_scratch( |
| 5781 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5782 | |
| 5783 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5784 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5785 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5786 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5787 | } |
| 5788 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5789 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5790 | ScratchRegisterScope ensure_scratch( |
| 5791 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5792 | |
| 5793 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5794 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5795 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5796 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5797 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5798 | } |
| 5799 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5800 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5801 | ScratchRegisterScope ensure_scratch1( |
| 5802 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5803 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5804 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5805 | ScratchRegisterScope ensure_scratch2( |
| 5806 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5807 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5808 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5809 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5810 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5811 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5812 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5813 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5817 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5818 | Location source = move->GetSource(); |
| 5819 | Location destination = move->GetDestination(); |
| 5820 | |
| 5821 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5822 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5823 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5824 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5825 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5826 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5827 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5828 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5829 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5830 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5831 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5832 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5833 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5834 | // Use XOR Swap algorithm to avoid a temporary. |
| 5835 | DCHECK_NE(source.reg(), destination.reg()); |
| 5836 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5837 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5838 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5839 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5840 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5841 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5842 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5843 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5844 | // Take advantage of the 16 bytes in the XMM register. |
| 5845 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5846 | Address stack(ESP, destination.GetStackIndex()); |
| 5847 | // Load the double into the high doubleword. |
| 5848 | __ movhpd(reg, stack); |
| 5849 | |
| 5850 | // Store the low double into the destination. |
| 5851 | __ movsd(stack, reg); |
| 5852 | |
| 5853 | // Move the high double to the low double. |
| 5854 | __ psrldq(reg, Immediate(8)); |
| 5855 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5856 | // Take advantage of the 16 bytes in the XMM register. |
| 5857 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5858 | Address stack(ESP, source.GetStackIndex()); |
| 5859 | // Load the double into the high doubleword. |
| 5860 | __ movhpd(reg, stack); |
| 5861 | |
| 5862 | // Store the low double into the destination. |
| 5863 | __ movsd(stack, reg); |
| 5864 | |
| 5865 | // Move the high double to the low double. |
| 5866 | __ psrldq(reg, Immediate(8)); |
| 5867 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5868 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5869 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5870 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5871 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5872 | } |
| 5873 | } |
| 5874 | |
| 5875 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5876 | __ pushl(static_cast<Register>(reg)); |
| 5877 | } |
| 5878 | |
| 5879 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5880 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5881 | } |
| 5882 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5883 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5884 | InvokeRuntimeCallingConvention calling_convention; |
| 5885 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5886 | cls, |
| 5887 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5888 | Location::RegisterLocation(EAX), |
| 5889 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5893 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5894 | if (cls->NeedsAccessCheck()) { |
| 5895 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5896 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5897 | cls, |
| 5898 | cls->GetDexPc(), |
| 5899 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5900 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5901 | return; |
| 5902 | } |
| 5903 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5904 | Location out_loc = locations->Out(); |
| 5905 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5906 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5907 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5908 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5909 | DCHECK(!cls->CanCallRuntime()); |
| 5910 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5911 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5912 | GenerateGcRootFieldLoad( |
| 5913 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5914 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5915 | // /* GcRoot<mirror::Class>[] */ out = |
| 5916 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5917 | __ movl(out, Address(current_method, |
| 5918 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5919 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5920 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5921 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5922 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5923 | DCHECK(cls->CanCallRuntime()); |
| 5924 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5925 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5926 | codegen_->AddSlowPath(slow_path); |
| 5927 | |
| 5928 | if (!cls->IsInDexCache()) { |
| 5929 | __ testl(out, out); |
| 5930 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5931 | } |
| 5932 | |
| 5933 | if (cls->MustGenerateClinitCheck()) { |
| 5934 | GenerateClassInitializationCheck(slow_path, out); |
| 5935 | } else { |
| 5936 | __ Bind(slow_path->GetExitLabel()); |
| 5937 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5938 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5943 | LocationSummary* locations = |
| 5944 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5945 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5946 | if (check->HasUses()) { |
| 5947 | locations->SetOut(Location::SameAsFirstInput()); |
| 5948 | } |
| 5949 | } |
| 5950 | |
| 5951 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5952 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5953 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5954 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5955 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5956 | GenerateClassInitializationCheck(slow_path, |
| 5957 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5958 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5959 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5960 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5961 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5962 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5963 | Immediate(mirror::Class::kStatusInitialized)); |
| 5964 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5965 | __ Bind(slow_path->GetExitLabel()); |
| 5966 | // No need for memory fence, thanks to the X86 memory model. |
| 5967 | } |
| 5968 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5969 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5970 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5971 | ? LocationSummary::kCallOnSlowPath |
| 5972 | : LocationSummary::kNoCall; |
| 5973 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5974 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5975 | locations->SetOut(Location::RequiresRegister()); |
| 5976 | } |
| 5977 | |
| 5978 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5979 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5980 | Location out_loc = locations->Out(); |
| 5981 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5982 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5983 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5984 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5985 | GenerateGcRootFieldLoad( |
| 5986 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5987 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5988 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5989 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5990 | GenerateGcRootFieldLoad( |
| 5991 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5992 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5993 | if (!load->IsInDexCache()) { |
| 5994 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5995 | codegen_->AddSlowPath(slow_path); |
| 5996 | __ testl(out, out); |
| 5997 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5998 | __ Bind(slow_path->GetExitLabel()); |
| 5999 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6000 | } |
| 6001 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6002 | static Address GetExceptionTlsAddress() { |
| 6003 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6004 | } |
| 6005 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6006 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6007 | LocationSummary* locations = |
| 6008 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6009 | locations->SetOut(Location::RequiresRegister()); |
| 6010 | } |
| 6011 | |
| 6012 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6013 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6014 | } |
| 6015 | |
| 6016 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6017 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6018 | } |
| 6019 | |
| 6020 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6021 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6025 | LocationSummary* locations = |
| 6026 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6027 | InvokeRuntimeCallingConvention calling_convention; |
| 6028 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6029 | } |
| 6030 | |
| 6031 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6032 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6033 | instruction, |
| 6034 | instruction->GetDexPc(), |
| 6035 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6036 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6037 | } |
| 6038 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6039 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6040 | return kEmitCompilerReadBarrier && |
| 6041 | (kUseBakerReadBarrier || |
| 6042 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6043 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6044 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6045 | } |
| 6046 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6047 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6048 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6049 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6050 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6051 | case TypeCheckKind::kExactCheck: |
| 6052 | case TypeCheckKind::kAbstractClassCheck: |
| 6053 | case TypeCheckKind::kClassHierarchyCheck: |
| 6054 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6055 | call_kind = |
| 6056 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6057 | break; |
| 6058 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6059 | case TypeCheckKind::kUnresolvedCheck: |
| 6060 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6061 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6062 | break; |
| 6063 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6064 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6065 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6066 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6067 | locations->SetInAt(1, Location::Any()); |
| 6068 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6069 | locations->SetOut(Location::RequiresRegister()); |
| 6070 | // When read barriers are enabled, we need a temporary register for |
| 6071 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6072 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6073 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6074 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6075 | } |
| 6076 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6077 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6078 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6079 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6080 | Location obj_loc = locations->InAt(0); |
| 6081 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6082 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6083 | Location out_loc = locations->Out(); |
| 6084 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6085 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6086 | locations->GetTemp(0) : |
| 6087 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6088 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6089 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6090 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6091 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6092 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6093 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6094 | |
| 6095 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6096 | // Avoid null check if we know obj is not null. |
| 6097 | if (instruction->MustDoNullCheck()) { |
| 6098 | __ testl(obj, obj); |
| 6099 | __ j(kEqual, &zero); |
| 6100 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6101 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6102 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6103 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6104 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6105 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6106 | case TypeCheckKind::kExactCheck: { |
| 6107 | if (cls.IsRegister()) { |
| 6108 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6109 | } else { |
| 6110 | DCHECK(cls.IsStackSlot()) << cls; |
| 6111 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6112 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6113 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6114 | // Classes must be equal for the instanceof to succeed. |
| 6115 | __ j(kNotEqual, &zero); |
| 6116 | __ movl(out, Immediate(1)); |
| 6117 | __ jmp(&done); |
| 6118 | break; |
| 6119 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6120 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6121 | case TypeCheckKind::kAbstractClassCheck: { |
| 6122 | // If the class is abstract, we eagerly fetch the super class of the |
| 6123 | // object to avoid doing a comparison we know will fail. |
| 6124 | NearLabel loop; |
| 6125 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6126 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6127 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6128 | __ testl(out, out); |
| 6129 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6130 | __ j(kEqual, &done); |
| 6131 | if (cls.IsRegister()) { |
| 6132 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6133 | } else { |
| 6134 | DCHECK(cls.IsStackSlot()) << cls; |
| 6135 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6136 | } |
| 6137 | __ j(kNotEqual, &loop); |
| 6138 | __ movl(out, Immediate(1)); |
| 6139 | if (zero.IsLinked()) { |
| 6140 | __ jmp(&done); |
| 6141 | } |
| 6142 | break; |
| 6143 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6144 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6145 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6146 | // Walk over the class hierarchy to find a match. |
| 6147 | NearLabel loop, success; |
| 6148 | __ Bind(&loop); |
| 6149 | if (cls.IsRegister()) { |
| 6150 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6151 | } else { |
| 6152 | DCHECK(cls.IsStackSlot()) << cls; |
| 6153 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6154 | } |
| 6155 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6156 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6157 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ testl(out, out); |
| 6159 | __ j(kNotEqual, &loop); |
| 6160 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6161 | __ jmp(&done); |
| 6162 | __ Bind(&success); |
| 6163 | __ movl(out, Immediate(1)); |
| 6164 | if (zero.IsLinked()) { |
| 6165 | __ jmp(&done); |
| 6166 | } |
| 6167 | break; |
| 6168 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6169 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6170 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6171 | // Do an exact check. |
| 6172 | NearLabel exact_check; |
| 6173 | if (cls.IsRegister()) { |
| 6174 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6175 | } else { |
| 6176 | DCHECK(cls.IsStackSlot()) << cls; |
| 6177 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6178 | } |
| 6179 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6180 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6181 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6182 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | __ testl(out, out); |
| 6184 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6185 | __ j(kEqual, &done); |
| 6186 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6187 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6188 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6189 | __ movl(out, Immediate(1)); |
| 6190 | __ jmp(&done); |
| 6191 | break; |
| 6192 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6193 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6194 | case TypeCheckKind::kArrayCheck: { |
| 6195 | if (cls.IsRegister()) { |
| 6196 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6197 | } else { |
| 6198 | DCHECK(cls.IsStackSlot()) << cls; |
| 6199 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6200 | } |
| 6201 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6202 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6203 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6204 | codegen_->AddSlowPath(slow_path); |
| 6205 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6206 | __ movl(out, Immediate(1)); |
| 6207 | if (zero.IsLinked()) { |
| 6208 | __ jmp(&done); |
| 6209 | } |
| 6210 | break; |
| 6211 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6212 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6213 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6214 | case TypeCheckKind::kInterfaceCheck: { |
| 6215 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6216 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6217 | // cases. |
| 6218 | // |
| 6219 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6220 | // entry point without resorting to a type checking slow path |
| 6221 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6222 | // require to assign fixed registers for the inputs of this |
| 6223 | // HInstanceOf instruction (following the runtime calling |
| 6224 | // convention), which might be cluttered by the potential first |
| 6225 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6226 | // |
| 6227 | // TODO: Introduce a new runtime entry point taking the object |
| 6228 | // to test (instead of its class) as argument, and let it deal |
| 6229 | // with the read barrier issues. This will let us refactor this |
| 6230 | // case of the `switch` code as it was previously (with a direct |
| 6231 | // call to the runtime not using a type checking slow path). |
| 6232 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6233 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6234 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6235 | /* is_fatal */ false); |
| 6236 | codegen_->AddSlowPath(slow_path); |
| 6237 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6238 | if (zero.IsLinked()) { |
| 6239 | __ jmp(&done); |
| 6240 | } |
| 6241 | break; |
| 6242 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6245 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6246 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6247 | __ xorl(out, out); |
| 6248 | } |
| 6249 | |
| 6250 | if (done.IsLinked()) { |
| 6251 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6252 | } |
| 6253 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6254 | if (slow_path != nullptr) { |
| 6255 | __ Bind(slow_path->GetExitLabel()); |
| 6256 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6259 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6260 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6261 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6262 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6263 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6264 | case TypeCheckKind::kExactCheck: |
| 6265 | case TypeCheckKind::kAbstractClassCheck: |
| 6266 | case TypeCheckKind::kClassHierarchyCheck: |
| 6267 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6268 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6269 | LocationSummary::kCallOnSlowPath : |
| 6270 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6271 | break; |
| 6272 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6273 | case TypeCheckKind::kUnresolvedCheck: |
| 6274 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6275 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6276 | break; |
| 6277 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6278 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6279 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6280 | locations->SetInAt(1, Location::Any()); |
| 6281 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6282 | locations->AddTemp(Location::RequiresRegister()); |
| 6283 | // When read barriers are enabled, we need an additional temporary |
| 6284 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6285 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6286 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6287 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6291 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6292 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6293 | Location obj_loc = locations->InAt(0); |
| 6294 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6295 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6296 | Location temp_loc = locations->GetTemp(0); |
| 6297 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6298 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6299 | locations->GetTemp(1) : |
| 6300 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6301 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6302 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6303 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6304 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6305 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6306 | bool is_type_check_slow_path_fatal = |
| 6307 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6308 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6309 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6310 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6311 | !instruction->CanThrowIntoCatchBlock(); |
| 6312 | SlowPathCode* type_check_slow_path = |
| 6313 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6314 | is_type_check_slow_path_fatal); |
| 6315 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6316 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6317 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6318 | // Avoid null check if we know obj is not null. |
| 6319 | if (instruction->MustDoNullCheck()) { |
| 6320 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6321 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6322 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6324 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6325 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6326 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6327 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6328 | case TypeCheckKind::kExactCheck: |
| 6329 | case TypeCheckKind::kArrayCheck: { |
| 6330 | if (cls.IsRegister()) { |
| 6331 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6332 | } else { |
| 6333 | DCHECK(cls.IsStackSlot()) << cls; |
| 6334 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6335 | } |
| 6336 | // Jump to slow path for throwing the exception or doing a |
| 6337 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6338 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6339 | break; |
| 6340 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6341 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6342 | case TypeCheckKind::kAbstractClassCheck: { |
| 6343 | // If the class is abstract, we eagerly fetch the super class of the |
| 6344 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6345 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6346 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6347 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6348 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6349 | |
| 6350 | // If the class reference currently in `temp` is not null, jump |
| 6351 | // to the `compare_classes` label to compare it with the checked |
| 6352 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6353 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 | __ j(kNotEqual, &compare_classes); |
| 6355 | // Otherwise, jump to the slow path to throw the exception. |
| 6356 | // |
| 6357 | // But before, move back the object's class into `temp` before |
| 6358 | // going into the slow path, as it has been overwritten in the |
| 6359 | // meantime. |
| 6360 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6361 | GenerateReferenceLoadTwoRegisters( |
| 6362 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6363 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6364 | |
| 6365 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6366 | if (cls.IsRegister()) { |
| 6367 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6368 | } else { |
| 6369 | DCHECK(cls.IsStackSlot()) << cls; |
| 6370 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6371 | } |
| 6372 | __ j(kNotEqual, &loop); |
| 6373 | break; |
| 6374 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6375 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6376 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6377 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6378 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6379 | __ Bind(&loop); |
| 6380 | if (cls.IsRegister()) { |
| 6381 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6382 | } else { |
| 6383 | DCHECK(cls.IsStackSlot()) << cls; |
| 6384 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6385 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6386 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6387 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6388 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6389 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6390 | |
| 6391 | // If the class reference currently in `temp` is not null, jump |
| 6392 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6393 | __ testl(temp, temp); |
| 6394 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6395 | // Otherwise, jump to the slow path to throw the exception. |
| 6396 | // |
| 6397 | // But before, move back the object's class into `temp` before |
| 6398 | // going into the slow path, as it has been overwritten in the |
| 6399 | // meantime. |
| 6400 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6401 | GenerateReferenceLoadTwoRegisters( |
| 6402 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6403 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6404 | break; |
| 6405 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6406 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6407 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6408 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6409 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6410 | if (cls.IsRegister()) { |
| 6411 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6412 | } else { |
| 6413 | DCHECK(cls.IsStackSlot()) << cls; |
| 6414 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6415 | } |
| 6416 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6417 | |
| 6418 | // Otherwise, we need to check that the object's class is a non-primitive array. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6420 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6421 | |
| 6422 | // If the component type is not null (i.e. the object is indeed |
| 6423 | // an array), jump to label `check_non_primitive_component_type` |
| 6424 | // to further check that this component type is not a primitive |
| 6425 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6426 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6427 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6428 | // Otherwise, jump to the slow path to throw the exception. |
| 6429 | // |
| 6430 | // But before, move back the object's class into `temp` before |
| 6431 | // going into the slow path, as it has been overwritten in the |
| 6432 | // meantime. |
| 6433 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6434 | GenerateReferenceLoadTwoRegisters( |
| 6435 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6436 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6437 | |
| 6438 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6439 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6440 | __ j(kEqual, &done); |
| 6441 | // Same comment as above regarding `temp` and the slow path. |
| 6442 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6443 | GenerateReferenceLoadTwoRegisters( |
| 6444 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6445 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6446 | break; |
| 6447 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6448 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6449 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6450 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6451 | // We always go into the type check slow path for the unresolved |
| 6452 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6453 | // |
| 6454 | // We cannot directly call the CheckCast runtime entry point |
| 6455 | // without resorting to a type checking slow path here (i.e. by |
| 6456 | // calling InvokeRuntime directly), as it would require to |
| 6457 | // assign fixed registers for the inputs of this HInstanceOf |
| 6458 | // instruction (following the runtime calling convention), which |
| 6459 | // might be cluttered by the potential first read barrier |
| 6460 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6461 | // |
| 6462 | // TODO: Introduce a new runtime entry point taking the object |
| 6463 | // to test (instead of its class) as argument, and let it deal |
| 6464 | // with the read barrier issues. This will let us refactor this |
| 6465 | // case of the `switch` code as it was previously (with a direct |
| 6466 | // call to the runtime not using a type checking slow path). |
| 6467 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6468 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6469 | break; |
| 6470 | } |
| 6471 | __ Bind(&done); |
| 6472 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6473 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6474 | } |
| 6475 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6476 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6477 | LocationSummary* locations = |
| 6478 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6479 | InvokeRuntimeCallingConvention calling_convention; |
| 6480 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6481 | } |
| 6482 | |
| 6483 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6484 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6485 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6486 | instruction, |
| 6487 | instruction->GetDexPc(), |
| 6488 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6489 | if (instruction->IsEnter()) { |
| 6490 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6491 | } else { |
| 6492 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6493 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6494 | } |
| 6495 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6496 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6497 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6498 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6499 | |
| 6500 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6501 | LocationSummary* locations = |
| 6502 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6503 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6504 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6505 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6506 | locations->SetInAt(1, Location::Any()); |
| 6507 | locations->SetOut(Location::SameAsFirstInput()); |
| 6508 | } |
| 6509 | |
| 6510 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6511 | HandleBitwiseOperation(instruction); |
| 6512 | } |
| 6513 | |
| 6514 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6515 | HandleBitwiseOperation(instruction); |
| 6516 | } |
| 6517 | |
| 6518 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6519 | HandleBitwiseOperation(instruction); |
| 6520 | } |
| 6521 | |
| 6522 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6523 | LocationSummary* locations = instruction->GetLocations(); |
| 6524 | Location first = locations->InAt(0); |
| 6525 | Location second = locations->InAt(1); |
| 6526 | DCHECK(first.Equals(locations->Out())); |
| 6527 | |
| 6528 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6529 | if (second.IsRegister()) { |
| 6530 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6531 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6532 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6533 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6534 | } else { |
| 6535 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6536 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6537 | } |
| 6538 | } else if (second.IsConstant()) { |
| 6539 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6540 | __ andl(first.AsRegister<Register>(), |
| 6541 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6542 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6543 | __ orl(first.AsRegister<Register>(), |
| 6544 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6545 | } else { |
| 6546 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6547 | __ xorl(first.AsRegister<Register>(), |
| 6548 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6549 | } |
| 6550 | } else { |
| 6551 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6552 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6553 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6554 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6555 | } else { |
| 6556 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6557 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6558 | } |
| 6559 | } |
| 6560 | } else { |
| 6561 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6562 | if (second.IsRegisterPair()) { |
| 6563 | if (instruction->IsAnd()) { |
| 6564 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6565 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6566 | } else if (instruction->IsOr()) { |
| 6567 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6568 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6569 | } else { |
| 6570 | DCHECK(instruction->IsXor()); |
| 6571 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6572 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6573 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6574 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6575 | if (instruction->IsAnd()) { |
| 6576 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6577 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6578 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6579 | } else if (instruction->IsOr()) { |
| 6580 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6581 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6582 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6583 | } else { |
| 6584 | DCHECK(instruction->IsXor()); |
| 6585 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6586 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6587 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6588 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6589 | } else { |
| 6590 | DCHECK(second.IsConstant()) << second; |
| 6591 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6592 | int32_t low_value = Low32Bits(value); |
| 6593 | int32_t high_value = High32Bits(value); |
| 6594 | Immediate low(low_value); |
| 6595 | Immediate high(high_value); |
| 6596 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6597 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6598 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6599 | if (low_value == 0) { |
| 6600 | __ xorl(first_low, first_low); |
| 6601 | } else if (low_value != -1) { |
| 6602 | __ andl(first_low, low); |
| 6603 | } |
| 6604 | if (high_value == 0) { |
| 6605 | __ xorl(first_high, first_high); |
| 6606 | } else if (high_value != -1) { |
| 6607 | __ andl(first_high, high); |
| 6608 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6609 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6610 | if (low_value != 0) { |
| 6611 | __ orl(first_low, low); |
| 6612 | } |
| 6613 | if (high_value != 0) { |
| 6614 | __ orl(first_high, high); |
| 6615 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6616 | } else { |
| 6617 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6618 | if (low_value != 0) { |
| 6619 | __ xorl(first_low, low); |
| 6620 | } |
| 6621 | if (high_value != 0) { |
| 6622 | __ xorl(first_high, high); |
| 6623 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6624 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6625 | } |
| 6626 | } |
| 6627 | } |
| 6628 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6629 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6630 | Location out, |
| 6631 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6632 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6633 | Register out_reg = out.AsRegister<Register>(); |
| 6634 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6635 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6636 | if (kUseBakerReadBarrier) { |
| 6637 | // Load with fast path based Baker's read barrier. |
| 6638 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6639 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6640 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6641 | } else { |
| 6642 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6643 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6644 | // in the following move operation, as we will need it for the |
| 6645 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6646 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6647 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6648 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6649 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6650 | } |
| 6651 | } else { |
| 6652 | // Plain load with no read barrier. |
| 6653 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6654 | __ movl(out_reg, Address(out_reg, offset)); |
| 6655 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6660 | Location out, |
| 6661 | Location obj, |
| 6662 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6663 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6664 | Register out_reg = out.AsRegister<Register>(); |
| 6665 | Register obj_reg = obj.AsRegister<Register>(); |
| 6666 | if (kEmitCompilerReadBarrier) { |
| 6667 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6668 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6669 | // Load with fast path based Baker's read barrier. |
| 6670 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6671 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6672 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6673 | } else { |
| 6674 | // Load with slow path based read barrier. |
| 6675 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6676 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6677 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6678 | } |
| 6679 | } else { |
| 6680 | // Plain load with no read barrier. |
| 6681 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6682 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6683 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6688 | Location root, |
| 6689 | Register obj, |
| 6690 | uint32_t offset) { |
| 6691 | Register root_reg = root.AsRegister<Register>(); |
| 6692 | if (kEmitCompilerReadBarrier) { |
| 6693 | if (kUseBakerReadBarrier) { |
| 6694 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6695 | // Baker's read barrier are used: |
| 6696 | // |
| 6697 | // root = obj.field; |
| 6698 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6699 | // root = ReadBarrier::Mark(root) |
| 6700 | // } |
| 6701 | |
| 6702 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6703 | __ movl(root_reg, Address(obj, offset)); |
| 6704 | static_assert( |
| 6705 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6706 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6707 | "have different sizes."); |
| 6708 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6709 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6710 | "have different sizes."); |
| 6711 | |
| 6712 | // Slow path used to mark the GC root `root`. |
| 6713 | SlowPathCode* slow_path = |
| 6714 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6715 | codegen_->AddSlowPath(slow_path); |
| 6716 | |
| 6717 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6718 | Immediate(0)); |
| 6719 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6720 | __ Bind(slow_path->GetExitLabel()); |
| 6721 | } else { |
| 6722 | // GC root loaded through a slow path for read barriers other |
| 6723 | // than Baker's. |
| 6724 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6725 | __ leal(root_reg, Address(obj, offset)); |
| 6726 | // /* mirror::Object* */ root = root->Read() |
| 6727 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6728 | } |
| 6729 | } else { |
| 6730 | // Plain GC root load with no read barrier. |
| 6731 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6732 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6733 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6734 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6735 | } |
| 6736 | } |
| 6737 | |
| 6738 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6739 | Location ref, |
| 6740 | Register obj, |
| 6741 | uint32_t offset, |
| 6742 | Location temp, |
| 6743 | bool needs_null_check) { |
| 6744 | DCHECK(kEmitCompilerReadBarrier); |
| 6745 | DCHECK(kUseBakerReadBarrier); |
| 6746 | |
| 6747 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6748 | Address src(obj, offset); |
| 6749 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6750 | } |
| 6751 | |
| 6752 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6753 | Location ref, |
| 6754 | Register obj, |
| 6755 | uint32_t data_offset, |
| 6756 | Location index, |
| 6757 | Location temp, |
| 6758 | bool needs_null_check) { |
| 6759 | DCHECK(kEmitCompilerReadBarrier); |
| 6760 | DCHECK(kUseBakerReadBarrier); |
| 6761 | |
| 6762 | // /* HeapReference<Object> */ ref = |
| 6763 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6764 | Address src = index.IsConstant() ? |
| 6765 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6766 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6767 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6768 | } |
| 6769 | |
| 6770 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6771 | Location ref, |
| 6772 | Register obj, |
| 6773 | const Address& src, |
| 6774 | Location temp, |
| 6775 | bool needs_null_check) { |
| 6776 | DCHECK(kEmitCompilerReadBarrier); |
| 6777 | DCHECK(kUseBakerReadBarrier); |
| 6778 | |
| 6779 | // In slow path based read barriers, the read barrier call is |
| 6780 | // inserted after the original load. However, in fast path based |
| 6781 | // Baker's read barriers, we need to perform the load of |
| 6782 | // mirror::Object::monitor_ *before* the original reference load. |
| 6783 | // This load-load ordering is required by the read barrier. |
| 6784 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6785 | // |
| 6786 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6787 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6788 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6789 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6790 | // if (is_gray) { |
| 6791 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6792 | // } |
| 6793 | // |
| 6794 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6795 | // slightly more complex as: |
| 6796 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6797 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6798 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6799 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6800 | // - it performs additional checks that we do not do here for |
| 6801 | // performance reasons. |
| 6802 | |
| 6803 | Register ref_reg = ref.AsRegister<Register>(); |
| 6804 | Register temp_reg = temp.AsRegister<Register>(); |
| 6805 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6806 | |
| 6807 | // /* int32_t */ monitor = obj->monitor_ |
| 6808 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6809 | if (needs_null_check) { |
| 6810 | MaybeRecordImplicitNullCheck(instruction); |
| 6811 | } |
| 6812 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6813 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6814 | "art::LockWord and int32_t have different sizes."); |
| 6815 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6816 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6817 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6818 | static_assert( |
| 6819 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6820 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6821 | |
| 6822 | // Load fence to prevent load-load reordering. |
| 6823 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6824 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6825 | |
| 6826 | // The actual reference load. |
| 6827 | // /* HeapReference<Object> */ ref = *src |
| 6828 | __ movl(ref_reg, src); |
| 6829 | |
| 6830 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6831 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6832 | |
| 6833 | // Slow path used to mark the object `ref` when it is gray. |
| 6834 | SlowPathCode* slow_path = |
| 6835 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6836 | AddSlowPath(slow_path); |
| 6837 | |
| 6838 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6839 | // ref = ReadBarrier::Mark(ref); |
| 6840 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6841 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6842 | __ Bind(slow_path->GetExitLabel()); |
| 6843 | } |
| 6844 | |
| 6845 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6846 | Location out, |
| 6847 | Location ref, |
| 6848 | Location obj, |
| 6849 | uint32_t offset, |
| 6850 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6851 | DCHECK(kEmitCompilerReadBarrier); |
| 6852 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6853 | // Insert a slow path based read barrier *after* the reference load. |
| 6854 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6855 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6856 | // reference will be carried out by the runtime within the slow |
| 6857 | // path. |
| 6858 | // |
| 6859 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6860 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6861 | // not used by the artReadBarrierSlow entry point. |
| 6862 | // |
| 6863 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6864 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6865 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6866 | AddSlowPath(slow_path); |
| 6867 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6868 | __ jmp(slow_path->GetEntryLabel()); |
| 6869 | __ Bind(slow_path->GetExitLabel()); |
| 6870 | } |
| 6871 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6872 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6873 | Location out, |
| 6874 | Location ref, |
| 6875 | Location obj, |
| 6876 | uint32_t offset, |
| 6877 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6878 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6879 | // Baker's read barriers shall be handled by the fast path |
| 6880 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6881 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6882 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6883 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6884 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6885 | } else if (kPoisonHeapReferences) { |
| 6886 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6887 | } |
| 6888 | } |
| 6889 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6890 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6891 | Location out, |
| 6892 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6893 | DCHECK(kEmitCompilerReadBarrier); |
| 6894 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6895 | // Insert a slow path based read barrier *after* the GC root load. |
| 6896 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6897 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6898 | // not need to do anything special for this here. |
| 6899 | SlowPathCode* slow_path = |
| 6900 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6901 | AddSlowPath(slow_path); |
| 6902 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6903 | __ jmp(slow_path->GetEntryLabel()); |
| 6904 | __ Bind(slow_path->GetExitLabel()); |
| 6905 | } |
| 6906 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6907 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6908 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6909 | LOG(FATAL) << "Unreachable"; |
| 6910 | } |
| 6911 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6912 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6913 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6914 | LOG(FATAL) << "Unreachable"; |
| 6915 | } |
| 6916 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6917 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6918 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6919 | LocationSummary* locations = |
| 6920 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6921 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6922 | } |
| 6923 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6924 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6925 | int32_t lower_bound, |
| 6926 | uint32_t num_entries, |
| 6927 | HBasicBlock* switch_block, |
| 6928 | HBasicBlock* default_block) { |
| 6929 | // Figure out the correct compare values and jump conditions. |
| 6930 | // Handle the first compare/branch as a special case because it might |
| 6931 | // jump to the default case. |
| 6932 | DCHECK_GT(num_entries, 2u); |
| 6933 | Condition first_condition; |
| 6934 | uint32_t index; |
| 6935 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6936 | if (lower_bound != 0) { |
| 6937 | first_condition = kLess; |
| 6938 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6939 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6940 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6941 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6942 | index = 1; |
| 6943 | } else { |
| 6944 | // Handle all the compare/jumps below. |
| 6945 | first_condition = kBelow; |
| 6946 | index = 0; |
| 6947 | } |
| 6948 | |
| 6949 | // Handle the rest of the compare/jumps. |
| 6950 | for (; index + 1 < num_entries; index += 2) { |
| 6951 | int32_t compare_to_value = lower_bound + index + 1; |
| 6952 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6953 | // Jump to successors[index] if value < case_value[index]. |
| 6954 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6955 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6956 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6957 | } |
| 6958 | |
| 6959 | if (index != num_entries) { |
| 6960 | // There are an odd number of entries. Handle the last one. |
| 6961 | DCHECK_EQ(index + 1, num_entries); |
| 6962 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6963 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6964 | } |
| 6965 | |
| 6966 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6967 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6968 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6969 | } |
| 6970 | } |
| 6971 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6972 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6973 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6974 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6975 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6976 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6977 | |
| 6978 | GenPackedSwitchWithCompares(value_reg, |
| 6979 | lower_bound, |
| 6980 | num_entries, |
| 6981 | switch_instr->GetBlock(), |
| 6982 | switch_instr->GetDefaultBlock()); |
| 6983 | } |
| 6984 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6985 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6986 | LocationSummary* locations = |
| 6987 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6988 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6989 | |
| 6990 | // Constant area pointer. |
| 6991 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6992 | |
| 6993 | // And the temporary we need. |
| 6994 | locations->AddTemp(Location::RequiresRegister()); |
| 6995 | } |
| 6996 | |
| 6997 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6998 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6999 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7000 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7001 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7002 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7003 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7004 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7005 | GenPackedSwitchWithCompares(value_reg, |
| 7006 | lower_bound, |
| 7007 | num_entries, |
| 7008 | switch_instr->GetBlock(), |
| 7009 | default_block); |
| 7010 | return; |
| 7011 | } |
| 7012 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7013 | // Optimizing has a jump area. |
| 7014 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7015 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7016 | |
| 7017 | // Remove the bias, if needed. |
| 7018 | if (lower_bound != 0) { |
| 7019 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7020 | value_reg = temp_reg; |
| 7021 | } |
| 7022 | |
| 7023 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7024 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7025 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7026 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7027 | |
| 7028 | // We are in the range of the table. |
| 7029 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7030 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7031 | |
| 7032 | // Compute the actual target address by adding in constant_area. |
| 7033 | __ addl(temp_reg, constant_area); |
| 7034 | |
| 7035 | // And jump. |
| 7036 | __ jmp(temp_reg); |
| 7037 | } |
| 7038 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7039 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7040 | HX86ComputeBaseMethodAddress* insn) { |
| 7041 | LocationSummary* locations = |
| 7042 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7043 | locations->SetOut(Location::RequiresRegister()); |
| 7044 | } |
| 7045 | |
| 7046 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7047 | HX86ComputeBaseMethodAddress* insn) { |
| 7048 | LocationSummary* locations = insn->GetLocations(); |
| 7049 | Register reg = locations->Out().AsRegister<Register>(); |
| 7050 | |
| 7051 | // Generate call to next instruction. |
| 7052 | Label next_instruction; |
| 7053 | __ call(&next_instruction); |
| 7054 | __ Bind(&next_instruction); |
| 7055 | |
| 7056 | // Remember this offset for later use with constant area. |
| 7057 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7058 | |
| 7059 | // Grab the return address off the stack. |
| 7060 | __ popl(reg); |
| 7061 | } |
| 7062 | |
| 7063 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7064 | HX86LoadFromConstantTable* insn) { |
| 7065 | LocationSummary* locations = |
| 7066 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7067 | |
| 7068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7069 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7070 | |
| 7071 | // If we don't need to be materialized, we only need the inputs to be set. |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7072 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7073 | return; |
| 7074 | } |
| 7075 | |
| 7076 | switch (insn->GetType()) { |
| 7077 | case Primitive::kPrimFloat: |
| 7078 | case Primitive::kPrimDouble: |
| 7079 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7080 | break; |
| 7081 | |
| 7082 | case Primitive::kPrimInt: |
| 7083 | locations->SetOut(Location::RequiresRegister()); |
| 7084 | break; |
| 7085 | |
| 7086 | default: |
| 7087 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7092 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7093 | return; |
| 7094 | } |
| 7095 | |
| 7096 | LocationSummary* locations = insn->GetLocations(); |
| 7097 | Location out = locations->Out(); |
| 7098 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7099 | HConstant *value = insn->GetConstant(); |
| 7100 | |
| 7101 | switch (insn->GetType()) { |
| 7102 | case Primitive::kPrimFloat: |
| 7103 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7104 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7105 | break; |
| 7106 | |
| 7107 | case Primitive::kPrimDouble: |
| 7108 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7109 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7110 | break; |
| 7111 | |
| 7112 | case Primitive::kPrimInt: |
| 7113 | __ movl(out.AsRegister<Register>(), |
| 7114 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7115 | break; |
| 7116 | |
| 7117 | default: |
| 7118 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7119 | } |
| 7120 | } |
| 7121 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7122 | /** |
| 7123 | * Class to handle late fixup of offsets into constant area. |
| 7124 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7125 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7126 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7127 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7128 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7129 | |
| 7130 | protected: |
| 7131 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7132 | |
| 7133 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7134 | |
| 7135 | private: |
| 7136 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7137 | // Patch the correct offset for the instruction. The place to patch is the |
| 7138 | // last 4 bytes of the instruction. |
| 7139 | // The value to patch is the distance from the offset in the constant area |
| 7140 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7141 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7142 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7143 | |
| 7144 | // Patch in the right value. |
| 7145 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7146 | } |
| 7147 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7148 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7149 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7150 | }; |
| 7151 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7152 | /** |
| 7153 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7154 | * constant area. |
| 7155 | */ |
| 7156 | class JumpTableRIPFixup : public RIPFixup { |
| 7157 | public: |
| 7158 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7159 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7160 | |
| 7161 | void CreateJumpTable() { |
| 7162 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7163 | |
| 7164 | // Ensure that the reference to the jump table has the correct offset. |
| 7165 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7166 | SetOffset(offset_in_constant_table); |
| 7167 | |
| 7168 | // The label values in the jump table are computed relative to the |
| 7169 | // instruction addressing the constant area. |
| 7170 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7171 | |
| 7172 | // Populate the jump table with the correct values for the jump table. |
| 7173 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7174 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7175 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7176 | // The value that we want is the target offset - the position of the table. |
| 7177 | for (int32_t i = 0; i < num_entries; i++) { |
| 7178 | HBasicBlock* b = successors[i]; |
| 7179 | Label* l = codegen_->GetLabelOf(b); |
| 7180 | DCHECK(l->IsBound()); |
| 7181 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7182 | assembler->AppendInt32(offset_to_block); |
| 7183 | } |
| 7184 | } |
| 7185 | |
| 7186 | private: |
| 7187 | const HX86PackedSwitch* switch_instr_; |
| 7188 | }; |
| 7189 | |
| 7190 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7191 | // Generate the constant area if needed. |
| 7192 | X86Assembler* assembler = GetAssembler(); |
| 7193 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7194 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7195 | // byte values. |
| 7196 | assembler->Align(4, 0); |
| 7197 | constant_area_start_ = assembler->CodeSize(); |
| 7198 | |
| 7199 | // Populate any jump tables. |
| 7200 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7201 | jump_table->CreateJumpTable(); |
| 7202 | } |
| 7203 | |
| 7204 | // And now add the constant area to the generated code. |
| 7205 | assembler->AddConstantArea(); |
| 7206 | } |
| 7207 | |
| 7208 | // And finish up. |
| 7209 | CodeGenerator::Finalize(allocator); |
| 7210 | } |
| 7211 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7212 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7213 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7214 | return Address(reg, kDummy32BitOffset, fixup); |
| 7215 | } |
| 7216 | |
| 7217 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7218 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7219 | return Address(reg, kDummy32BitOffset, fixup); |
| 7220 | } |
| 7221 | |
| 7222 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7223 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7224 | return Address(reg, kDummy32BitOffset, fixup); |
| 7225 | } |
| 7226 | |
| 7227 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7228 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7229 | return Address(reg, kDummy32BitOffset, fixup); |
| 7230 | } |
| 7231 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7232 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7233 | if (value == 0) { |
| 7234 | __ xorl(dest, dest); |
| 7235 | } else { |
| 7236 | __ movl(dest, Immediate(value)); |
| 7237 | } |
| 7238 | } |
| 7239 | |
| 7240 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7241 | if (value == 0) { |
| 7242 | __ testl(dest, dest); |
| 7243 | } else { |
| 7244 | __ cmpl(dest, Immediate(value)); |
| 7245 | } |
| 7246 | } |
| 7247 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7248 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7249 | Register reg, |
| 7250 | Register value) { |
| 7251 | // Create a fixup to be used to create and address the jump table. |
| 7252 | JumpTableRIPFixup* table_fixup = |
| 7253 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7254 | |
| 7255 | // We have to populate the jump tables. |
| 7256 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7257 | |
| 7258 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7259 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7260 | } |
| 7261 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7262 | // TODO: target as memory. |
| 7263 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7264 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7265 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7266 | return; |
| 7267 | } |
| 7268 | |
| 7269 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7270 | |
| 7271 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7272 | if (target.Equals(return_loc)) { |
| 7273 | return; |
| 7274 | } |
| 7275 | |
| 7276 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7277 | // with the else branch. |
| 7278 | if (type == Primitive::kPrimLong) { |
| 7279 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7280 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7281 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7282 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7283 | } else { |
| 7284 | // Let the parallel move resolver take care of all of this. |
| 7285 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7286 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7287 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7288 | } |
| 7289 | } |
| 7290 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7291 | #undef __ |
| 7292 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7293 | } // namespace x86 |
| 7294 | } // namespace art |