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 | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1278 | } else if (right.IsRegisterPair()) { |
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); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1293 | } else { |
| 1294 | DCHECK(right.IsDoubleStackSlot()); |
| 1295 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1296 | if (if_cond == kCondNE) { |
| 1297 | __ j(X86Condition(true_high_cond), true_label); |
| 1298 | } else if (if_cond == kCondEQ) { |
| 1299 | __ j(X86Condition(false_high_cond), false_label); |
| 1300 | } else { |
| 1301 | __ j(X86Condition(true_high_cond), true_label); |
| 1302 | __ j(X86Condition(false_high_cond), false_label); |
| 1303 | } |
| 1304 | // Must be equal high, so compare the lows. |
| 1305 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1306 | } |
| 1307 | // The last comparison might be unsigned. |
| 1308 | __ j(final_condition, true_label); |
| 1309 | } |
| 1310 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1311 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1312 | Location rhs, |
| 1313 | HInstruction* insn, |
| 1314 | bool is_double) { |
| 1315 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1316 | if (is_double) { |
| 1317 | if (rhs.IsFpuRegister()) { |
| 1318 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1319 | } else if (const_area != nullptr) { |
| 1320 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1321 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1322 | codegen_->LiteralDoubleAddress( |
| 1323 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1324 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1325 | } else { |
| 1326 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1327 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1328 | } |
| 1329 | } else { |
| 1330 | if (rhs.IsFpuRegister()) { |
| 1331 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1332 | } else if (const_area != nullptr) { |
| 1333 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1334 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1335 | codegen_->LiteralFloatAddress( |
| 1336 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1337 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1338 | } else { |
| 1339 | DCHECK(rhs.IsStackSlot()); |
| 1340 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1345 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1346 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1347 | LabelType* true_target_in, |
| 1348 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1349 | // Generated branching requires both targets to be explicit. If either of the |
| 1350 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1351 | LabelType fallthrough_target; |
| 1352 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1353 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1354 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1355 | LocationSummary* locations = condition->GetLocations(); |
| 1356 | Location left = locations->InAt(0); |
| 1357 | Location right = locations->InAt(1); |
| 1358 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1360 | switch (type) { |
| 1361 | case Primitive::kPrimLong: |
| 1362 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1363 | break; |
| 1364 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1365 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1366 | GenerateFPJumps(condition, true_target, false_target); |
| 1367 | break; |
| 1368 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1369 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1370 | GenerateFPJumps(condition, true_target, false_target); |
| 1371 | break; |
| 1372 | default: |
| 1373 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1374 | } |
| 1375 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1376 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1377 | __ jmp(false_target); |
| 1378 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1379 | |
| 1380 | if (fallthrough_target.IsLinked()) { |
| 1381 | __ Bind(&fallthrough_target); |
| 1382 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1383 | } |
| 1384 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1385 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1386 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1387 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1388 | // conditions if they are materialized due to the complex branching. |
| 1389 | return cond->IsCondition() && |
| 1390 | cond->GetNext() == branch && |
| 1391 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1392 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1393 | } |
| 1394 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1395 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1396 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1397 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1398 | LabelType* true_target, |
| 1399 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1401 | |
| 1402 | if (true_target == nullptr && false_target == nullptr) { |
| 1403 | // Nothing to do. The code always falls through. |
| 1404 | return; |
| 1405 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1406 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1407 | if (cond->AsIntConstant()->IsOne()) { |
| 1408 | if (true_target != nullptr) { |
| 1409 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1410 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1412 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1413 | if (false_target != nullptr) { |
| 1414 | __ jmp(false_target); |
| 1415 | } |
| 1416 | } |
| 1417 | return; |
| 1418 | } |
| 1419 | |
| 1420 | // The following code generates these patterns: |
| 1421 | // (1) true_target == nullptr && false_target != nullptr |
| 1422 | // - opposite condition true => branch to false_target |
| 1423 | // (2) true_target != nullptr && false_target == nullptr |
| 1424 | // - condition true => branch to true_target |
| 1425 | // (3) true_target != nullptr && false_target != nullptr |
| 1426 | // - condition true => branch to true_target |
| 1427 | // - branch to false_target |
| 1428 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1429 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1430 | if (true_target == nullptr) { |
| 1431 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1432 | } else { |
| 1433 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1434 | } |
| 1435 | } else { |
| 1436 | // Materialized condition, compare against 0. |
| 1437 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1438 | if (lhs.IsRegister()) { |
| 1439 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1440 | } else { |
| 1441 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1442 | } |
| 1443 | if (true_target == nullptr) { |
| 1444 | __ j(kEqual, false_target); |
| 1445 | } else { |
| 1446 | __ j(kNotEqual, true_target); |
| 1447 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1448 | } |
| 1449 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | // Condition has not been materialized, use its inputs as the comparison and |
| 1451 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1452 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1453 | |
| 1454 | // If this is a long or FP comparison that has been folded into |
| 1455 | // the HCondition, generate the comparison directly. |
| 1456 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1457 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1458 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | Location lhs = condition->GetLocations()->InAt(0); |
| 1463 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1464 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1465 | if (rhs.IsRegister()) { |
| 1466 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1467 | } else if (rhs.IsConstant()) { |
| 1468 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1469 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1470 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1471 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1472 | } |
| 1473 | if (true_target == nullptr) { |
| 1474 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1475 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1476 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1477 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1478 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1479 | |
| 1480 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1481 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1482 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1483 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1487 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1488 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1489 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1490 | locations->SetInAt(0, Location::Any()); |
| 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1495 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1496 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1497 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1498 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1499 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1500 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1501 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1505 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1506 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1507 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1508 | locations->SetInAt(0, Location::Any()); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1513 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1514 | GenerateTestAndBranch<Label>(deoptimize, |
| 1515 | /* condition_input_index */ 0, |
| 1516 | slow_path->GetEntryLabel(), |
| 1517 | /* false_target */ nullptr); |
| 1518 | } |
| 1519 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1520 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1521 | // There are no conditional move instructions for XMMs. |
| 1522 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | // A FP condition doesn't generate the single CC that we need. |
| 1527 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1528 | HInstruction* condition = select->GetCondition(); |
| 1529 | if (condition->IsCondition()) { |
| 1530 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1531 | if (compare_type == Primitive::kPrimLong || |
| 1532 | Primitive::IsFloatingPointType(compare_type)) { |
| 1533 | return false; |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | // We can generate a CMOV for this Select. |
| 1538 | return true; |
| 1539 | } |
| 1540 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1541 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1542 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1543 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1544 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1545 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1546 | } else { |
| 1547 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1548 | if (SelectCanUseCMOV(select)) { |
| 1549 | if (select->InputAt(1)->IsConstant()) { |
| 1550 | // Cmov can't handle a constant value. |
| 1551 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1552 | } else { |
| 1553 | locations->SetInAt(1, Location::Any()); |
| 1554 | } |
| 1555 | } else { |
| 1556 | locations->SetInAt(1, Location::Any()); |
| 1557 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1558 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1559 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1560 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1561 | } |
| 1562 | locations->SetOut(Location::SameAsFirstInput()); |
| 1563 | } |
| 1564 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1565 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1566 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1567 | if (rhs.IsConstant()) { |
| 1568 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1569 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1570 | } else if (rhs.IsStackSlot()) { |
| 1571 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1572 | } else { |
| 1573 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1574 | } |
| 1575 | } |
| 1576 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1577 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1578 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1579 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1580 | if (SelectCanUseCMOV(select)) { |
| 1581 | // If both the condition and the source types are integer, we can generate |
| 1582 | // a CMOV to implement Select. |
| 1583 | |
| 1584 | HInstruction* select_condition = select->GetCondition(); |
| 1585 | Condition cond = kNotEqual; |
| 1586 | |
| 1587 | // Figure out how to test the 'condition'. |
| 1588 | if (select_condition->IsCondition()) { |
| 1589 | HCondition* condition = select_condition->AsCondition(); |
| 1590 | if (!condition->IsEmittedAtUseSite()) { |
| 1591 | // This was a previously materialized condition. |
| 1592 | // Can we use the existing condition code? |
| 1593 | if (AreEflagsSetFrom(condition, select)) { |
| 1594 | // Materialization was the previous instruction. Condition codes are right. |
| 1595 | cond = X86Condition(condition->GetCondition()); |
| 1596 | } else { |
| 1597 | // No, we have to recreate the condition code. |
| 1598 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1599 | __ testl(cond_reg, cond_reg); |
| 1600 | } |
| 1601 | } else { |
| 1602 | // We can't handle FP or long here. |
| 1603 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1604 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1605 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1606 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1607 | cond = X86Condition(condition->GetCondition()); |
| 1608 | } |
| 1609 | } else { |
| 1610 | // Must be a boolean condition, which needs to be compared to 0. |
| 1611 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1612 | __ testl(cond_reg, cond_reg); |
| 1613 | } |
| 1614 | |
| 1615 | // If the condition is true, overwrite the output, which already contains false. |
| 1616 | Location false_loc = locations->InAt(0); |
| 1617 | Location true_loc = locations->InAt(1); |
| 1618 | if (select->GetType() == Primitive::kPrimLong) { |
| 1619 | // 64 bit conditional move. |
| 1620 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1621 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1622 | if (true_loc.IsRegisterPair()) { |
| 1623 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1624 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1625 | } else { |
| 1626 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1627 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1628 | } |
| 1629 | } else { |
| 1630 | // 32 bit conditional move. |
| 1631 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1632 | if (true_loc.IsRegister()) { |
| 1633 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1634 | } else { |
| 1635 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1636 | } |
| 1637 | } |
| 1638 | } else { |
| 1639 | NearLabel false_target; |
| 1640 | GenerateTestAndBranch<NearLabel>( |
| 1641 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1642 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1643 | __ Bind(&false_target); |
| 1644 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1647 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1648 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1649 | } |
| 1650 | |
| 1651 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1652 | codegen_->MaybeRecordNativeDebugInfo(info, info->GetDexPc()); |
| 1653 | } |
| 1654 | |
| 1655 | void CodeGeneratorX86::GenerateNop() { |
| 1656 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1659 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1660 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1663 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1664 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1667 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1668 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1671 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1672 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1675 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1676 | LocationSummary* locations = |
| 1677 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1678 | switch (store->InputAt(1)->GetType()) { |
| 1679 | case Primitive::kPrimBoolean: |
| 1680 | case Primitive::kPrimByte: |
| 1681 | case Primitive::kPrimChar: |
| 1682 | case Primitive::kPrimShort: |
| 1683 | case Primitive::kPrimInt: |
| 1684 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1685 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1686 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1687 | break; |
| 1688 | |
| 1689 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1690 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1691 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1692 | break; |
| 1693 | |
| 1694 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1695 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1696 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1699 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1702 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1703 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1704 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1705 | // Handle the long/FP comparisons made in instruction simplification. |
| 1706 | switch (cond->InputAt(0)->GetType()) { |
| 1707 | case Primitive::kPrimLong: { |
| 1708 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1709 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1710 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1711 | locations->SetOut(Location::RequiresRegister()); |
| 1712 | } |
| 1713 | break; |
| 1714 | } |
| 1715 | case Primitive::kPrimFloat: |
| 1716 | case Primitive::kPrimDouble: { |
| 1717 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1718 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1719 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1720 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1721 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1722 | } else { |
| 1723 | locations->SetInAt(1, Location::Any()); |
| 1724 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1725 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1726 | locations->SetOut(Location::RequiresRegister()); |
| 1727 | } |
| 1728 | break; |
| 1729 | } |
| 1730 | default: |
| 1731 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1732 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1733 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1734 | // We need a byte register. |
| 1735 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1736 | } |
| 1737 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1738 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1741 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1742 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1743 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1744 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1745 | |
| 1746 | LocationSummary* locations = cond->GetLocations(); |
| 1747 | Location lhs = locations->InAt(0); |
| 1748 | Location rhs = locations->InAt(1); |
| 1749 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1750 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1751 | |
| 1752 | switch (cond->InputAt(0)->GetType()) { |
| 1753 | default: { |
| 1754 | // Integer case. |
| 1755 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1756 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1757 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1758 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1759 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1760 | return; |
| 1761 | } |
| 1762 | case Primitive::kPrimLong: |
| 1763 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1764 | break; |
| 1765 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1766 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1767 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1768 | break; |
| 1769 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1770 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1771 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1772 | break; |
| 1773 | } |
| 1774 | |
| 1775 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1776 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1777 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1778 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1779 | __ Bind(&false_label); |
| 1780 | __ xorl(reg, reg); |
| 1781 | __ jmp(&done_label); |
| 1782 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1783 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1784 | __ Bind(&true_label); |
| 1785 | __ movl(reg, Immediate(1)); |
| 1786 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1826 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1830 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1834 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1837 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1838 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1842 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1846 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1850 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1854 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1858 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1862 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1866 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1869 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1870 | LocationSummary* locations = |
| 1871 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1872 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1875 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1876 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1879 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1880 | LocationSummary* locations = |
| 1881 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1882 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1883 | } |
| 1884 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1885 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1886 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1887 | } |
| 1888 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1889 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1890 | LocationSummary* locations = |
| 1891 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1892 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1895 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1896 | // Will be generated at use site. |
| 1897 | } |
| 1898 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1899 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1900 | LocationSummary* locations = |
| 1901 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1902 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1903 | } |
| 1904 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1905 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1906 | // Will be generated at use site. |
| 1907 | } |
| 1908 | |
| 1909 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1910 | LocationSummary* locations = |
| 1911 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1912 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1913 | } |
| 1914 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1915 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1916 | // Will be generated at use site. |
| 1917 | } |
| 1918 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1919 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1920 | memory_barrier->SetLocations(nullptr); |
| 1921 | } |
| 1922 | |
| 1923 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1924 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1927 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1928 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1931 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1932 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1935 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1936 | LocationSummary* locations = |
| 1937 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1938 | switch (ret->InputAt(0)->GetType()) { |
| 1939 | case Primitive::kPrimBoolean: |
| 1940 | case Primitive::kPrimByte: |
| 1941 | case Primitive::kPrimChar: |
| 1942 | case Primitive::kPrimShort: |
| 1943 | case Primitive::kPrimInt: |
| 1944 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1945 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1946 | break; |
| 1947 | |
| 1948 | case Primitive::kPrimLong: |
| 1949 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1950 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1951 | break; |
| 1952 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1953 | case Primitive::kPrimFloat: |
| 1954 | case Primitive::kPrimDouble: |
| 1955 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1956 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1957 | break; |
| 1958 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1959 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1960 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1961 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1964 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1965 | if (kIsDebugBuild) { |
| 1966 | switch (ret->InputAt(0)->GetType()) { |
| 1967 | case Primitive::kPrimBoolean: |
| 1968 | case Primitive::kPrimByte: |
| 1969 | case Primitive::kPrimChar: |
| 1970 | case Primitive::kPrimShort: |
| 1971 | case Primitive::kPrimInt: |
| 1972 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1973 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1974 | break; |
| 1975 | |
| 1976 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1977 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1978 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1979 | break; |
| 1980 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1981 | case Primitive::kPrimFloat: |
| 1982 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1983 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1984 | break; |
| 1985 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1986 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1987 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1988 | } |
| 1989 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1990 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1993 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1994 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1995 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1996 | // the method_idx. |
| 1997 | HandleInvoke(invoke); |
| 1998 | } |
| 1999 | |
| 2000 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 2001 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 2002 | } |
| 2003 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2004 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2005 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2006 | // art::PrepareForRegisterAllocation. |
| 2007 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2008 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2009 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2010 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2011 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2012 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2013 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2014 | return; |
| 2015 | } |
| 2016 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2017 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2018 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2019 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2020 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2021 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2022 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2023 | } |
| 2024 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2025 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2026 | if (invoke->GetLocations()->Intrinsified()) { |
| 2027 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2028 | intrinsic.Dispatch(invoke); |
| 2029 | return true; |
| 2030 | } |
| 2031 | return false; |
| 2032 | } |
| 2033 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2034 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2035 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2036 | // art::PrepareForRegisterAllocation. |
| 2037 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2038 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2039 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2040 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2041 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2042 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2043 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2044 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2045 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2046 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2047 | } |
| 2048 | |
| 2049 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2050 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2051 | if (intrinsic.TryDispatch(invoke)) { |
| 2052 | return; |
| 2053 | } |
| 2054 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2055 | HandleInvoke(invoke); |
| 2056 | } |
| 2057 | |
| 2058 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2059 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2060 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2063 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2064 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2065 | return; |
| 2066 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2067 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2068 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2069 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2070 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2073 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2074 | // This call to HandleInvoke allocates a temporary (core) register |
| 2075 | // which is also used to transfer the hidden argument from FP to |
| 2076 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2077 | HandleInvoke(invoke); |
| 2078 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2079 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2083 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2084 | LocationSummary* locations = invoke->GetLocations(); |
| 2085 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2086 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2087 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2088 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2089 | Location receiver = locations->InAt(0); |
| 2090 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2091 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2092 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2093 | // won't be modified thereafter, before the `call` instruction. |
| 2094 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2095 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2096 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2097 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2098 | if (receiver.IsStackSlot()) { |
| 2099 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2100 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2101 | __ movl(temp, Address(temp, class_offset)); |
| 2102 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2103 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2104 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2105 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2106 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2107 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2108 | // emit a read barrier for the previous class reference load. |
| 2109 | // However this is not required in practice, as this is an |
| 2110 | // intermediate/temporary reference and because the current |
| 2111 | // concurrent copying collector keeps the from-space memory |
| 2112 | // intact/accessible until the end of the marking phase (the |
| 2113 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2114 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2115 | // temp = temp->GetImtEntryAt(method_offset); |
| 2116 | __ movl(temp, Address(temp, method_offset)); |
| 2117 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2118 | __ call(Address(temp, |
| 2119 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2120 | |
| 2121 | DCHECK(!codegen_->IsLeafMethod()); |
| 2122 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2123 | } |
| 2124 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2125 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2126 | LocationSummary* locations = |
| 2127 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2128 | switch (neg->GetResultType()) { |
| 2129 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2130 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2131 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2132 | locations->SetOut(Location::SameAsFirstInput()); |
| 2133 | break; |
| 2134 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2135 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2136 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2137 | locations->SetOut(Location::SameAsFirstInput()); |
| 2138 | locations->AddTemp(Location::RequiresRegister()); |
| 2139 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2140 | break; |
| 2141 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2142 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2143 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2144 | locations->SetOut(Location::SameAsFirstInput()); |
| 2145 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2146 | break; |
| 2147 | |
| 2148 | default: |
| 2149 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2154 | LocationSummary* locations = neg->GetLocations(); |
| 2155 | Location out = locations->Out(); |
| 2156 | Location in = locations->InAt(0); |
| 2157 | switch (neg->GetResultType()) { |
| 2158 | case Primitive::kPrimInt: |
| 2159 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2160 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2161 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2162 | break; |
| 2163 | |
| 2164 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2165 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2166 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2167 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2168 | // Negation is similar to subtraction from zero. The least |
| 2169 | // significant byte triggers a borrow when it is different from |
| 2170 | // zero; to take it into account, add 1 to the most significant |
| 2171 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2172 | // operation. |
| 2173 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2174 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2175 | break; |
| 2176 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2177 | case Primitive::kPrimFloat: { |
| 2178 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2179 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2180 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2181 | // Implement float negation with an exclusive or with value |
| 2182 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2183 | // single-precision floating-point number). |
| 2184 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2185 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2186 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2187 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2188 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2189 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2190 | case Primitive::kPrimDouble: { |
| 2191 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2192 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2193 | // Implement double negation with an exclusive or with value |
| 2194 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2195 | // a double-precision floating-point number). |
| 2196 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2197 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2198 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2199 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2200 | |
| 2201 | default: |
| 2202 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2203 | } |
| 2204 | } |
| 2205 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2206 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2207 | LocationSummary* locations = |
| 2208 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2209 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2210 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2211 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2212 | locations->SetOut(Location::SameAsFirstInput()); |
| 2213 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2214 | } |
| 2215 | |
| 2216 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2217 | LocationSummary* locations = neg->GetLocations(); |
| 2218 | Location out = locations->Out(); |
| 2219 | DCHECK(locations->InAt(0).Equals(out)); |
| 2220 | |
| 2221 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2222 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2223 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2224 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2225 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2226 | } else { |
| 2227 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2228 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2229 | } |
| 2230 | } |
| 2231 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2232 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2233 | Primitive::Type result_type = conversion->GetResultType(); |
| 2234 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2235 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2236 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2237 | // The float-to-long and double-to-long type conversions rely on a |
| 2238 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2239 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2240 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2241 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2242 | ? LocationSummary::kCall |
| 2243 | : LocationSummary::kNoCall; |
| 2244 | LocationSummary* locations = |
| 2245 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2246 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2247 | // The Java language does not allow treating boolean as an integral type but |
| 2248 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2249 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2250 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimByte: |
| 2252 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2253 | case Primitive::kPrimLong: { |
| 2254 | // Type conversion from long to byte is a result of code transformations. |
| 2255 | HInstruction* input = conversion->InputAt(0); |
| 2256 | Location input_location = input->IsConstant() |
| 2257 | ? Location::ConstantLocation(input->AsConstant()) |
| 2258 | : Location::RegisterPairLocation(EAX, EDX); |
| 2259 | locations->SetInAt(0, input_location); |
| 2260 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2261 | // the validation of the linear scan implementation |
| 2262 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2263 | break; |
| 2264 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2265 | case Primitive::kPrimBoolean: |
| 2266 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2267 | case Primitive::kPrimShort: |
| 2268 | case Primitive::kPrimInt: |
| 2269 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2270 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2271 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2272 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2273 | // the validation of the linear scan implementation |
| 2274 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2275 | break; |
| 2276 | |
| 2277 | default: |
| 2278 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2279 | << " to " << result_type; |
| 2280 | } |
| 2281 | break; |
| 2282 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimShort: |
| 2284 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2285 | case Primitive::kPrimLong: |
| 2286 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2287 | case Primitive::kPrimBoolean: |
| 2288 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2289 | case Primitive::kPrimByte: |
| 2290 | case Primitive::kPrimInt: |
| 2291 | case Primitive::kPrimChar: |
| 2292 | // Processing a Dex `int-to-short' instruction. |
| 2293 | locations->SetInAt(0, Location::Any()); |
| 2294 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2295 | break; |
| 2296 | |
| 2297 | default: |
| 2298 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2299 | << " to " << result_type; |
| 2300 | } |
| 2301 | break; |
| 2302 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2303 | case Primitive::kPrimInt: |
| 2304 | switch (input_type) { |
| 2305 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2306 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2307 | locations->SetInAt(0, Location::Any()); |
| 2308 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2309 | break; |
| 2310 | |
| 2311 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2312 | // Processing a Dex `float-to-int' instruction. |
| 2313 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2314 | locations->SetOut(Location::RequiresRegister()); |
| 2315 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2316 | break; |
| 2317 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2318 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2319 | // Processing a Dex `double-to-int' instruction. |
| 2320 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2321 | locations->SetOut(Location::RequiresRegister()); |
| 2322 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2323 | break; |
| 2324 | |
| 2325 | default: |
| 2326 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2327 | << " to " << result_type; |
| 2328 | } |
| 2329 | break; |
| 2330 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimLong: |
| 2332 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2333 | case Primitive::kPrimBoolean: |
| 2334 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2335 | case Primitive::kPrimByte: |
| 2336 | case Primitive::kPrimShort: |
| 2337 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2338 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2339 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2340 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2341 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2342 | break; |
| 2343 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2346 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2347 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2348 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2349 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2350 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2351 | // The runtime helper puts the result in EAX, EDX. |
| 2352 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2353 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2354 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2355 | |
| 2356 | default: |
| 2357 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2358 | << " to " << result_type; |
| 2359 | } |
| 2360 | break; |
| 2361 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2362 | case Primitive::kPrimChar: |
| 2363 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimLong: |
| 2365 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2366 | case Primitive::kPrimBoolean: |
| 2367 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimByte: |
| 2369 | case Primitive::kPrimShort: |
| 2370 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2371 | // Processing a Dex `int-to-char' instruction. |
| 2372 | locations->SetInAt(0, Location::Any()); |
| 2373 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2374 | break; |
| 2375 | |
| 2376 | default: |
| 2377 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2378 | << " to " << result_type; |
| 2379 | } |
| 2380 | break; |
| 2381 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2382 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2383 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2384 | case Primitive::kPrimBoolean: |
| 2385 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2386 | case Primitive::kPrimByte: |
| 2387 | case Primitive::kPrimShort: |
| 2388 | case Primitive::kPrimInt: |
| 2389 | case Primitive::kPrimChar: |
| 2390 | // Processing a Dex `int-to-float' instruction. |
| 2391 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2392 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2393 | break; |
| 2394 | |
| 2395 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2396 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2397 | locations->SetInAt(0, Location::Any()); |
| 2398 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2399 | break; |
| 2400 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2402 | // Processing a Dex `double-to-float' instruction. |
| 2403 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2404 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2405 | break; |
| 2406 | |
| 2407 | default: |
| 2408 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2409 | << " to " << result_type; |
| 2410 | }; |
| 2411 | break; |
| 2412 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2413 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2414 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2415 | case Primitive::kPrimBoolean: |
| 2416 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2417 | case Primitive::kPrimByte: |
| 2418 | case Primitive::kPrimShort: |
| 2419 | case Primitive::kPrimInt: |
| 2420 | case Primitive::kPrimChar: |
| 2421 | // Processing a Dex `int-to-double' instruction. |
| 2422 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2423 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2424 | break; |
| 2425 | |
| 2426 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2427 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2428 | locations->SetInAt(0, Location::Any()); |
| 2429 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2433 | // Processing a Dex `float-to-double' instruction. |
| 2434 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2435 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2436 | break; |
| 2437 | |
| 2438 | default: |
| 2439 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2440 | << " to " << result_type; |
| 2441 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2442 | break; |
| 2443 | |
| 2444 | default: |
| 2445 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2446 | << " to " << result_type; |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2451 | LocationSummary* locations = conversion->GetLocations(); |
| 2452 | Location out = locations->Out(); |
| 2453 | Location in = locations->InAt(0); |
| 2454 | Primitive::Type result_type = conversion->GetResultType(); |
| 2455 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2456 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2457 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimByte: |
| 2459 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimLong: |
| 2461 | // Type conversion from long to byte is a result of code transformations. |
| 2462 | if (in.IsRegisterPair()) { |
| 2463 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2464 | } else { |
| 2465 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2466 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2467 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2468 | } |
| 2469 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimBoolean: |
| 2471 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimShort: |
| 2473 | case Primitive::kPrimInt: |
| 2474 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2475 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2476 | if (in.IsRegister()) { |
| 2477 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2478 | } else { |
| 2479 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2480 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2481 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2482 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2483 | break; |
| 2484 | |
| 2485 | default: |
| 2486 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2487 | << " to " << result_type; |
| 2488 | } |
| 2489 | break; |
| 2490 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2491 | case Primitive::kPrimShort: |
| 2492 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimLong: |
| 2494 | // Type conversion from long to short is a result of code transformations. |
| 2495 | if (in.IsRegisterPair()) { |
| 2496 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2497 | } else if (in.IsDoubleStackSlot()) { |
| 2498 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2499 | } else { |
| 2500 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2501 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2502 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2503 | } |
| 2504 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2505 | case Primitive::kPrimBoolean: |
| 2506 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2507 | case Primitive::kPrimByte: |
| 2508 | case Primitive::kPrimInt: |
| 2509 | case Primitive::kPrimChar: |
| 2510 | // Processing a Dex `int-to-short' instruction. |
| 2511 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2512 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2513 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2514 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2515 | } else { |
| 2516 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2517 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2518 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2519 | } |
| 2520 | break; |
| 2521 | |
| 2522 | default: |
| 2523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2524 | << " to " << result_type; |
| 2525 | } |
| 2526 | break; |
| 2527 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimInt: |
| 2529 | switch (input_type) { |
| 2530 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2531 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2532 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2533 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2534 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2535 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2536 | } else { |
| 2537 | DCHECK(in.IsConstant()); |
| 2538 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2539 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2540 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2541 | } |
| 2542 | break; |
| 2543 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2544 | case Primitive::kPrimFloat: { |
| 2545 | // Processing a Dex `float-to-int' instruction. |
| 2546 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2547 | Register output = out.AsRegister<Register>(); |
| 2548 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2549 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2550 | |
| 2551 | __ movl(output, Immediate(kPrimIntMax)); |
| 2552 | // temp = int-to-float(output) |
| 2553 | __ cvtsi2ss(temp, output); |
| 2554 | // if input >= temp goto done |
| 2555 | __ comiss(input, temp); |
| 2556 | __ j(kAboveEqual, &done); |
| 2557 | // if input == NaN goto nan |
| 2558 | __ j(kUnordered, &nan); |
| 2559 | // output = float-to-int-truncate(input) |
| 2560 | __ cvttss2si(output, input); |
| 2561 | __ jmp(&done); |
| 2562 | __ Bind(&nan); |
| 2563 | // output = 0 |
| 2564 | __ xorl(output, output); |
| 2565 | __ Bind(&done); |
| 2566 | break; |
| 2567 | } |
| 2568 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimDouble: { |
| 2570 | // Processing a Dex `double-to-int' instruction. |
| 2571 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2572 | Register output = out.AsRegister<Register>(); |
| 2573 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2574 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2575 | |
| 2576 | __ movl(output, Immediate(kPrimIntMax)); |
| 2577 | // temp = int-to-double(output) |
| 2578 | __ cvtsi2sd(temp, output); |
| 2579 | // if input >= temp goto done |
| 2580 | __ comisd(input, temp); |
| 2581 | __ j(kAboveEqual, &done); |
| 2582 | // if input == NaN goto nan |
| 2583 | __ j(kUnordered, &nan); |
| 2584 | // output = double-to-int-truncate(input) |
| 2585 | __ cvttsd2si(output, input); |
| 2586 | __ jmp(&done); |
| 2587 | __ Bind(&nan); |
| 2588 | // output = 0 |
| 2589 | __ xorl(output, output); |
| 2590 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2591 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2592 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2593 | |
| 2594 | default: |
| 2595 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2596 | << " to " << result_type; |
| 2597 | } |
| 2598 | break; |
| 2599 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2600 | case Primitive::kPrimLong: |
| 2601 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimBoolean: |
| 2603 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimByte: |
| 2605 | case Primitive::kPrimShort: |
| 2606 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2607 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2608 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2609 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2610 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2611 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | __ cdq(); |
| 2613 | break; |
| 2614 | |
| 2615 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2616 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2617 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2618 | conversion, |
| 2619 | conversion->GetDexPc(), |
| 2620 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2621 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2622 | break; |
| 2623 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2625 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2626 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2627 | conversion, |
| 2628 | conversion->GetDexPc(), |
| 2629 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2630 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2631 | break; |
| 2632 | |
| 2633 | default: |
| 2634 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2635 | << " to " << result_type; |
| 2636 | } |
| 2637 | break; |
| 2638 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2639 | case Primitive::kPrimChar: |
| 2640 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2641 | case Primitive::kPrimLong: |
| 2642 | // Type conversion from long to short is a result of code transformations. |
| 2643 | if (in.IsRegisterPair()) { |
| 2644 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2645 | } else if (in.IsDoubleStackSlot()) { |
| 2646 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2647 | } else { |
| 2648 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2649 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2650 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2651 | } |
| 2652 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2653 | case Primitive::kPrimBoolean: |
| 2654 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimByte: |
| 2656 | case Primitive::kPrimShort: |
| 2657 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2658 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2659 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2660 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2661 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2662 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2663 | } else { |
| 2664 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2665 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2666 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2667 | } |
| 2668 | break; |
| 2669 | |
| 2670 | default: |
| 2671 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2672 | << " to " << result_type; |
| 2673 | } |
| 2674 | break; |
| 2675 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2677 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2678 | case Primitive::kPrimBoolean: |
| 2679 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimByte: |
| 2681 | case Primitive::kPrimShort: |
| 2682 | case Primitive::kPrimInt: |
| 2683 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2684 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2685 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2686 | break; |
| 2687 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2688 | case Primitive::kPrimLong: { |
| 2689 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2690 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2691 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2692 | // Create stack space for the call to |
| 2693 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2694 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2695 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2696 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2697 | __ subl(ESP, Immediate(adjustment)); |
| 2698 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2699 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2700 | // Load the value to the FP stack, using temporaries if needed. |
| 2701 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2702 | |
| 2703 | if (out.IsStackSlot()) { |
| 2704 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2705 | } else { |
| 2706 | __ fstps(Address(ESP, 0)); |
| 2707 | Location stack_temp = Location::StackSlot(0); |
| 2708 | codegen_->Move32(out, stack_temp); |
| 2709 | } |
| 2710 | |
| 2711 | // Remove the temporary stack space we allocated. |
| 2712 | if (adjustment != 0) { |
| 2713 | __ addl(ESP, Immediate(adjustment)); |
| 2714 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2715 | break; |
| 2716 | } |
| 2717 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2718 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2719 | // Processing a Dex `double-to-float' instruction. |
| 2720 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2721 | break; |
| 2722 | |
| 2723 | default: |
| 2724 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2725 | << " to " << result_type; |
| 2726 | }; |
| 2727 | break; |
| 2728 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2730 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2731 | case Primitive::kPrimBoolean: |
| 2732 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2733 | case Primitive::kPrimByte: |
| 2734 | case Primitive::kPrimShort: |
| 2735 | case Primitive::kPrimInt: |
| 2736 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2737 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2738 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2739 | break; |
| 2740 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2741 | case Primitive::kPrimLong: { |
| 2742 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2743 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2744 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2745 | // Create stack space for the call to |
| 2746 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2747 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2748 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2749 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2750 | __ subl(ESP, Immediate(adjustment)); |
| 2751 | } |
| 2752 | |
| 2753 | // Load the value to the FP stack, using temporaries if needed. |
| 2754 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2755 | |
| 2756 | if (out.IsDoubleStackSlot()) { |
| 2757 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2758 | } else { |
| 2759 | __ fstpl(Address(ESP, 0)); |
| 2760 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2761 | codegen_->Move64(out, stack_temp); |
| 2762 | } |
| 2763 | |
| 2764 | // Remove the temporary stack space we allocated. |
| 2765 | if (adjustment != 0) { |
| 2766 | __ addl(ESP, Immediate(adjustment)); |
| 2767 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2768 | break; |
| 2769 | } |
| 2770 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2771 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2772 | // Processing a Dex `float-to-double' instruction. |
| 2773 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2774 | break; |
| 2775 | |
| 2776 | default: |
| 2777 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2778 | << " to " << result_type; |
| 2779 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2780 | break; |
| 2781 | |
| 2782 | default: |
| 2783 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2784 | << " to " << result_type; |
| 2785 | } |
| 2786 | } |
| 2787 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2788 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2789 | LocationSummary* locations = |
| 2790 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2791 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2792 | case Primitive::kPrimInt: { |
| 2793 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2794 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2795 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2796 | break; |
| 2797 | } |
| 2798 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2799 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2800 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2801 | locations->SetInAt(1, Location::Any()); |
| 2802 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2803 | break; |
| 2804 | } |
| 2805 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2806 | case Primitive::kPrimFloat: |
| 2807 | case Primitive::kPrimDouble: { |
| 2808 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2809 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2810 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2811 | } else if (add->InputAt(1)->IsConstant()) { |
| 2812 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2813 | } else { |
| 2814 | locations->SetInAt(1, Location::Any()); |
| 2815 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2816 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2817 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2818 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2819 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2820 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2821 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2822 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2823 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2827 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2828 | Location first = locations->InAt(0); |
| 2829 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2830 | Location out = locations->Out(); |
| 2831 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2832 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2833 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2834 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2835 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2836 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2837 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2838 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2839 | } else { |
| 2840 | __ leal(out.AsRegister<Register>(), Address( |
| 2841 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2842 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2843 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2844 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2845 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2846 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2847 | } else { |
| 2848 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2849 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2850 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2851 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2852 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2853 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2854 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2858 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2859 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2860 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2861 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2862 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2863 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2864 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2865 | } else { |
| 2866 | DCHECK(second.IsConstant()) << second; |
| 2867 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2868 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2869 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2870 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2871 | break; |
| 2872 | } |
| 2873 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2874 | case Primitive::kPrimFloat: { |
| 2875 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2876 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2877 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2878 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2879 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2880 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2881 | codegen_->LiteralFloatAddress( |
| 2882 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2883 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2884 | } else { |
| 2885 | DCHECK(second.IsStackSlot()); |
| 2886 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2887 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2888 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | case Primitive::kPrimDouble: { |
| 2892 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2893 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2894 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2895 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2896 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2897 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2898 | codegen_->LiteralDoubleAddress( |
| 2899 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2900 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2901 | } else { |
| 2902 | DCHECK(second.IsDoubleStackSlot()); |
| 2903 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2904 | } |
| 2905 | break; |
| 2906 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2907 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2908 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2909 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2913 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2914 | LocationSummary* locations = |
| 2915 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2916 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2917 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2918 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2920 | locations->SetInAt(1, Location::Any()); |
| 2921 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2922 | break; |
| 2923 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2924 | case Primitive::kPrimFloat: |
| 2925 | case Primitive::kPrimDouble: { |
| 2926 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2927 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2928 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2929 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2930 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2931 | } else { |
| 2932 | locations->SetInAt(1, Location::Any()); |
| 2933 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2934 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2935 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2936 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2937 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2938 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2939 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2940 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2944 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2945 | Location first = locations->InAt(0); |
| 2946 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2947 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2948 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2949 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2950 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2951 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2952 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2953 | __ subl(first.AsRegister<Register>(), |
| 2954 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2955 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2956 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2957 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2958 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2962 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2963 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2964 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2965 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2966 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2967 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2968 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2969 | } else { |
| 2970 | DCHECK(second.IsConstant()) << second; |
| 2971 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2972 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2973 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2974 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2975 | break; |
| 2976 | } |
| 2977 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2978 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2979 | if (second.IsFpuRegister()) { |
| 2980 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2981 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2982 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2983 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2984 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2985 | codegen_->LiteralFloatAddress( |
| 2986 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2987 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2988 | } else { |
| 2989 | DCHECK(second.IsStackSlot()); |
| 2990 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2991 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2992 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2996 | if (second.IsFpuRegister()) { |
| 2997 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2998 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2999 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3000 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3001 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 3002 | codegen_->LiteralDoubleAddress( |
| 3003 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3004 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3005 | } else { |
| 3006 | DCHECK(second.IsDoubleStackSlot()); |
| 3007 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3008 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3009 | break; |
| 3010 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3011 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3012 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3013 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3014 | } |
| 3015 | } |
| 3016 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3017 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3018 | LocationSummary* locations = |
| 3019 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3020 | switch (mul->GetResultType()) { |
| 3021 | case Primitive::kPrimInt: |
| 3022 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3023 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3024 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3025 | // Can use 3 operand multiply. |
| 3026 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3027 | } else { |
| 3028 | locations->SetOut(Location::SameAsFirstInput()); |
| 3029 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3030 | break; |
| 3031 | case Primitive::kPrimLong: { |
| 3032 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3033 | locations->SetInAt(1, Location::Any()); |
| 3034 | locations->SetOut(Location::SameAsFirstInput()); |
| 3035 | // Needed for imul on 32bits with 64bits output. |
| 3036 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3037 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3038 | break; |
| 3039 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3040 | case Primitive::kPrimFloat: |
| 3041 | case Primitive::kPrimDouble: { |
| 3042 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3043 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3044 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3045 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3046 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3047 | } else { |
| 3048 | locations->SetInAt(1, Location::Any()); |
| 3049 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3050 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3051 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3052 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3053 | |
| 3054 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3055 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3060 | LocationSummary* locations = mul->GetLocations(); |
| 3061 | Location first = locations->InAt(0); |
| 3062 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3063 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3064 | |
| 3065 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3066 | case Primitive::kPrimInt: |
| 3067 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3068 | // problems where the output may not be the same as the first operand. |
| 3069 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3070 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3071 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3072 | } else if (second.IsRegister()) { |
| 3073 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3074 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3075 | } else { |
| 3076 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3077 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3078 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3079 | } |
| 3080 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3081 | |
| 3082 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3083 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3084 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3085 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3086 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3087 | |
| 3088 | DCHECK_EQ(EAX, eax); |
| 3089 | DCHECK_EQ(EDX, edx); |
| 3090 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3091 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3092 | // output: in1 |
| 3093 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3094 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3095 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3096 | if (second.IsConstant()) { |
| 3097 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3098 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3099 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3100 | int32_t low_value = Low32Bits(value); |
| 3101 | int32_t high_value = High32Bits(value); |
| 3102 | Immediate low(low_value); |
| 3103 | Immediate high(high_value); |
| 3104 | |
| 3105 | __ movl(eax, high); |
| 3106 | // eax <- in1.lo * in2.hi |
| 3107 | __ imull(eax, in1_lo); |
| 3108 | // in1.hi <- in1.hi * in2.lo |
| 3109 | __ imull(in1_hi, low); |
| 3110 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3111 | __ addl(in1_hi, eax); |
| 3112 | // move in2_lo to eax to prepare for double precision |
| 3113 | __ movl(eax, low); |
| 3114 | // edx:eax <- in1.lo * in2.lo |
| 3115 | __ mull(in1_lo); |
| 3116 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3117 | __ addl(in1_hi, edx); |
| 3118 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3119 | __ movl(in1_lo, eax); |
| 3120 | } else if (second.IsRegisterPair()) { |
| 3121 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3122 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3123 | |
| 3124 | __ movl(eax, in2_hi); |
| 3125 | // eax <- in1.lo * in2.hi |
| 3126 | __ imull(eax, in1_lo); |
| 3127 | // in1.hi <- in1.hi * in2.lo |
| 3128 | __ imull(in1_hi, in2_lo); |
| 3129 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3130 | __ addl(in1_hi, eax); |
| 3131 | // move in1_lo to eax to prepare for double precision |
| 3132 | __ movl(eax, in1_lo); |
| 3133 | // edx:eax <- in1.lo * in2.lo |
| 3134 | __ mull(in2_lo); |
| 3135 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3136 | __ addl(in1_hi, edx); |
| 3137 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3138 | __ movl(in1_lo, eax); |
| 3139 | } else { |
| 3140 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3141 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3142 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3143 | |
| 3144 | __ movl(eax, in2_hi); |
| 3145 | // eax <- in1.lo * in2.hi |
| 3146 | __ imull(eax, in1_lo); |
| 3147 | // in1.hi <- in1.hi * in2.lo |
| 3148 | __ imull(in1_hi, in2_lo); |
| 3149 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3150 | __ addl(in1_hi, eax); |
| 3151 | // move in1_lo to eax to prepare for double precision |
| 3152 | __ movl(eax, in1_lo); |
| 3153 | // edx:eax <- in1.lo * in2.lo |
| 3154 | __ mull(in2_lo); |
| 3155 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3156 | __ addl(in1_hi, edx); |
| 3157 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3158 | __ movl(in1_lo, eax); |
| 3159 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3160 | |
| 3161 | break; |
| 3162 | } |
| 3163 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3164 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3165 | DCHECK(first.Equals(locations->Out())); |
| 3166 | if (second.IsFpuRegister()) { |
| 3167 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3168 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3169 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3170 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3171 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3172 | codegen_->LiteralFloatAddress( |
| 3173 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3174 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3175 | } else { |
| 3176 | DCHECK(second.IsStackSlot()); |
| 3177 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3178 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3179 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3183 | DCHECK(first.Equals(locations->Out())); |
| 3184 | if (second.IsFpuRegister()) { |
| 3185 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3186 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3187 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3188 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3189 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3190 | codegen_->LiteralDoubleAddress( |
| 3191 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3192 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3193 | } else { |
| 3194 | DCHECK(second.IsDoubleStackSlot()); |
| 3195 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3196 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3197 | break; |
| 3198 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3199 | |
| 3200 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3201 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3205 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3206 | uint32_t temp_offset, |
| 3207 | uint32_t stack_adjustment, |
| 3208 | bool is_fp, |
| 3209 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3210 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3211 | DCHECK(!is_wide); |
| 3212 | if (is_fp) { |
| 3213 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3214 | } else { |
| 3215 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3216 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3217 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3218 | DCHECK(is_wide); |
| 3219 | if (is_fp) { |
| 3220 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3221 | } else { |
| 3222 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3223 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3224 | } else { |
| 3225 | // 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] | 3226 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3227 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3228 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3229 | if (is_fp) { |
| 3230 | __ flds(Address(ESP, temp_offset)); |
| 3231 | } else { |
| 3232 | __ filds(Address(ESP, temp_offset)); |
| 3233 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3234 | } else { |
| 3235 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3236 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3237 | if (is_fp) { |
| 3238 | __ fldl(Address(ESP, temp_offset)); |
| 3239 | } else { |
| 3240 | __ fildl(Address(ESP, temp_offset)); |
| 3241 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3242 | } |
| 3243 | } |
| 3244 | } |
| 3245 | |
| 3246 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3247 | Primitive::Type type = rem->GetResultType(); |
| 3248 | bool is_float = type == Primitive::kPrimFloat; |
| 3249 | size_t elem_size = Primitive::ComponentSize(type); |
| 3250 | LocationSummary* locations = rem->GetLocations(); |
| 3251 | Location first = locations->InAt(0); |
| 3252 | Location second = locations->InAt(1); |
| 3253 | Location out = locations->Out(); |
| 3254 | |
| 3255 | // Create stack space for 2 elements. |
| 3256 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3257 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3258 | |
| 3259 | // 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] | 3260 | const bool is_wide = !is_float; |
| 3261 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3262 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3263 | |
| 3264 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3265 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3266 | __ Bind(&retry); |
| 3267 | __ fprem(); |
| 3268 | |
| 3269 | // Move FP status to AX. |
| 3270 | __ fstsw(); |
| 3271 | |
| 3272 | // And see if the argument reduction is complete. This is signaled by the |
| 3273 | // C2 FPU flag bit set to 0. |
| 3274 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3275 | __ j(kNotEqual, &retry); |
| 3276 | |
| 3277 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3278 | // Store FP top of stack to real stack. |
| 3279 | if (is_float) { |
| 3280 | __ fsts(Address(ESP, 0)); |
| 3281 | } else { |
| 3282 | __ fstl(Address(ESP, 0)); |
| 3283 | } |
| 3284 | |
| 3285 | // Pop the 2 items from the FP stack. |
| 3286 | __ fucompp(); |
| 3287 | |
| 3288 | // Load the value from the stack into an XMM register. |
| 3289 | DCHECK(out.IsFpuRegister()) << out; |
| 3290 | if (is_float) { |
| 3291 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3292 | } else { |
| 3293 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3294 | } |
| 3295 | |
| 3296 | // And remove the temporary stack space we allocated. |
| 3297 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3298 | } |
| 3299 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3300 | |
| 3301 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3302 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3303 | |
| 3304 | LocationSummary* locations = instruction->GetLocations(); |
| 3305 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3306 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3307 | |
| 3308 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3309 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3310 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3311 | |
| 3312 | DCHECK(imm == 1 || imm == -1); |
| 3313 | |
| 3314 | if (instruction->IsRem()) { |
| 3315 | __ xorl(out_register, out_register); |
| 3316 | } else { |
| 3317 | __ movl(out_register, input_register); |
| 3318 | if (imm == -1) { |
| 3319 | __ negl(out_register); |
| 3320 | } |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3325 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3326 | LocationSummary* locations = instruction->GetLocations(); |
| 3327 | |
| 3328 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3329 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3330 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3331 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3332 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3333 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3334 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3335 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3336 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3337 | __ testl(input_register, input_register); |
| 3338 | __ cmovl(kGreaterEqual, num, input_register); |
| 3339 | int shift = CTZ(imm); |
| 3340 | __ sarl(num, Immediate(shift)); |
| 3341 | |
| 3342 | if (imm < 0) { |
| 3343 | __ negl(num); |
| 3344 | } |
| 3345 | |
| 3346 | __ movl(out_register, num); |
| 3347 | } |
| 3348 | |
| 3349 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3350 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3351 | |
| 3352 | LocationSummary* locations = instruction->GetLocations(); |
| 3353 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3354 | |
| 3355 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3356 | Register out = locations->Out().AsRegister<Register>(); |
| 3357 | Register num; |
| 3358 | Register edx; |
| 3359 | |
| 3360 | if (instruction->IsDiv()) { |
| 3361 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3362 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3363 | } else { |
| 3364 | edx = locations->Out().AsRegister<Register>(); |
| 3365 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3366 | } |
| 3367 | |
| 3368 | DCHECK_EQ(EAX, eax); |
| 3369 | DCHECK_EQ(EDX, edx); |
| 3370 | if (instruction->IsDiv()) { |
| 3371 | DCHECK_EQ(EAX, out); |
| 3372 | } else { |
| 3373 | DCHECK_EQ(EDX, out); |
| 3374 | } |
| 3375 | |
| 3376 | int64_t magic; |
| 3377 | int shift; |
| 3378 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3379 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3380 | NearLabel ndiv; |
| 3381 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3382 | // If numerator is 0, the result is 0, no computation needed. |
| 3383 | __ testl(eax, eax); |
| 3384 | __ j(kNotEqual, &ndiv); |
| 3385 | |
| 3386 | __ xorl(out, out); |
| 3387 | __ jmp(&end); |
| 3388 | |
| 3389 | __ Bind(&ndiv); |
| 3390 | |
| 3391 | // Save the numerator. |
| 3392 | __ movl(num, eax); |
| 3393 | |
| 3394 | // EAX = magic |
| 3395 | __ movl(eax, Immediate(magic)); |
| 3396 | |
| 3397 | // EDX:EAX = magic * numerator |
| 3398 | __ imull(num); |
| 3399 | |
| 3400 | if (imm > 0 && magic < 0) { |
| 3401 | // EDX += num |
| 3402 | __ addl(edx, num); |
| 3403 | } else if (imm < 0 && magic > 0) { |
| 3404 | __ subl(edx, num); |
| 3405 | } |
| 3406 | |
| 3407 | // Shift if needed. |
| 3408 | if (shift != 0) { |
| 3409 | __ sarl(edx, Immediate(shift)); |
| 3410 | } |
| 3411 | |
| 3412 | // EDX += 1 if EDX < 0 |
| 3413 | __ movl(eax, edx); |
| 3414 | __ shrl(edx, Immediate(31)); |
| 3415 | __ addl(edx, eax); |
| 3416 | |
| 3417 | if (instruction->IsRem()) { |
| 3418 | __ movl(eax, num); |
| 3419 | __ imull(edx, Immediate(imm)); |
| 3420 | __ subl(eax, edx); |
| 3421 | __ movl(edx, eax); |
| 3422 | } else { |
| 3423 | __ movl(eax, edx); |
| 3424 | } |
| 3425 | __ Bind(&end); |
| 3426 | } |
| 3427 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3428 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3429 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3430 | |
| 3431 | LocationSummary* locations = instruction->GetLocations(); |
| 3432 | Location out = locations->Out(); |
| 3433 | Location first = locations->InAt(0); |
| 3434 | Location second = locations->InAt(1); |
| 3435 | bool is_div = instruction->IsDiv(); |
| 3436 | |
| 3437 | switch (instruction->GetResultType()) { |
| 3438 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3439 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3440 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3441 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3442 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3443 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3444 | |
| 3445 | if (imm == 0) { |
| 3446 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3447 | } else if (imm == 1 || imm == -1) { |
| 3448 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3449 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3450 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3451 | } else { |
| 3452 | DCHECK(imm <= -2 || imm >= 2); |
| 3453 | GenerateDivRemWithAnyConstant(instruction); |
| 3454 | } |
| 3455 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3456 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3457 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 | is_div); |
| 3459 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3460 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3461 | Register second_reg = second.AsRegister<Register>(); |
| 3462 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3463 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3464 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3465 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3466 | __ cmpl(second_reg, Immediate(-1)); |
| 3467 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3468 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3469 | // edx:eax <- sign-extended of eax |
| 3470 | __ cdq(); |
| 3471 | // eax = quotient, edx = remainder |
| 3472 | __ idivl(second_reg); |
| 3473 | __ Bind(slow_path->GetExitLabel()); |
| 3474 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3475 | break; |
| 3476 | } |
| 3477 | |
| 3478 | case Primitive::kPrimLong: { |
| 3479 | InvokeRuntimeCallingConvention calling_convention; |
| 3480 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3481 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3482 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3483 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3484 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3485 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3486 | |
| 3487 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3488 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3489 | instruction, |
| 3490 | instruction->GetDexPc(), |
| 3491 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3492 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3493 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3494 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3495 | instruction, |
| 3496 | instruction->GetDexPc(), |
| 3497 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3498 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3499 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3500 | break; |
| 3501 | } |
| 3502 | |
| 3503 | default: |
| 3504 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3505 | } |
| 3506 | } |
| 3507 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3508 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3509 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3510 | ? LocationSummary::kCall |
| 3511 | : LocationSummary::kNoCall; |
| 3512 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3513 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3514 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3515 | case Primitive::kPrimInt: { |
| 3516 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3517 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3518 | locations->SetOut(Location::SameAsFirstInput()); |
| 3519 | // Intel uses edx:eax as the dividend. |
| 3520 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3521 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3522 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3523 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3524 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3525 | locations->AddTemp(Location::RequiresRegister()); |
| 3526 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3527 | break; |
| 3528 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3529 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3530 | InvokeRuntimeCallingConvention calling_convention; |
| 3531 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3532 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3533 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3534 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3535 | // Runtime helper puts the result in EAX, EDX. |
| 3536 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3537 | break; |
| 3538 | } |
| 3539 | case Primitive::kPrimFloat: |
| 3540 | case Primitive::kPrimDouble: { |
| 3541 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3542 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3543 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3544 | } else if (div->InputAt(1)->IsConstant()) { |
| 3545 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3546 | } else { |
| 3547 | locations->SetInAt(1, Location::Any()); |
| 3548 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3549 | locations->SetOut(Location::SameAsFirstInput()); |
| 3550 | break; |
| 3551 | } |
| 3552 | |
| 3553 | default: |
| 3554 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3559 | LocationSummary* locations = div->GetLocations(); |
| 3560 | Location first = locations->InAt(0); |
| 3561 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3562 | |
| 3563 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3564 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3565 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3566 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3571 | if (second.IsFpuRegister()) { |
| 3572 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3573 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3574 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3575 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3576 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3577 | codegen_->LiteralFloatAddress( |
| 3578 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3579 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3580 | } else { |
| 3581 | DCHECK(second.IsStackSlot()); |
| 3582 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3583 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3584 | break; |
| 3585 | } |
| 3586 | |
| 3587 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3588 | if (second.IsFpuRegister()) { |
| 3589 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3590 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3591 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3592 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3593 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3594 | codegen_->LiteralDoubleAddress( |
| 3595 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3596 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3597 | } else { |
| 3598 | DCHECK(second.IsDoubleStackSlot()); |
| 3599 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3600 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3601 | break; |
| 3602 | } |
| 3603 | |
| 3604 | default: |
| 3605 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3606 | } |
| 3607 | } |
| 3608 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3609 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3610 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3611 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3612 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3613 | ? LocationSummary::kCall |
| 3614 | : LocationSummary::kNoCall; |
| 3615 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3616 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3617 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3618 | case Primitive::kPrimInt: { |
| 3619 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3620 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3621 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3622 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3623 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3624 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3625 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3626 | locations->AddTemp(Location::RequiresRegister()); |
| 3627 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3628 | break; |
| 3629 | } |
| 3630 | case Primitive::kPrimLong: { |
| 3631 | InvokeRuntimeCallingConvention calling_convention; |
| 3632 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3633 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3634 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3635 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3636 | // Runtime helper puts the result in EAX, EDX. |
| 3637 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3638 | break; |
| 3639 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3640 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3641 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3642 | locations->SetInAt(0, Location::Any()); |
| 3643 | locations->SetInAt(1, Location::Any()); |
| 3644 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3645 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3646 | break; |
| 3647 | } |
| 3648 | |
| 3649 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3650 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3655 | Primitive::Type type = rem->GetResultType(); |
| 3656 | switch (type) { |
| 3657 | case Primitive::kPrimInt: |
| 3658 | case Primitive::kPrimLong: { |
| 3659 | GenerateDivRemIntegral(rem); |
| 3660 | break; |
| 3661 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3662 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3663 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3664 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3665 | break; |
| 3666 | } |
| 3667 | default: |
| 3668 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3669 | } |
| 3670 | } |
| 3671 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3672 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3673 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3674 | ? LocationSummary::kCallOnSlowPath |
| 3675 | : LocationSummary::kNoCall; |
| 3676 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3677 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3678 | case Primitive::kPrimByte: |
| 3679 | case Primitive::kPrimChar: |
| 3680 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3681 | case Primitive::kPrimInt: { |
| 3682 | locations->SetInAt(0, Location::Any()); |
| 3683 | break; |
| 3684 | } |
| 3685 | case Primitive::kPrimLong: { |
| 3686 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3687 | if (!instruction->IsConstant()) { |
| 3688 | locations->AddTemp(Location::RequiresRegister()); |
| 3689 | } |
| 3690 | break; |
| 3691 | } |
| 3692 | default: |
| 3693 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3694 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3695 | if (instruction->HasUses()) { |
| 3696 | locations->SetOut(Location::SameAsFirstInput()); |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3701 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3702 | codegen_->AddSlowPath(slow_path); |
| 3703 | |
| 3704 | LocationSummary* locations = instruction->GetLocations(); |
| 3705 | Location value = locations->InAt(0); |
| 3706 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3707 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3708 | case Primitive::kPrimByte: |
| 3709 | case Primitive::kPrimChar: |
| 3710 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3711 | case Primitive::kPrimInt: { |
| 3712 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3713 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3714 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3715 | } else if (value.IsStackSlot()) { |
| 3716 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3717 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3718 | } else { |
| 3719 | DCHECK(value.IsConstant()) << value; |
| 3720 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3721 | __ jmp(slow_path->GetEntryLabel()); |
| 3722 | } |
| 3723 | } |
| 3724 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3725 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3726 | case Primitive::kPrimLong: { |
| 3727 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3728 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3729 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3730 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3731 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3732 | } else { |
| 3733 | DCHECK(value.IsConstant()) << value; |
| 3734 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3735 | __ jmp(slow_path->GetEntryLabel()); |
| 3736 | } |
| 3737 | } |
| 3738 | break; |
| 3739 | } |
| 3740 | default: |
| 3741 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3742 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3745 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3746 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3747 | |
| 3748 | LocationSummary* locations = |
| 3749 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3750 | |
| 3751 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3752 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3753 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3754 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3755 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3756 | // The shift count needs to be in CL or a constant. |
| 3757 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3758 | locations->SetOut(Location::SameAsFirstInput()); |
| 3759 | break; |
| 3760 | } |
| 3761 | default: |
| 3762 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3767 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3768 | |
| 3769 | LocationSummary* locations = op->GetLocations(); |
| 3770 | Location first = locations->InAt(0); |
| 3771 | Location second = locations->InAt(1); |
| 3772 | DCHECK(first.Equals(locations->Out())); |
| 3773 | |
| 3774 | switch (op->GetResultType()) { |
| 3775 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3776 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3777 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3778 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3779 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3780 | DCHECK_EQ(ECX, second_reg); |
| 3781 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3782 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3783 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3784 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3785 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3786 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3787 | } |
| 3788 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3789 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3790 | if (shift == 0) { |
| 3791 | return; |
| 3792 | } |
| 3793 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3794 | if (op->IsShl()) { |
| 3795 | __ shll(first_reg, imm); |
| 3796 | } else if (op->IsShr()) { |
| 3797 | __ sarl(first_reg, imm); |
| 3798 | } else { |
| 3799 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3800 | } |
| 3801 | } |
| 3802 | break; |
| 3803 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3804 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3805 | if (second.IsRegister()) { |
| 3806 | Register second_reg = second.AsRegister<Register>(); |
| 3807 | DCHECK_EQ(ECX, second_reg); |
| 3808 | if (op->IsShl()) { |
| 3809 | GenerateShlLong(first, second_reg); |
| 3810 | } else if (op->IsShr()) { |
| 3811 | GenerateShrLong(first, second_reg); |
| 3812 | } else { |
| 3813 | GenerateUShrLong(first, second_reg); |
| 3814 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3815 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3816 | // Shift by a constant. |
| 3817 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3818 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3819 | if (shift != 0) { |
| 3820 | if (op->IsShl()) { |
| 3821 | GenerateShlLong(first, shift); |
| 3822 | } else if (op->IsShr()) { |
| 3823 | GenerateShrLong(first, shift); |
| 3824 | } else { |
| 3825 | GenerateUShrLong(first, shift); |
| 3826 | } |
| 3827 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3828 | } |
| 3829 | break; |
| 3830 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3831 | default: |
| 3832 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3833 | } |
| 3834 | } |
| 3835 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3836 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3837 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3838 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3839 | if (shift == 1) { |
| 3840 | // This is just an addition. |
| 3841 | __ addl(low, low); |
| 3842 | __ adcl(high, high); |
| 3843 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3844 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3845 | codegen_->EmitParallelMoves( |
| 3846 | loc.ToLow(), |
| 3847 | loc.ToHigh(), |
| 3848 | Primitive::kPrimInt, |
| 3849 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3850 | loc.ToLow(), |
| 3851 | Primitive::kPrimInt); |
| 3852 | } else if (shift > 32) { |
| 3853 | // Low part becomes 0. High part is low part << (shift-32). |
| 3854 | __ movl(high, low); |
| 3855 | __ shll(high, Immediate(shift - 32)); |
| 3856 | __ xorl(low, low); |
| 3857 | } else { |
| 3858 | // Between 1 and 31. |
| 3859 | __ shld(high, low, Immediate(shift)); |
| 3860 | __ shll(low, Immediate(shift)); |
| 3861 | } |
| 3862 | } |
| 3863 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3864 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3865 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3866 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3867 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3868 | __ testl(shifter, Immediate(32)); |
| 3869 | __ j(kEqual, &done); |
| 3870 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3871 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3872 | __ Bind(&done); |
| 3873 | } |
| 3874 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3875 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3876 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3877 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3878 | if (shift == 32) { |
| 3879 | // Need to copy the sign. |
| 3880 | DCHECK_NE(low, high); |
| 3881 | __ movl(low, high); |
| 3882 | __ sarl(high, Immediate(31)); |
| 3883 | } else if (shift > 32) { |
| 3884 | DCHECK_NE(low, high); |
| 3885 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3886 | __ movl(low, high); |
| 3887 | __ sarl(high, Immediate(31)); |
| 3888 | __ sarl(low, Immediate(shift - 32)); |
| 3889 | } else { |
| 3890 | // Between 1 and 31. |
| 3891 | __ shrd(low, high, Immediate(shift)); |
| 3892 | __ sarl(high, Immediate(shift)); |
| 3893 | } |
| 3894 | } |
| 3895 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3896 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3897 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3898 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3899 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3900 | __ testl(shifter, Immediate(32)); |
| 3901 | __ j(kEqual, &done); |
| 3902 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3903 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3904 | __ Bind(&done); |
| 3905 | } |
| 3906 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3907 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3908 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3909 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3910 | if (shift == 32) { |
| 3911 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3912 | codegen_->EmitParallelMoves( |
| 3913 | loc.ToHigh(), |
| 3914 | loc.ToLow(), |
| 3915 | Primitive::kPrimInt, |
| 3916 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3917 | loc.ToHigh(), |
| 3918 | Primitive::kPrimInt); |
| 3919 | } else if (shift > 32) { |
| 3920 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3921 | __ movl(low, high); |
| 3922 | __ shrl(low, Immediate(shift - 32)); |
| 3923 | __ xorl(high, high); |
| 3924 | } else { |
| 3925 | // Between 1 and 31. |
| 3926 | __ shrd(low, high, Immediate(shift)); |
| 3927 | __ shrl(high, Immediate(shift)); |
| 3928 | } |
| 3929 | } |
| 3930 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3931 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3932 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3933 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3934 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3935 | __ testl(shifter, Immediate(32)); |
| 3936 | __ j(kEqual, &done); |
| 3937 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3938 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3939 | __ Bind(&done); |
| 3940 | } |
| 3941 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3942 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3943 | LocationSummary* locations = |
| 3944 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3945 | |
| 3946 | switch (ror->GetResultType()) { |
| 3947 | case Primitive::kPrimLong: |
| 3948 | // Add the temporary needed. |
| 3949 | locations->AddTemp(Location::RequiresRegister()); |
| 3950 | FALLTHROUGH_INTENDED; |
| 3951 | case Primitive::kPrimInt: |
| 3952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3953 | // The shift count needs to be in CL (unless it is a constant). |
| 3954 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3955 | locations->SetOut(Location::SameAsFirstInput()); |
| 3956 | break; |
| 3957 | default: |
| 3958 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3959 | UNREACHABLE(); |
| 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3964 | LocationSummary* locations = ror->GetLocations(); |
| 3965 | Location first = locations->InAt(0); |
| 3966 | Location second = locations->InAt(1); |
| 3967 | |
| 3968 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3969 | Register first_reg = first.AsRegister<Register>(); |
| 3970 | if (second.IsRegister()) { |
| 3971 | Register second_reg = second.AsRegister<Register>(); |
| 3972 | __ rorl(first_reg, second_reg); |
| 3973 | } else { |
| 3974 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3975 | __ rorl(first_reg, imm); |
| 3976 | } |
| 3977 | return; |
| 3978 | } |
| 3979 | |
| 3980 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3981 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3982 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3983 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3984 | if (second.IsRegister()) { |
| 3985 | Register second_reg = second.AsRegister<Register>(); |
| 3986 | DCHECK_EQ(second_reg, ECX); |
| 3987 | __ movl(temp_reg, first_reg_hi); |
| 3988 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3989 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3990 | __ movl(temp_reg, first_reg_hi); |
| 3991 | __ testl(second_reg, Immediate(32)); |
| 3992 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3993 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3994 | } else { |
| 3995 | int32_t shift_amt = |
| 3996 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3997 | if (shift_amt == 0) { |
| 3998 | // Already fine. |
| 3999 | return; |
| 4000 | } |
| 4001 | if (shift_amt == 32) { |
| 4002 | // Just swap. |
| 4003 | __ movl(temp_reg, first_reg_lo); |
| 4004 | __ movl(first_reg_lo, first_reg_hi); |
| 4005 | __ movl(first_reg_hi, temp_reg); |
| 4006 | return; |
| 4007 | } |
| 4008 | |
| 4009 | Immediate imm(shift_amt); |
| 4010 | // Save the constents of the low value. |
| 4011 | __ movl(temp_reg, first_reg_lo); |
| 4012 | |
| 4013 | // Shift right into low, feeding bits from high. |
| 4014 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4015 | |
| 4016 | // Shift right into high, feeding bits from the original low. |
| 4017 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4018 | |
| 4019 | // Swap if needed. |
| 4020 | if (shift_amt > 32) { |
| 4021 | __ movl(temp_reg, first_reg_lo); |
| 4022 | __ movl(first_reg_lo, first_reg_hi); |
| 4023 | __ movl(first_reg_hi, temp_reg); |
| 4024 | } |
| 4025 | } |
| 4026 | } |
| 4027 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4028 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4029 | HandleShift(shl); |
| 4030 | } |
| 4031 | |
| 4032 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4033 | HandleShift(shl); |
| 4034 | } |
| 4035 | |
| 4036 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4037 | HandleShift(shr); |
| 4038 | } |
| 4039 | |
| 4040 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4041 | HandleShift(shr); |
| 4042 | } |
| 4043 | |
| 4044 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4045 | HandleShift(ushr); |
| 4046 | } |
| 4047 | |
| 4048 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4049 | HandleShift(ushr); |
| 4050 | } |
| 4051 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4052 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4053 | LocationSummary* locations = |
| 4054 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4055 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4056 | if (instruction->IsStringAlloc()) { |
| 4057 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4058 | } else { |
| 4059 | InvokeRuntimeCallingConvention calling_convention; |
| 4060 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4061 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4062 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4066 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4067 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4068 | if (instruction->IsStringAlloc()) { |
| 4069 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4070 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4071 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4072 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4073 | __ call(Address(temp, code_offset.Int32Value())); |
| 4074 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4075 | } else { |
| 4076 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4077 | instruction, |
| 4078 | instruction->GetDexPc(), |
| 4079 | nullptr); |
| 4080 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4081 | DCHECK(!codegen_->IsLeafMethod()); |
| 4082 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4083 | } |
| 4084 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4085 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4086 | LocationSummary* locations = |
| 4087 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4088 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4089 | InvokeRuntimeCallingConvention calling_convention; |
| 4090 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4091 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4092 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4096 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4097 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4098 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4099 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4100 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4101 | instruction, |
| 4102 | instruction->GetDexPc(), |
| 4103 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4104 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4105 | DCHECK(!codegen_->IsLeafMethod()); |
| 4106 | } |
| 4107 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4108 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4109 | LocationSummary* locations = |
| 4110 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4111 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4112 | if (location.IsStackSlot()) { |
| 4113 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4114 | } else if (location.IsDoubleStackSlot()) { |
| 4115 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4116 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4117 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4120 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4121 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4122 | } |
| 4123 | |
| 4124 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4125 | LocationSummary* locations = |
| 4126 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4127 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4128 | } |
| 4129 | |
| 4130 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4131 | } |
| 4132 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4133 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4134 | LocationSummary* locations = |
| 4135 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4137 | locations->SetOut(Location::RequiresRegister()); |
| 4138 | } |
| 4139 | |
| 4140 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4141 | LocationSummary* locations = instruction->GetLocations(); |
| 4142 | uint32_t method_offset = 0; |
| 4143 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4144 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4145 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4146 | } else { |
| 4147 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4148 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4149 | } |
| 4150 | __ movl(locations->Out().AsRegister<Register>(), |
| 4151 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4152 | } |
| 4153 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4154 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4155 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4156 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4157 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4158 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4159 | } |
| 4160 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4161 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4162 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4163 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4164 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4165 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4166 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4167 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4168 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4169 | break; |
| 4170 | |
| 4171 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4172 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4173 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4174 | break; |
| 4175 | |
| 4176 | default: |
| 4177 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4178 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4181 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4182 | LocationSummary* locations = |
| 4183 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4184 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4185 | locations->SetOut(Location::SameAsFirstInput()); |
| 4186 | } |
| 4187 | |
| 4188 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4189 | LocationSummary* locations = bool_not->GetLocations(); |
| 4190 | Location in = locations->InAt(0); |
| 4191 | Location out = locations->Out(); |
| 4192 | DCHECK(in.Equals(out)); |
| 4193 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4194 | } |
| 4195 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4196 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4197 | LocationSummary* locations = |
| 4198 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4199 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4200 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4201 | case Primitive::kPrimLong: { |
| 4202 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4203 | locations->SetInAt(1, Location::Any()); |
| 4204 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4205 | break; |
| 4206 | } |
| 4207 | case Primitive::kPrimFloat: |
| 4208 | case Primitive::kPrimDouble: { |
| 4209 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4210 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4211 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4212 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4213 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4214 | } else { |
| 4215 | locations->SetInAt(1, Location::Any()); |
| 4216 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4217 | locations->SetOut(Location::RequiresRegister()); |
| 4218 | break; |
| 4219 | } |
| 4220 | default: |
| 4221 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4222 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4226 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4227 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4228 | Location left = locations->InAt(0); |
| 4229 | Location right = locations->InAt(1); |
| 4230 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4231 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4232 | Condition less_cond = kLess; |
| 4233 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4234 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4235 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4236 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4237 | break; |
| 4238 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4239 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4240 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4241 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4242 | int32_t val_low = 0; |
| 4243 | int32_t val_high = 0; |
| 4244 | bool right_is_const = false; |
| 4245 | |
| 4246 | if (right.IsConstant()) { |
| 4247 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4248 | right_is_const = true; |
| 4249 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4250 | val_low = Low32Bits(val); |
| 4251 | val_high = High32Bits(val); |
| 4252 | } |
| 4253 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4254 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4255 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4256 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4257 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4258 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4259 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4260 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4261 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4262 | __ j(kLess, &less); // Signed compare. |
| 4263 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4264 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4265 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4266 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4267 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4268 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4269 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4270 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4271 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4272 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4273 | break; |
| 4274 | } |
| 4275 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4276 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4277 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4278 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4279 | break; |
| 4280 | } |
| 4281 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4282 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4283 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4284 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4285 | break; |
| 4286 | } |
| 4287 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4288 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4289 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4290 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4291 | __ movl(out, Immediate(0)); |
| 4292 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4293 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4294 | |
| 4295 | __ Bind(&greater); |
| 4296 | __ movl(out, Immediate(1)); |
| 4297 | __ jmp(&done); |
| 4298 | |
| 4299 | __ Bind(&less); |
| 4300 | __ movl(out, Immediate(-1)); |
| 4301 | |
| 4302 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4305 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4306 | LocationSummary* locations = |
| 4307 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4308 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4309 | locations->SetInAt(i, Location::Any()); |
| 4310 | } |
| 4311 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4312 | } |
| 4313 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4314 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4315 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4316 | } |
| 4317 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4318 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4319 | /* |
| 4320 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4321 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4322 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4323 | */ |
| 4324 | switch (kind) { |
| 4325 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4326 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4327 | break; |
| 4328 | } |
| 4329 | case MemBarrierKind::kAnyStore: |
| 4330 | case MemBarrierKind::kLoadAny: |
| 4331 | case MemBarrierKind::kStoreStore: { |
| 4332 | // nop |
| 4333 | break; |
| 4334 | } |
| 4335 | default: |
| 4336 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4337 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4338 | } |
| 4339 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4340 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4341 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4342 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4343 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4344 | |
| 4345 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4346 | // is incompatible with it. |
| 4347 | if (GetGraph()->HasIrreducibleLoops() && |
| 4348 | (dispatch_info.method_load_kind == |
| 4349 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4350 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4351 | } |
| 4352 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4353 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4354 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4355 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4356 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4357 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4358 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4359 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4360 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4361 | 0u |
| 4362 | }; |
| 4363 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4364 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4365 | } |
| 4366 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4367 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4368 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4369 | Register temp) { |
| 4370 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4371 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4372 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4373 | return location.AsRegister<Register>(); |
| 4374 | } |
| 4375 | // For intrinsics we allow any location, so it may be on the stack. |
| 4376 | if (!location.IsRegister()) { |
| 4377 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4378 | return temp; |
| 4379 | } |
| 4380 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4381 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4382 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4383 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4384 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4385 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4386 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4387 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4388 | __ movl(temp, Address(ESP, stack_offset)); |
| 4389 | return temp; |
| 4390 | } |
| 4391 | return location.AsRegister<Register>(); |
| 4392 | } |
| 4393 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4394 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4395 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4396 | switch (invoke->GetMethodLoadKind()) { |
| 4397 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4398 | // temp = thread->string_init_entrypoint |
| 4399 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4400 | break; |
| 4401 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4402 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4403 | break; |
| 4404 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4405 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4406 | break; |
| 4407 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4408 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4409 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4410 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4411 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4412 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4413 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4414 | temp.AsRegister<Register>()); |
| 4415 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4416 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4417 | // Add the patch entry and bind its label at the end of the instruction. |
| 4418 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4419 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4420 | break; |
| 4421 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4422 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4423 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4424 | Register method_reg; |
| 4425 | Register reg = temp.AsRegister<Register>(); |
| 4426 | if (current_method.IsRegister()) { |
| 4427 | method_reg = current_method.AsRegister<Register>(); |
| 4428 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4429 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4430 | DCHECK(!current_method.IsValid()); |
| 4431 | method_reg = reg; |
| 4432 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4433 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4434 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4435 | __ movl(reg, Address(method_reg, |
| 4436 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4437 | // temp = temp[index_in_cache] |
| 4438 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4439 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4440 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4441 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | switch (invoke->GetCodePtrLocation()) { |
| 4445 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4446 | __ call(GetFrameEntryLabel()); |
| 4447 | break; |
| 4448 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4449 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4450 | Label* label = &relative_call_patches_.back().label; |
| 4451 | __ call(label); // Bind to the patch label, override at link time. |
| 4452 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4453 | break; |
| 4454 | } |
| 4455 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4456 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4457 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4458 | LOG(FATAL) << "Unsupported"; |
| 4459 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4460 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4461 | // (callee_method + offset_of_quick_compiled_code)() |
| 4462 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4463 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4464 | kX86WordSize).Int32Value())); |
| 4465 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4469 | } |
| 4470 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4471 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4472 | Register temp = temp_in.AsRegister<Register>(); |
| 4473 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4474 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4475 | |
| 4476 | // Use the calling convention instead of the location of the receiver, as |
| 4477 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4478 | // slow path, the arguments have been moved to the right place, so here we are |
| 4479 | // guaranteed that the receiver is the first register of the calling convention. |
| 4480 | InvokeDexCallingConvention calling_convention; |
| 4481 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4482 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4483 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4484 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4485 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4486 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4487 | // emit a read barrier for the previous class reference load. |
| 4488 | // However this is not required in practice, as this is an |
| 4489 | // intermediate/temporary reference and because the current |
| 4490 | // concurrent copying collector keeps the from-space memory |
| 4491 | // intact/accessible until the end of the marking phase (the |
| 4492 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4493 | __ MaybeUnpoisonHeapReference(temp); |
| 4494 | // temp = temp->GetMethodAt(method_offset); |
| 4495 | __ movl(temp, Address(temp, method_offset)); |
| 4496 | // call temp->GetEntryPoint(); |
| 4497 | __ call(Address( |
| 4498 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4499 | } |
| 4500 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4501 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4502 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4503 | size_t size = |
| 4504 | method_patches_.size() + |
| 4505 | relative_call_patches_.size() + |
| 4506 | pc_relative_dex_cache_patches_.size(); |
| 4507 | linker_patches->reserve(size); |
| 4508 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4509 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4510 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4511 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4512 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4514 | info.target_method.dex_file, |
| 4515 | info.target_method.dex_method_index)); |
| 4516 | } |
| 4517 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4518 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4520 | info.target_method.dex_file, |
| 4521 | info.target_method.dex_method_index)); |
| 4522 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4523 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4524 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4525 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4526 | &info.target_dex_file, |
| 4527 | GetMethodAddressOffset(), |
| 4528 | info.element_offset)); |
| 4529 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4532 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4533 | Register card, |
| 4534 | Register object, |
| 4535 | Register value, |
| 4536 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4537 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4538 | if (value_can_be_null) { |
| 4539 | __ testl(value, value); |
| 4540 | __ j(kEqual, &is_null); |
| 4541 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4542 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4543 | __ movl(temp, object); |
| 4544 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4545 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4546 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4547 | if (value_can_be_null) { |
| 4548 | __ Bind(&is_null); |
| 4549 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4550 | } |
| 4551 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4552 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4553 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4554 | |
| 4555 | bool object_field_get_with_read_barrier = |
| 4556 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4557 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4558 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4559 | kEmitCompilerReadBarrier ? |
| 4560 | LocationSummary::kCallOnSlowPath : |
| 4561 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4562 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4563 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4564 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4565 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4566 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4567 | // The output overlaps in case of long: we don't want the low move |
| 4568 | // to overwrite the object's location. Likewise, in the case of |
| 4569 | // an object field get with read barriers enabled, we do not want |
| 4570 | // the move to overwrite the object's location, as we need it to emit |
| 4571 | // the read barrier. |
| 4572 | locations->SetOut( |
| 4573 | Location::RequiresRegister(), |
| 4574 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4575 | Location::kOutputOverlap : |
| 4576 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4577 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | |
| 4579 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4580 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4581 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4582 | // load the temp into the XMM and then copy the XMM into the |
| 4583 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4584 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4585 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4586 | // We need a temporary register for the read barrier marking slow |
| 4587 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4588 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4589 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4590 | } |
| 4591 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4592 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4593 | const FieldInfo& field_info) { |
| 4594 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4595 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4596 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4597 | Location base_loc = locations->InAt(0); |
| 4598 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4599 | Location out = locations->Out(); |
| 4600 | bool is_volatile = field_info.IsVolatile(); |
| 4601 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4602 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4603 | |
| 4604 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4605 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4606 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4607 | break; |
| 4608 | } |
| 4609 | |
| 4610 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4611 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4612 | break; |
| 4613 | } |
| 4614 | |
| 4615 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4616 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4617 | break; |
| 4618 | } |
| 4619 | |
| 4620 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4621 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4622 | break; |
| 4623 | } |
| 4624 | |
| 4625 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4626 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4627 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4628 | |
| 4629 | case Primitive::kPrimNot: { |
| 4630 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4631 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4632 | Location temp_loc = locations->GetTemp(0); |
| 4633 | // Note that a potential implicit null check is handled in this |
| 4634 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4635 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4636 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4637 | if (is_volatile) { |
| 4638 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4639 | } |
| 4640 | } else { |
| 4641 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4642 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4643 | if (is_volatile) { |
| 4644 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4645 | } |
| 4646 | // If read barriers are enabled, emit read barriers other than |
| 4647 | // Baker's using a slow path (and also unpoison the loaded |
| 4648 | // reference, if heap poisoning is enabled). |
| 4649 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4650 | } |
| 4651 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4655 | if (is_volatile) { |
| 4656 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4657 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4658 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4660 | __ psrlq(temp, Immediate(32)); |
| 4661 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4662 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4663 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4664 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4665 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4666 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4667 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4668 | break; |
| 4669 | } |
| 4670 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4671 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4673 | break; |
| 4674 | } |
| 4675 | |
| 4676 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4677 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4678 | break; |
| 4679 | } |
| 4680 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4681 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4682 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4683 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4684 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4685 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4686 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4687 | // Potential implicit null checks, in the case of reference or |
| 4688 | // long fields, are handled in the previous switch statement. |
| 4689 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4690 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4691 | } |
| 4692 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4693 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4694 | if (field_type == Primitive::kPrimNot) { |
| 4695 | // Memory barriers, in the case of references, are also handled |
| 4696 | // in the previous switch statement. |
| 4697 | } else { |
| 4698 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4699 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4700 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4704 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4705 | |
| 4706 | LocationSummary* locations = |
| 4707 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4708 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4709 | bool is_volatile = field_info.IsVolatile(); |
| 4710 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4711 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4712 | || (field_type == Primitive::kPrimByte); |
| 4713 | |
| 4714 | // The register allocator does not support multiple |
| 4715 | // inputs that die at entry with one in a specific register. |
| 4716 | if (is_byte_type) { |
| 4717 | // Ensure the value is in a byte register. |
| 4718 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4719 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4720 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4721 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4722 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4723 | } else { |
| 4724 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4725 | } |
| 4726 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4727 | // 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] | 4728 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4729 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4730 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4731 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4732 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4733 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4734 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4735 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4736 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4737 | } else { |
| 4738 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4739 | |
| 4740 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4741 | // Temporary registers for the write barrier. |
| 4742 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4743 | // Ensure the card is in a byte register. |
| 4744 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4745 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4746 | } |
| 4747 | } |
| 4748 | |
| 4749 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4750 | const FieldInfo& field_info, |
| 4751 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4752 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4753 | |
| 4754 | LocationSummary* locations = instruction->GetLocations(); |
| 4755 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4756 | Location value = locations->InAt(1); |
| 4757 | bool is_volatile = field_info.IsVolatile(); |
| 4758 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4759 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4760 | bool needs_write_barrier = |
| 4761 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4762 | |
| 4763 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4764 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4765 | } |
| 4766 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4767 | bool maybe_record_implicit_null_check_done = false; |
| 4768 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4769 | switch (field_type) { |
| 4770 | case Primitive::kPrimBoolean: |
| 4771 | case Primitive::kPrimByte: { |
| 4772 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4773 | break; |
| 4774 | } |
| 4775 | |
| 4776 | case Primitive::kPrimShort: |
| 4777 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4778 | if (value.IsConstant()) { |
| 4779 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4780 | __ movw(Address(base, offset), Immediate(v)); |
| 4781 | } else { |
| 4782 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4783 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4784 | break; |
| 4785 | } |
| 4786 | |
| 4787 | case Primitive::kPrimInt: |
| 4788 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4789 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4790 | // Note that in the case where `value` is a null reference, |
| 4791 | // we do not enter this block, as the reference does not |
| 4792 | // need poisoning. |
| 4793 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4794 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4795 | __ movl(temp, value.AsRegister<Register>()); |
| 4796 | __ PoisonHeapReference(temp); |
| 4797 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4798 | } else if (value.IsConstant()) { |
| 4799 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4800 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4801 | } else { |
| 4802 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4803 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4804 | break; |
| 4805 | } |
| 4806 | |
| 4807 | case Primitive::kPrimLong: { |
| 4808 | if (is_volatile) { |
| 4809 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4810 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4811 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4812 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4813 | __ punpckldq(temp1, temp2); |
| 4814 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4815 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4816 | } else if (value.IsConstant()) { |
| 4817 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4818 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4819 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4820 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4821 | } else { |
| 4822 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4823 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4824 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4825 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4826 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | } |
| 4829 | |
| 4830 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4831 | if (value.IsConstant()) { |
| 4832 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4833 | __ movl(Address(base, offset), Immediate(v)); |
| 4834 | } else { |
| 4835 | __ movss(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::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4841 | if (value.IsConstant()) { |
| 4842 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4843 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4844 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4845 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4846 | maybe_record_implicit_null_check_done = true; |
| 4847 | } else { |
| 4848 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4849 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4850 | break; |
| 4851 | } |
| 4852 | |
| 4853 | case Primitive::kPrimVoid: |
| 4854 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4855 | UNREACHABLE(); |
| 4856 | } |
| 4857 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4858 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4859 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4860 | } |
| 4861 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4862 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4863 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4864 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4865 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4868 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4869 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4870 | } |
| 4871 | } |
| 4872 | |
| 4873 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4874 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4875 | } |
| 4876 | |
| 4877 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4878 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4879 | } |
| 4880 | |
| 4881 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4882 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4883 | } |
| 4884 | |
| 4885 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4886 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4890 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4891 | } |
| 4892 | |
| 4893 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4894 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4898 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4899 | } |
| 4900 | |
| 4901 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4902 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4903 | } |
| 4904 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4905 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4906 | HUnresolvedInstanceFieldGet* instruction) { |
| 4907 | FieldAccessCallingConventionX86 calling_convention; |
| 4908 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4909 | instruction, instruction->GetFieldType(), calling_convention); |
| 4910 | } |
| 4911 | |
| 4912 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4913 | HUnresolvedInstanceFieldGet* instruction) { |
| 4914 | FieldAccessCallingConventionX86 calling_convention; |
| 4915 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4916 | instruction->GetFieldType(), |
| 4917 | instruction->GetFieldIndex(), |
| 4918 | instruction->GetDexPc(), |
| 4919 | calling_convention); |
| 4920 | } |
| 4921 | |
| 4922 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4923 | HUnresolvedInstanceFieldSet* instruction) { |
| 4924 | FieldAccessCallingConventionX86 calling_convention; |
| 4925 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4926 | instruction, instruction->GetFieldType(), calling_convention); |
| 4927 | } |
| 4928 | |
| 4929 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4930 | HUnresolvedInstanceFieldSet* instruction) { |
| 4931 | FieldAccessCallingConventionX86 calling_convention; |
| 4932 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4933 | instruction->GetFieldType(), |
| 4934 | instruction->GetFieldIndex(), |
| 4935 | instruction->GetDexPc(), |
| 4936 | calling_convention); |
| 4937 | } |
| 4938 | |
| 4939 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4940 | HUnresolvedStaticFieldGet* instruction) { |
| 4941 | FieldAccessCallingConventionX86 calling_convention; |
| 4942 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4943 | instruction, instruction->GetFieldType(), calling_convention); |
| 4944 | } |
| 4945 | |
| 4946 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4947 | HUnresolvedStaticFieldGet* instruction) { |
| 4948 | FieldAccessCallingConventionX86 calling_convention; |
| 4949 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4950 | instruction->GetFieldType(), |
| 4951 | instruction->GetFieldIndex(), |
| 4952 | instruction->GetDexPc(), |
| 4953 | calling_convention); |
| 4954 | } |
| 4955 | |
| 4956 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4957 | HUnresolvedStaticFieldSet* instruction) { |
| 4958 | FieldAccessCallingConventionX86 calling_convention; |
| 4959 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4960 | instruction, instruction->GetFieldType(), calling_convention); |
| 4961 | } |
| 4962 | |
| 4963 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4964 | HUnresolvedStaticFieldSet* instruction) { |
| 4965 | FieldAccessCallingConventionX86 calling_convention; |
| 4966 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4967 | instruction->GetFieldType(), |
| 4968 | instruction->GetFieldIndex(), |
| 4969 | instruction->GetDexPc(), |
| 4970 | calling_convention); |
| 4971 | } |
| 4972 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4973 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4974 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4975 | ? LocationSummary::kCallOnSlowPath |
| 4976 | : LocationSummary::kNoCall; |
| 4977 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4978 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4979 | ? Location::RequiresRegister() |
| 4980 | : Location::Any(); |
| 4981 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4982 | if (instruction->HasUses()) { |
| 4983 | locations->SetOut(Location::SameAsFirstInput()); |
| 4984 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4985 | } |
| 4986 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4987 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4988 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4989 | return; |
| 4990 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4991 | LocationSummary* locations = instruction->GetLocations(); |
| 4992 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4993 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4994 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4995 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4996 | } |
| 4997 | |
| 4998 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4999 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5000 | codegen_->AddSlowPath(slow_path); |
| 5001 | |
| 5002 | LocationSummary* locations = instruction->GetLocations(); |
| 5003 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5004 | |
| 5005 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5006 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5007 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5008 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5009 | } else { |
| 5010 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5011 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5012 | __ jmp(slow_path->GetEntryLabel()); |
| 5013 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5014 | } |
| 5015 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5016 | } |
| 5017 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5018 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5019 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5020 | GenerateImplicitNullCheck(instruction); |
| 5021 | } else { |
| 5022 | GenerateExplicitNullCheck(instruction); |
| 5023 | } |
| 5024 | } |
| 5025 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5026 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5027 | bool object_array_get_with_read_barrier = |
| 5028 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5029 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5030 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5031 | object_array_get_with_read_barrier ? |
| 5032 | LocationSummary::kCallOnSlowPath : |
| 5033 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5035 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5036 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5037 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5038 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5039 | // The output overlaps in case of long: we don't want the low move |
| 5040 | // to overwrite the array's location. Likewise, in the case of an |
| 5041 | // object array get with read barriers enabled, we do not want the |
| 5042 | // move to overwrite the array's location, as we need it to emit |
| 5043 | // the read barrier. |
| 5044 | locations->SetOut( |
| 5045 | Location::RequiresRegister(), |
| 5046 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5047 | Location::kOutputOverlap : |
| 5048 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5049 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5050 | // We need a temporary register for the read barrier marking slow |
| 5051 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5052 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5053 | locations->AddTemp(Location::RequiresRegister()); |
| 5054 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5058 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5059 | Location obj_loc = locations->InAt(0); |
| 5060 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5061 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5062 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5063 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5064 | Primitive::Type type = instruction->GetType(); |
| 5065 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | case Primitive::kPrimBoolean: { |
| 5067 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5068 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | if (index.IsConstant()) { |
| 5070 | __ movzxb(out, Address(obj, |
| 5071 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5072 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5073 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | } |
| 5075 | break; |
| 5076 | } |
| 5077 | |
| 5078 | case Primitive::kPrimByte: { |
| 5079 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5080 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5081 | if (index.IsConstant()) { |
| 5082 | __ movsxb(out, Address(obj, |
| 5083 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5084 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5085 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5086 | } |
| 5087 | break; |
| 5088 | } |
| 5089 | |
| 5090 | case Primitive::kPrimShort: { |
| 5091 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5092 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5093 | if (index.IsConstant()) { |
| 5094 | __ movsxw(out, Address(obj, |
| 5095 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5096 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5097 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5098 | } |
| 5099 | break; |
| 5100 | } |
| 5101 | |
| 5102 | case Primitive::kPrimChar: { |
| 5103 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5104 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5105 | if (index.IsConstant()) { |
| 5106 | __ movzxw(out, Address(obj, |
| 5107 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5108 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5109 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5110 | } |
| 5111 | break; |
| 5112 | } |
| 5113 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5114 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5115 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5116 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5117 | if (index.IsConstant()) { |
| 5118 | __ movl(out, Address(obj, |
| 5119 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5120 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5121 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5122 | } |
| 5123 | break; |
| 5124 | } |
| 5125 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5126 | case Primitive::kPrimNot: { |
| 5127 | static_assert( |
| 5128 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5129 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5130 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5131 | // /* HeapReference<Object> */ out = |
| 5132 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5133 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5134 | Location temp = locations->GetTemp(0); |
| 5135 | // Note that a potential implicit null check is handled in this |
| 5136 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5137 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5138 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5139 | } else { |
| 5140 | Register out = out_loc.AsRegister<Register>(); |
| 5141 | if (index.IsConstant()) { |
| 5142 | uint32_t offset = |
| 5143 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5144 | __ movl(out, Address(obj, offset)); |
| 5145 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5146 | // If read barriers are enabled, emit read barriers other than |
| 5147 | // Baker's using a slow path (and also unpoison the loaded |
| 5148 | // reference, if heap poisoning is enabled). |
| 5149 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5150 | } else { |
| 5151 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5152 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5153 | // If read barriers are enabled, emit read barriers other than |
| 5154 | // Baker's using a slow path (and also unpoison the loaded |
| 5155 | // reference, if heap poisoning is enabled). |
| 5156 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5157 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5158 | } |
| 5159 | } |
| 5160 | break; |
| 5161 | } |
| 5162 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | case Primitive::kPrimLong: { |
| 5164 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5165 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5166 | if (index.IsConstant()) { |
| 5167 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5168 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5169 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5170 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5171 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5172 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5173 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5174 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5175 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5176 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5177 | } |
| 5178 | break; |
| 5179 | } |
| 5180 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5181 | case Primitive::kPrimFloat: { |
| 5182 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5183 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5184 | if (index.IsConstant()) { |
| 5185 | __ movss(out, Address(obj, |
| 5186 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5187 | } else { |
| 5188 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5189 | } |
| 5190 | break; |
| 5191 | } |
| 5192 | |
| 5193 | case Primitive::kPrimDouble: { |
| 5194 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5195 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5196 | if (index.IsConstant()) { |
| 5197 | __ movsd(out, Address(obj, |
| 5198 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5199 | } else { |
| 5200 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5201 | } |
| 5202 | break; |
| 5203 | } |
| 5204 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5205 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5206 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5207 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5208 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5209 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5210 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5211 | // Potential implicit null checks, in the case of reference or |
| 5212 | // long arrays, are handled in the previous switch statement. |
| 5213 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5214 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5215 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5216 | } |
| 5217 | |
| 5218 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5219 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5220 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5221 | bool needs_write_barrier = |
| 5222 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5223 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5224 | bool object_array_set_with_read_barrier = |
| 5225 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5226 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5227 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5228 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5229 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5230 | LocationSummary::kCallOnSlowPath : |
| 5231 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5232 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5233 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5234 | || (value_type == Primitive::kPrimByte); |
| 5235 | // We need the inputs to be different than the output in case of long operation. |
| 5236 | // In case of a byte operation, the register allocator does not support multiple |
| 5237 | // inputs that die at entry with one in a specific register. |
| 5238 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5239 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5240 | if (is_byte_type) { |
| 5241 | // Ensure the value is in a byte register. |
| 5242 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5243 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5244 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5245 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5246 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5247 | } |
| 5248 | if (needs_write_barrier) { |
| 5249 | // Temporary registers for the write barrier. |
| 5250 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5251 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5252 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5253 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | } |
| 5255 | |
| 5256 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5257 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5258 | Location array_loc = locations->InAt(0); |
| 5259 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5261 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5262 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5263 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5264 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5265 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5266 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5267 | bool needs_write_barrier = |
| 5268 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5269 | |
| 5270 | switch (value_type) { |
| 5271 | case Primitive::kPrimBoolean: |
| 5272 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5273 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5274 | Address address = index.IsConstant() |
| 5275 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5276 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5277 | if (value.IsRegister()) { |
| 5278 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5279 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5280 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5281 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5282 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5283 | break; |
| 5284 | } |
| 5285 | |
| 5286 | case Primitive::kPrimShort: |
| 5287 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5288 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5289 | Address address = index.IsConstant() |
| 5290 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5291 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5292 | if (value.IsRegister()) { |
| 5293 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5294 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5295 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5296 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5297 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | break; |
| 5299 | } |
| 5300 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5301 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5302 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5303 | Address address = index.IsConstant() |
| 5304 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5305 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5306 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5307 | if (!value.IsRegister()) { |
| 5308 | // Just setting null. |
| 5309 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5310 | DCHECK(value.IsConstant()) << value; |
| 5311 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5312 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5313 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5314 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5315 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5316 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5317 | |
| 5318 | DCHECK(needs_write_barrier); |
| 5319 | Register register_value = value.AsRegister<Register>(); |
| 5320 | NearLabel done, not_null, do_put; |
| 5321 | SlowPathCode* slow_path = nullptr; |
| 5322 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5323 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5324 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5325 | codegen_->AddSlowPath(slow_path); |
| 5326 | if (instruction->GetValueCanBeNull()) { |
| 5327 | __ testl(register_value, register_value); |
| 5328 | __ j(kNotEqual, ¬_null); |
| 5329 | __ movl(address, Immediate(0)); |
| 5330 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5331 | __ jmp(&done); |
| 5332 | __ Bind(¬_null); |
| 5333 | } |
| 5334 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5335 | if (kEmitCompilerReadBarrier) { |
| 5336 | // When read barriers are enabled, the type checking |
| 5337 | // instrumentation requires two read barriers: |
| 5338 | // |
| 5339 | // __ movl(temp2, temp); |
| 5340 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5341 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5342 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5343 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5344 | // |
| 5345 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5346 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5347 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5348 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5349 | // |
| 5350 | // __ cmpl(temp, temp2); |
| 5351 | // |
| 5352 | // However, the second read barrier may trash `temp`, as it |
| 5353 | // is a temporary register, and as such would not be saved |
| 5354 | // along with live registers before calling the runtime (nor |
| 5355 | // restored afterwards). So in this case, we bail out and |
| 5356 | // delegate the work to the array set slow path. |
| 5357 | // |
| 5358 | // TODO: Extend the register allocator to support a new |
| 5359 | // "(locally) live temp" location so as to avoid always |
| 5360 | // going into the slow path when read barriers are enabled. |
| 5361 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5362 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5363 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5364 | __ movl(temp, Address(array, class_offset)); |
| 5365 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5366 | __ MaybeUnpoisonHeapReference(temp); |
| 5367 | |
| 5368 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5369 | __ movl(temp, Address(temp, component_offset)); |
| 5370 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5371 | // nor the object reference in `register_value->klass`, as |
| 5372 | // we are comparing two poisoned references. |
| 5373 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5374 | |
| 5375 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5376 | __ j(kEqual, &do_put); |
| 5377 | // If heap poisoning is enabled, the `temp` reference has |
| 5378 | // not been unpoisoned yet; unpoison it now. |
| 5379 | __ MaybeUnpoisonHeapReference(temp); |
| 5380 | |
| 5381 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5382 | __ movl(temp, Address(temp, super_offset)); |
| 5383 | // If heap poisoning is enabled, no need to unpoison |
| 5384 | // `temp`, as we are comparing against null below. |
| 5385 | __ testl(temp, temp); |
| 5386 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5387 | __ Bind(&do_put); |
| 5388 | } else { |
| 5389 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5390 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | if (kPoisonHeapReferences) { |
| 5395 | __ movl(temp, register_value); |
| 5396 | __ PoisonHeapReference(temp); |
| 5397 | __ movl(address, temp); |
| 5398 | } else { |
| 5399 | __ movl(address, register_value); |
| 5400 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5401 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5403 | } |
| 5404 | |
| 5405 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5406 | codegen_->MarkGCCard( |
| 5407 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5408 | __ Bind(&done); |
| 5409 | |
| 5410 | if (slow_path != nullptr) { |
| 5411 | __ Bind(slow_path->GetExitLabel()); |
| 5412 | } |
| 5413 | |
| 5414 | break; |
| 5415 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5416 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5417 | case Primitive::kPrimInt: { |
| 5418 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5419 | Address address = index.IsConstant() |
| 5420 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5421 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5422 | if (value.IsRegister()) { |
| 5423 | __ movl(address, value.AsRegister<Register>()); |
| 5424 | } else { |
| 5425 | DCHECK(value.IsConstant()) << value; |
| 5426 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5427 | __ movl(address, Immediate(v)); |
| 5428 | } |
| 5429 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5430 | break; |
| 5431 | } |
| 5432 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5433 | case Primitive::kPrimLong: { |
| 5434 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5435 | if (index.IsConstant()) { |
| 5436 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5437 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5438 | __ movl(Address(array, offset), 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, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5441 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5442 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5443 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5444 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5445 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5446 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5447 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5448 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5449 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5450 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5451 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5452 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5453 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5454 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5455 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5456 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5457 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5458 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5459 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5460 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5461 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5462 | Immediate(High32Bits(val))); |
| 5463 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5464 | } |
| 5465 | break; |
| 5466 | } |
| 5467 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5468 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5469 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5470 | Address address = index.IsConstant() |
| 5471 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5472 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5473 | if (value.IsFpuRegister()) { |
| 5474 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5475 | } else { |
| 5476 | DCHECK(value.IsConstant()); |
| 5477 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5478 | __ movl(address, Immediate(v)); |
| 5479 | } |
| 5480 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5481 | break; |
| 5482 | } |
| 5483 | |
| 5484 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5485 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5486 | Address address = index.IsConstant() |
| 5487 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5488 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5489 | if (value.IsFpuRegister()) { |
| 5490 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5491 | } else { |
| 5492 | DCHECK(value.IsConstant()); |
| 5493 | Address address_hi = index.IsConstant() ? |
| 5494 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5495 | offset + kX86WordSize) : |
| 5496 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5497 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5498 | __ movl(address, Immediate(Low32Bits(v))); |
| 5499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5500 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5501 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5502 | break; |
| 5503 | } |
| 5504 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5505 | case Primitive::kPrimVoid: |
| 5506 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5507 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5512 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5513 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5514 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5518 | LocationSummary* locations = instruction->GetLocations(); |
| 5519 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5520 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5521 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5522 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5523 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5527 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5528 | ? LocationSummary::kCallOnSlowPath |
| 5529 | : LocationSummary::kNoCall; |
| 5530 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5531 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5532 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5533 | if (instruction->HasUses()) { |
| 5534 | locations->SetOut(Location::SameAsFirstInput()); |
| 5535 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5539 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5540 | Location index_loc = locations->InAt(0); |
| 5541 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5542 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5543 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5544 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5545 | if (length_loc.IsConstant()) { |
| 5546 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5547 | if (index_loc.IsConstant()) { |
| 5548 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5549 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5550 | if (index < 0 || index >= length) { |
| 5551 | codegen_->AddSlowPath(slow_path); |
| 5552 | __ jmp(slow_path->GetEntryLabel()); |
| 5553 | } else { |
| 5554 | // Some optimization after BCE may have generated this, and we should not |
| 5555 | // generate a bounds check if it is a valid range. |
| 5556 | } |
| 5557 | return; |
| 5558 | } |
| 5559 | |
| 5560 | // We have to reverse the jump condition because the length is the constant. |
| 5561 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5562 | __ cmpl(index_reg, Immediate(length)); |
| 5563 | codegen_->AddSlowPath(slow_path); |
| 5564 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5565 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5566 | Register length = length_loc.AsRegister<Register>(); |
| 5567 | if (index_loc.IsConstant()) { |
| 5568 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5569 | __ cmpl(length, Immediate(value)); |
| 5570 | } else { |
| 5571 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5572 | } |
| 5573 | codegen_->AddSlowPath(slow_path); |
| 5574 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5575 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5576 | } |
| 5577 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5578 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5579 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5580 | } |
| 5581 | |
| 5582 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5583 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5584 | } |
| 5585 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5586 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5587 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5588 | } |
| 5589 | |
| 5590 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5591 | HBasicBlock* block = instruction->GetBlock(); |
| 5592 | if (block->GetLoopInformation() != nullptr) { |
| 5593 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5594 | // The back edge will generate the suspend check. |
| 5595 | return; |
| 5596 | } |
| 5597 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5598 | // The goto will generate the suspend check. |
| 5599 | return; |
| 5600 | } |
| 5601 | GenerateSuspendCheck(instruction, nullptr); |
| 5602 | } |
| 5603 | |
| 5604 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5605 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5606 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5607 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5608 | if (slow_path == nullptr) { |
| 5609 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5610 | instruction->SetSlowPath(slow_path); |
| 5611 | codegen_->AddSlowPath(slow_path); |
| 5612 | if (successor != nullptr) { |
| 5613 | DCHECK(successor->IsLoopHeader()); |
| 5614 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5615 | } |
| 5616 | } else { |
| 5617 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5618 | } |
| 5619 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5620 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5621 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5622 | if (successor == nullptr) { |
| 5623 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5624 | __ Bind(slow_path->GetReturnLabel()); |
| 5625 | } else { |
| 5626 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5627 | __ jmp(slow_path->GetEntryLabel()); |
| 5628 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5629 | } |
| 5630 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5631 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5632 | return codegen_->GetAssembler(); |
| 5633 | } |
| 5634 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5635 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5636 | ScratchRegisterScope ensure_scratch( |
| 5637 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5638 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5639 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5640 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5641 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5645 | ScratchRegisterScope ensure_scratch( |
| 5646 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5647 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5648 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5649 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5650 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5651 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5652 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5653 | } |
| 5654 | |
| 5655 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5656 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5657 | Location source = move->GetSource(); |
| 5658 | Location destination = move->GetDestination(); |
| 5659 | |
| 5660 | if (source.IsRegister()) { |
| 5661 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5662 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5663 | } else if (destination.IsFpuRegister()) { |
| 5664 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5665 | } else { |
| 5666 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5667 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5668 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5669 | } else if (source.IsRegisterPair()) { |
| 5670 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5671 | // Create stack space for 2 elements. |
| 5672 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5673 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5674 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5675 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5676 | // And remove the temporary stack space we allocated. |
| 5677 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5678 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5679 | if (destination.IsRegister()) { |
| 5680 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5681 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5682 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5683 | } else if (destination.IsRegisterPair()) { |
| 5684 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5685 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5686 | __ psrlq(src_reg, Immediate(32)); |
| 5687 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5688 | } else if (destination.IsStackSlot()) { |
| 5689 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5690 | } else { |
| 5691 | DCHECK(destination.IsDoubleStackSlot()); |
| 5692 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5693 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5694 | } else if (source.IsStackSlot()) { |
| 5695 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5696 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5697 | } else if (destination.IsFpuRegister()) { |
| 5698 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5699 | } else { |
| 5700 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5701 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5702 | } |
| 5703 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5704 | if (destination.IsRegisterPair()) { |
| 5705 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5706 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5707 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5708 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5709 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5710 | } else { |
| 5711 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5712 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5713 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5714 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5715 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5716 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5717 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5718 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5719 | if (value == 0) { |
| 5720 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5721 | } else { |
| 5722 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5723 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5724 | } else { |
| 5725 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5726 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5727 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5728 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5729 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5730 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5731 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5732 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5733 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5734 | if (value == 0) { |
| 5735 | // Easy handling of 0.0. |
| 5736 | __ xorps(dest, dest); |
| 5737 | } else { |
| 5738 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5739 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5740 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5741 | __ movl(temp, Immediate(value)); |
| 5742 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5743 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5744 | } else { |
| 5745 | DCHECK(destination.IsStackSlot()) << destination; |
| 5746 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5747 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5748 | } else if (constant->IsLongConstant()) { |
| 5749 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5750 | int32_t low_value = Low32Bits(value); |
| 5751 | int32_t high_value = High32Bits(value); |
| 5752 | Immediate low(low_value); |
| 5753 | Immediate high(high_value); |
| 5754 | if (destination.IsDoubleStackSlot()) { |
| 5755 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5756 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5757 | } else { |
| 5758 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5759 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5760 | } |
| 5761 | } else { |
| 5762 | DCHECK(constant->IsDoubleConstant()); |
| 5763 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5764 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5765 | int32_t low_value = Low32Bits(value); |
| 5766 | int32_t high_value = High32Bits(value); |
| 5767 | Immediate low(low_value); |
| 5768 | Immediate high(high_value); |
| 5769 | if (destination.IsFpuRegister()) { |
| 5770 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5771 | if (value == 0) { |
| 5772 | // Easy handling of 0.0. |
| 5773 | __ xorpd(dest, dest); |
| 5774 | } else { |
| 5775 | __ pushl(high); |
| 5776 | __ pushl(low); |
| 5777 | __ movsd(dest, Address(ESP, 0)); |
| 5778 | __ addl(ESP, Immediate(8)); |
| 5779 | } |
| 5780 | } else { |
| 5781 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5782 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5783 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5784 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5785 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5786 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5787 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5788 | } |
| 5789 | } |
| 5790 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5791 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5792 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5793 | ScratchRegisterScope ensure_scratch( |
| 5794 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5795 | |
| 5796 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5797 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5798 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5799 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5800 | } |
| 5801 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5802 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5803 | ScratchRegisterScope ensure_scratch( |
| 5804 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5805 | |
| 5806 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5807 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5808 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5809 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5810 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5811 | } |
| 5812 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5813 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5814 | ScratchRegisterScope ensure_scratch1( |
| 5815 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5816 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5817 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5818 | ScratchRegisterScope ensure_scratch2( |
| 5819 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5820 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5821 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5822 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5823 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5824 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5825 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5826 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5830 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5831 | Location source = move->GetSource(); |
| 5832 | Location destination = move->GetDestination(); |
| 5833 | |
| 5834 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5835 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5836 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5837 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5838 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5839 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5840 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5841 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5842 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5843 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5844 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5845 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5846 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5847 | // Use XOR Swap algorithm to avoid a temporary. |
| 5848 | DCHECK_NE(source.reg(), destination.reg()); |
| 5849 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5850 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5851 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5852 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5853 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5854 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5855 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5856 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5857 | // Take advantage of the 16 bytes in the XMM register. |
| 5858 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5859 | Address stack(ESP, destination.GetStackIndex()); |
| 5860 | // Load the double into the high doubleword. |
| 5861 | __ movhpd(reg, stack); |
| 5862 | |
| 5863 | // Store the low double into the destination. |
| 5864 | __ movsd(stack, reg); |
| 5865 | |
| 5866 | // Move the high double to the low double. |
| 5867 | __ psrldq(reg, Immediate(8)); |
| 5868 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5869 | // Take advantage of the 16 bytes in the XMM register. |
| 5870 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5871 | Address stack(ESP, source.GetStackIndex()); |
| 5872 | // Load the double into the high doubleword. |
| 5873 | __ movhpd(reg, stack); |
| 5874 | |
| 5875 | // Store the low double into the destination. |
| 5876 | __ movsd(stack, reg); |
| 5877 | |
| 5878 | // Move the high double to the low double. |
| 5879 | __ psrldq(reg, Immediate(8)); |
| 5880 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5881 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5882 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5883 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5884 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5885 | } |
| 5886 | } |
| 5887 | |
| 5888 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5889 | __ pushl(static_cast<Register>(reg)); |
| 5890 | } |
| 5891 | |
| 5892 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5893 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5894 | } |
| 5895 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5896 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5897 | InvokeRuntimeCallingConvention calling_convention; |
| 5898 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5899 | cls, |
| 5900 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5901 | Location::RegisterLocation(EAX), |
| 5902 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5906 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5907 | if (cls->NeedsAccessCheck()) { |
| 5908 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5909 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5910 | cls, |
| 5911 | cls->GetDexPc(), |
| 5912 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5913 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5914 | return; |
| 5915 | } |
| 5916 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5917 | Location out_loc = locations->Out(); |
| 5918 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5919 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5921 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5922 | DCHECK(!cls->CanCallRuntime()); |
| 5923 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5924 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5925 | GenerateGcRootFieldLoad( |
| 5926 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5927 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5928 | // /* GcRoot<mirror::Class>[] */ out = |
| 5929 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5930 | __ movl(out, Address(current_method, |
| 5931 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5932 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5933 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5934 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5935 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5936 | DCHECK(cls->CanCallRuntime()); |
| 5937 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5938 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5939 | codegen_->AddSlowPath(slow_path); |
| 5940 | |
| 5941 | if (!cls->IsInDexCache()) { |
| 5942 | __ testl(out, out); |
| 5943 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5944 | } |
| 5945 | |
| 5946 | if (cls->MustGenerateClinitCheck()) { |
| 5947 | GenerateClassInitializationCheck(slow_path, out); |
| 5948 | } else { |
| 5949 | __ Bind(slow_path->GetExitLabel()); |
| 5950 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5951 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5952 | } |
| 5953 | } |
| 5954 | |
| 5955 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5956 | LocationSummary* locations = |
| 5957 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5958 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5959 | if (check->HasUses()) { |
| 5960 | locations->SetOut(Location::SameAsFirstInput()); |
| 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5965 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5966 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5967 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5968 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5969 | GenerateClassInitializationCheck(slow_path, |
| 5970 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5971 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5972 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5973 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5974 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5975 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5976 | Immediate(mirror::Class::kStatusInitialized)); |
| 5977 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5978 | __ Bind(slow_path->GetExitLabel()); |
| 5979 | // No need for memory fence, thanks to the X86 memory model. |
| 5980 | } |
| 5981 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5982 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5983 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5984 | ? LocationSummary::kCallOnSlowPath |
| 5985 | : LocationSummary::kNoCall; |
| 5986 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5987 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5988 | locations->SetOut(Location::RequiresRegister()); |
| 5989 | } |
| 5990 | |
| 5991 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5992 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5993 | Location out_loc = locations->Out(); |
| 5994 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5995 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5996 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5997 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5998 | GenerateGcRootFieldLoad( |
| 5999 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6000 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 6001 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6002 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 6003 | GenerateGcRootFieldLoad( |
| 6004 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6005 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6006 | if (!load->IsInDexCache()) { |
| 6007 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6008 | codegen_->AddSlowPath(slow_path); |
| 6009 | __ testl(out, out); |
| 6010 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6011 | __ Bind(slow_path->GetExitLabel()); |
| 6012 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6013 | } |
| 6014 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6015 | static Address GetExceptionTlsAddress() { |
| 6016 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6017 | } |
| 6018 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6019 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6020 | LocationSummary* locations = |
| 6021 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6022 | locations->SetOut(Location::RequiresRegister()); |
| 6023 | } |
| 6024 | |
| 6025 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6026 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6027 | } |
| 6028 | |
| 6029 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6030 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6031 | } |
| 6032 | |
| 6033 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6034 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6038 | LocationSummary* locations = |
| 6039 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6040 | InvokeRuntimeCallingConvention calling_convention; |
| 6041 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6042 | } |
| 6043 | |
| 6044 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6045 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6046 | instruction, |
| 6047 | instruction->GetDexPc(), |
| 6048 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6049 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6050 | } |
| 6051 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6052 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6053 | return kEmitCompilerReadBarrier && |
| 6054 | (kUseBakerReadBarrier || |
| 6055 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6056 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6057 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6058 | } |
| 6059 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6060 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6061 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6062 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6063 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6064 | case TypeCheckKind::kExactCheck: |
| 6065 | case TypeCheckKind::kAbstractClassCheck: |
| 6066 | case TypeCheckKind::kClassHierarchyCheck: |
| 6067 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6068 | call_kind = |
| 6069 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6070 | break; |
| 6071 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6072 | case TypeCheckKind::kUnresolvedCheck: |
| 6073 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6074 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6075 | break; |
| 6076 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6077 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6078 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6080 | locations->SetInAt(1, Location::Any()); |
| 6081 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6082 | locations->SetOut(Location::RequiresRegister()); |
| 6083 | // When read barriers are enabled, we need a temporary register for |
| 6084 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6085 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6086 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6087 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6090 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6091 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6092 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6093 | Location obj_loc = locations->InAt(0); |
| 6094 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6095 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6096 | Location out_loc = locations->Out(); |
| 6097 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6098 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6099 | locations->GetTemp(0) : |
| 6100 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6101 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6102 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6103 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6104 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6105 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6106 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6107 | |
| 6108 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6109 | // Avoid null check if we know obj is not null. |
| 6110 | if (instruction->MustDoNullCheck()) { |
| 6111 | __ testl(obj, obj); |
| 6112 | __ j(kEqual, &zero); |
| 6113 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6114 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6115 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6116 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6117 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6118 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6119 | case TypeCheckKind::kExactCheck: { |
| 6120 | if (cls.IsRegister()) { |
| 6121 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6122 | } else { |
| 6123 | DCHECK(cls.IsStackSlot()) << cls; |
| 6124 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6125 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6126 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6127 | // Classes must be equal for the instanceof to succeed. |
| 6128 | __ j(kNotEqual, &zero); |
| 6129 | __ movl(out, Immediate(1)); |
| 6130 | __ jmp(&done); |
| 6131 | break; |
| 6132 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6133 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6134 | case TypeCheckKind::kAbstractClassCheck: { |
| 6135 | // If the class is abstract, we eagerly fetch the super class of the |
| 6136 | // object to avoid doing a comparison we know will fail. |
| 6137 | NearLabel loop; |
| 6138 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6139 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6140 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6141 | __ testl(out, out); |
| 6142 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6143 | __ j(kEqual, &done); |
| 6144 | if (cls.IsRegister()) { |
| 6145 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6146 | } else { |
| 6147 | DCHECK(cls.IsStackSlot()) << cls; |
| 6148 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6149 | } |
| 6150 | __ j(kNotEqual, &loop); |
| 6151 | __ movl(out, Immediate(1)); |
| 6152 | if (zero.IsLinked()) { |
| 6153 | __ jmp(&done); |
| 6154 | } |
| 6155 | break; |
| 6156 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6157 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6159 | // Walk over the class hierarchy to find a match. |
| 6160 | NearLabel loop, success; |
| 6161 | __ Bind(&loop); |
| 6162 | if (cls.IsRegister()) { |
| 6163 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6164 | } else { |
| 6165 | DCHECK(cls.IsStackSlot()) << cls; |
| 6166 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6167 | } |
| 6168 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6169 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6170 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | __ testl(out, out); |
| 6172 | __ j(kNotEqual, &loop); |
| 6173 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6174 | __ jmp(&done); |
| 6175 | __ Bind(&success); |
| 6176 | __ movl(out, Immediate(1)); |
| 6177 | if (zero.IsLinked()) { |
| 6178 | __ jmp(&done); |
| 6179 | } |
| 6180 | break; |
| 6181 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6182 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6184 | // Do an exact check. |
| 6185 | NearLabel exact_check; |
| 6186 | if (cls.IsRegister()) { |
| 6187 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6188 | } else { |
| 6189 | DCHECK(cls.IsStackSlot()) << cls; |
| 6190 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6191 | } |
| 6192 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6193 | // 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] | 6194 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6195 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6196 | __ testl(out, out); |
| 6197 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6198 | __ j(kEqual, &done); |
| 6199 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6200 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6201 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6202 | __ movl(out, Immediate(1)); |
| 6203 | __ jmp(&done); |
| 6204 | break; |
| 6205 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6206 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6207 | case TypeCheckKind::kArrayCheck: { |
| 6208 | if (cls.IsRegister()) { |
| 6209 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6210 | } else { |
| 6211 | DCHECK(cls.IsStackSlot()) << cls; |
| 6212 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6213 | } |
| 6214 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6215 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6216 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6217 | codegen_->AddSlowPath(slow_path); |
| 6218 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6219 | __ movl(out, Immediate(1)); |
| 6220 | if (zero.IsLinked()) { |
| 6221 | __ jmp(&done); |
| 6222 | } |
| 6223 | break; |
| 6224 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6225 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6226 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6227 | case TypeCheckKind::kInterfaceCheck: { |
| 6228 | // 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] | 6229 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6230 | // cases. |
| 6231 | // |
| 6232 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6233 | // entry point without resorting to a type checking slow path |
| 6234 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6235 | // require to assign fixed registers for the inputs of this |
| 6236 | // HInstanceOf instruction (following the runtime calling |
| 6237 | // convention), which might be cluttered by the potential first |
| 6238 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6239 | // |
| 6240 | // TODO: Introduce a new runtime entry point taking the object |
| 6241 | // to test (instead of its class) as argument, and let it deal |
| 6242 | // with the read barrier issues. This will let us refactor this |
| 6243 | // case of the `switch` code as it was previously (with a direct |
| 6244 | // call to the runtime not using a type checking slow path). |
| 6245 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6246 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6247 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6248 | /* is_fatal */ false); |
| 6249 | codegen_->AddSlowPath(slow_path); |
| 6250 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6251 | if (zero.IsLinked()) { |
| 6252 | __ jmp(&done); |
| 6253 | } |
| 6254 | break; |
| 6255 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6258 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6259 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6260 | __ xorl(out, out); |
| 6261 | } |
| 6262 | |
| 6263 | if (done.IsLinked()) { |
| 6264 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6265 | } |
| 6266 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6267 | if (slow_path != nullptr) { |
| 6268 | __ Bind(slow_path->GetExitLabel()); |
| 6269 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6272 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6273 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6274 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6275 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6276 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6277 | case TypeCheckKind::kExactCheck: |
| 6278 | case TypeCheckKind::kAbstractClassCheck: |
| 6279 | case TypeCheckKind::kClassHierarchyCheck: |
| 6280 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6282 | LocationSummary::kCallOnSlowPath : |
| 6283 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6284 | break; |
| 6285 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6286 | case TypeCheckKind::kUnresolvedCheck: |
| 6287 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6289 | break; |
| 6290 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6291 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6292 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6293 | locations->SetInAt(1, Location::Any()); |
| 6294 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6295 | locations->AddTemp(Location::RequiresRegister()); |
| 6296 | // When read barriers are enabled, we need an additional temporary |
| 6297 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6298 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6299 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6300 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6304 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6305 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6306 | Location obj_loc = locations->InAt(0); |
| 6307 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6308 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6309 | Location temp_loc = locations->GetTemp(0); |
| 6310 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6311 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6312 | locations->GetTemp(1) : |
| 6313 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6314 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6315 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6316 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6317 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6318 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6319 | bool is_type_check_slow_path_fatal = |
| 6320 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6321 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6322 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6323 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6324 | !instruction->CanThrowIntoCatchBlock(); |
| 6325 | SlowPathCode* type_check_slow_path = |
| 6326 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6327 | is_type_check_slow_path_fatal); |
| 6328 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6329 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6330 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6331 | // Avoid null check if we know obj is not null. |
| 6332 | if (instruction->MustDoNullCheck()) { |
| 6333 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6334 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6335 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6336 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6338 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6339 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6340 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6341 | case TypeCheckKind::kExactCheck: |
| 6342 | case TypeCheckKind::kArrayCheck: { |
| 6343 | if (cls.IsRegister()) { |
| 6344 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6345 | } else { |
| 6346 | DCHECK(cls.IsStackSlot()) << cls; |
| 6347 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6348 | } |
| 6349 | // Jump to slow path for throwing the exception or doing a |
| 6350 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6351 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6352 | break; |
| 6353 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6355 | case TypeCheckKind::kAbstractClassCheck: { |
| 6356 | // If the class is abstract, we eagerly fetch the super class of the |
| 6357 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6358 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6359 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6360 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6361 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6362 | |
| 6363 | // If the class reference currently in `temp` is not null, jump |
| 6364 | // to the `compare_classes` label to compare it with the checked |
| 6365 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6366 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6367 | __ j(kNotEqual, &compare_classes); |
| 6368 | // Otherwise, jump to the slow path to throw the exception. |
| 6369 | // |
| 6370 | // But before, move back the object's class into `temp` before |
| 6371 | // going into the slow path, as it has been overwritten in the |
| 6372 | // meantime. |
| 6373 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6374 | GenerateReferenceLoadTwoRegisters( |
| 6375 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6376 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6377 | |
| 6378 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6379 | if (cls.IsRegister()) { |
| 6380 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6381 | } else { |
| 6382 | DCHECK(cls.IsStackSlot()) << cls; |
| 6383 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6384 | } |
| 6385 | __ j(kNotEqual, &loop); |
| 6386 | break; |
| 6387 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6388 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6389 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6390 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6391 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6392 | __ Bind(&loop); |
| 6393 | if (cls.IsRegister()) { |
| 6394 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6395 | } else { |
| 6396 | DCHECK(cls.IsStackSlot()) << cls; |
| 6397 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6398 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6399 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6401 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6402 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6403 | |
| 6404 | // If the class reference currently in `temp` is not null, jump |
| 6405 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | __ testl(temp, temp); |
| 6407 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6408 | // Otherwise, jump to the slow path to throw the exception. |
| 6409 | // |
| 6410 | // But before, move back the object's class into `temp` before |
| 6411 | // going into the slow path, as it has been overwritten in the |
| 6412 | // meantime. |
| 6413 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6414 | GenerateReferenceLoadTwoRegisters( |
| 6415 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6416 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6417 | break; |
| 6418 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6420 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6421 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6422 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6423 | if (cls.IsRegister()) { |
| 6424 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6425 | } else { |
| 6426 | DCHECK(cls.IsStackSlot()) << cls; |
| 6427 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6428 | } |
| 6429 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6430 | |
| 6431 | // 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] | 6432 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6433 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6434 | |
| 6435 | // If the component type is not null (i.e. the object is indeed |
| 6436 | // an array), jump to label `check_non_primitive_component_type` |
| 6437 | // to further check that this component type is not a primitive |
| 6438 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6439 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6440 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6441 | // Otherwise, jump to the slow path to throw the exception. |
| 6442 | // |
| 6443 | // But before, move back the object's class into `temp` before |
| 6444 | // going into the slow path, as it has been overwritten in the |
| 6445 | // meantime. |
| 6446 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6447 | GenerateReferenceLoadTwoRegisters( |
| 6448 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6449 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6450 | |
| 6451 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6453 | __ j(kEqual, &done); |
| 6454 | // Same comment as above regarding `temp` and the slow path. |
| 6455 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6456 | GenerateReferenceLoadTwoRegisters( |
| 6457 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6458 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6459 | break; |
| 6460 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6461 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6462 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6463 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6464 | // We always go into the type check slow path for the unresolved |
| 6465 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6466 | // |
| 6467 | // We cannot directly call the CheckCast runtime entry point |
| 6468 | // without resorting to a type checking slow path here (i.e. by |
| 6469 | // calling InvokeRuntime directly), as it would require to |
| 6470 | // assign fixed registers for the inputs of this HInstanceOf |
| 6471 | // instruction (following the runtime calling convention), which |
| 6472 | // might be cluttered by the potential first read barrier |
| 6473 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6474 | // |
| 6475 | // TODO: Introduce a new runtime entry point taking the object |
| 6476 | // to test (instead of its class) as argument, and let it deal |
| 6477 | // with the read barrier issues. This will let us refactor this |
| 6478 | // case of the `switch` code as it was previously (with a direct |
| 6479 | // call to the runtime not using a type checking slow path). |
| 6480 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6481 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6482 | break; |
| 6483 | } |
| 6484 | __ Bind(&done); |
| 6485 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6486 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6487 | } |
| 6488 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6489 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6490 | LocationSummary* locations = |
| 6491 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6492 | InvokeRuntimeCallingConvention calling_convention; |
| 6493 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6494 | } |
| 6495 | |
| 6496 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6497 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6498 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6499 | instruction, |
| 6500 | instruction->GetDexPc(), |
| 6501 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6502 | if (instruction->IsEnter()) { |
| 6503 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6504 | } else { |
| 6505 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6506 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6509 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6510 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6511 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6512 | |
| 6513 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6514 | LocationSummary* locations = |
| 6515 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6516 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6517 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6518 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6519 | locations->SetInAt(1, Location::Any()); |
| 6520 | locations->SetOut(Location::SameAsFirstInput()); |
| 6521 | } |
| 6522 | |
| 6523 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6524 | HandleBitwiseOperation(instruction); |
| 6525 | } |
| 6526 | |
| 6527 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6528 | HandleBitwiseOperation(instruction); |
| 6529 | } |
| 6530 | |
| 6531 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6532 | HandleBitwiseOperation(instruction); |
| 6533 | } |
| 6534 | |
| 6535 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6536 | LocationSummary* locations = instruction->GetLocations(); |
| 6537 | Location first = locations->InAt(0); |
| 6538 | Location second = locations->InAt(1); |
| 6539 | DCHECK(first.Equals(locations->Out())); |
| 6540 | |
| 6541 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6542 | if (second.IsRegister()) { |
| 6543 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6544 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6545 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6546 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6547 | } else { |
| 6548 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6549 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6550 | } |
| 6551 | } else if (second.IsConstant()) { |
| 6552 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6553 | __ andl(first.AsRegister<Register>(), |
| 6554 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6555 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6556 | __ orl(first.AsRegister<Register>(), |
| 6557 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6558 | } else { |
| 6559 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6560 | __ xorl(first.AsRegister<Register>(), |
| 6561 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6562 | } |
| 6563 | } else { |
| 6564 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6565 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6566 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6567 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6568 | } else { |
| 6569 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6570 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6571 | } |
| 6572 | } |
| 6573 | } else { |
| 6574 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6575 | if (second.IsRegisterPair()) { |
| 6576 | if (instruction->IsAnd()) { |
| 6577 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6578 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6579 | } else if (instruction->IsOr()) { |
| 6580 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6581 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6582 | } else { |
| 6583 | DCHECK(instruction->IsXor()); |
| 6584 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6585 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6586 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6587 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6588 | if (instruction->IsAnd()) { |
| 6589 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6590 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6591 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6592 | } else if (instruction->IsOr()) { |
| 6593 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6594 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6595 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6596 | } else { |
| 6597 | DCHECK(instruction->IsXor()); |
| 6598 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6599 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6600 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6601 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6602 | } else { |
| 6603 | DCHECK(second.IsConstant()) << second; |
| 6604 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6605 | int32_t low_value = Low32Bits(value); |
| 6606 | int32_t high_value = High32Bits(value); |
| 6607 | Immediate low(low_value); |
| 6608 | Immediate high(high_value); |
| 6609 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6610 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6611 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6612 | if (low_value == 0) { |
| 6613 | __ xorl(first_low, first_low); |
| 6614 | } else if (low_value != -1) { |
| 6615 | __ andl(first_low, low); |
| 6616 | } |
| 6617 | if (high_value == 0) { |
| 6618 | __ xorl(first_high, first_high); |
| 6619 | } else if (high_value != -1) { |
| 6620 | __ andl(first_high, high); |
| 6621 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6622 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6623 | if (low_value != 0) { |
| 6624 | __ orl(first_low, low); |
| 6625 | } |
| 6626 | if (high_value != 0) { |
| 6627 | __ orl(first_high, high); |
| 6628 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6629 | } else { |
| 6630 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6631 | if (low_value != 0) { |
| 6632 | __ xorl(first_low, low); |
| 6633 | } |
| 6634 | if (high_value != 0) { |
| 6635 | __ xorl(first_high, high); |
| 6636 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6637 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6638 | } |
| 6639 | } |
| 6640 | } |
| 6641 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6642 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6643 | Location out, |
| 6644 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6645 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6646 | Register out_reg = out.AsRegister<Register>(); |
| 6647 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6648 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6649 | if (kUseBakerReadBarrier) { |
| 6650 | // Load with fast path based Baker's read barrier. |
| 6651 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6652 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6653 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6654 | } else { |
| 6655 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6656 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6657 | // in the following move operation, as we will need it for the |
| 6658 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6659 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6660 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6661 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6662 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6663 | } |
| 6664 | } else { |
| 6665 | // Plain load with no read barrier. |
| 6666 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6667 | __ movl(out_reg, Address(out_reg, offset)); |
| 6668 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6673 | Location out, |
| 6674 | Location obj, |
| 6675 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6676 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6677 | Register out_reg = out.AsRegister<Register>(); |
| 6678 | Register obj_reg = obj.AsRegister<Register>(); |
| 6679 | if (kEmitCompilerReadBarrier) { |
| 6680 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6681 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6682 | // Load with fast path based Baker's read barrier. |
| 6683 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6684 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6685 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6686 | } else { |
| 6687 | // Load with slow path based read barrier. |
| 6688 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6689 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6690 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6691 | } |
| 6692 | } else { |
| 6693 | // Plain load with no read barrier. |
| 6694 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6695 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6696 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6701 | Location root, |
| 6702 | Register obj, |
| 6703 | uint32_t offset) { |
| 6704 | Register root_reg = root.AsRegister<Register>(); |
| 6705 | if (kEmitCompilerReadBarrier) { |
| 6706 | if (kUseBakerReadBarrier) { |
| 6707 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6708 | // Baker's read barrier are used: |
| 6709 | // |
| 6710 | // root = obj.field; |
| 6711 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6712 | // root = ReadBarrier::Mark(root) |
| 6713 | // } |
| 6714 | |
| 6715 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6716 | __ movl(root_reg, Address(obj, offset)); |
| 6717 | static_assert( |
| 6718 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6719 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6720 | "have different sizes."); |
| 6721 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6722 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6723 | "have different sizes."); |
| 6724 | |
| 6725 | // Slow path used to mark the GC root `root`. |
| 6726 | SlowPathCode* slow_path = |
| 6727 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6728 | codegen_->AddSlowPath(slow_path); |
| 6729 | |
| 6730 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6731 | Immediate(0)); |
| 6732 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6733 | __ Bind(slow_path->GetExitLabel()); |
| 6734 | } else { |
| 6735 | // GC root loaded through a slow path for read barriers other |
| 6736 | // than Baker's. |
| 6737 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6738 | __ leal(root_reg, Address(obj, offset)); |
| 6739 | // /* mirror::Object* */ root = root->Read() |
| 6740 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6741 | } |
| 6742 | } else { |
| 6743 | // Plain GC root load with no read barrier. |
| 6744 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6745 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6746 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6747 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6748 | } |
| 6749 | } |
| 6750 | |
| 6751 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6752 | Location ref, |
| 6753 | Register obj, |
| 6754 | uint32_t offset, |
| 6755 | Location temp, |
| 6756 | bool needs_null_check) { |
| 6757 | DCHECK(kEmitCompilerReadBarrier); |
| 6758 | DCHECK(kUseBakerReadBarrier); |
| 6759 | |
| 6760 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6761 | Address src(obj, offset); |
| 6762 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6763 | } |
| 6764 | |
| 6765 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6766 | Location ref, |
| 6767 | Register obj, |
| 6768 | uint32_t data_offset, |
| 6769 | Location index, |
| 6770 | Location temp, |
| 6771 | bool needs_null_check) { |
| 6772 | DCHECK(kEmitCompilerReadBarrier); |
| 6773 | DCHECK(kUseBakerReadBarrier); |
| 6774 | |
| 6775 | // /* HeapReference<Object> */ ref = |
| 6776 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6777 | Address src = index.IsConstant() ? |
| 6778 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6779 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6780 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6781 | } |
| 6782 | |
| 6783 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6784 | Location ref, |
| 6785 | Register obj, |
| 6786 | const Address& src, |
| 6787 | Location temp, |
| 6788 | bool needs_null_check) { |
| 6789 | DCHECK(kEmitCompilerReadBarrier); |
| 6790 | DCHECK(kUseBakerReadBarrier); |
| 6791 | |
| 6792 | // In slow path based read barriers, the read barrier call is |
| 6793 | // inserted after the original load. However, in fast path based |
| 6794 | // Baker's read barriers, we need to perform the load of |
| 6795 | // mirror::Object::monitor_ *before* the original reference load. |
| 6796 | // This load-load ordering is required by the read barrier. |
| 6797 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6798 | // |
| 6799 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6800 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6801 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6802 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6803 | // if (is_gray) { |
| 6804 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6805 | // } |
| 6806 | // |
| 6807 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6808 | // slightly more complex as: |
| 6809 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6810 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6811 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6812 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6813 | // - it performs additional checks that we do not do here for |
| 6814 | // performance reasons. |
| 6815 | |
| 6816 | Register ref_reg = ref.AsRegister<Register>(); |
| 6817 | Register temp_reg = temp.AsRegister<Register>(); |
| 6818 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6819 | |
| 6820 | // /* int32_t */ monitor = obj->monitor_ |
| 6821 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6822 | if (needs_null_check) { |
| 6823 | MaybeRecordImplicitNullCheck(instruction); |
| 6824 | } |
| 6825 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6826 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6827 | "art::LockWord and int32_t have different sizes."); |
| 6828 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6829 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6830 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6831 | static_assert( |
| 6832 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6833 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6834 | |
| 6835 | // Load fence to prevent load-load reordering. |
| 6836 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6837 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6838 | |
| 6839 | // The actual reference load. |
| 6840 | // /* HeapReference<Object> */ ref = *src |
| 6841 | __ movl(ref_reg, src); |
| 6842 | |
| 6843 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6844 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6845 | |
| 6846 | // Slow path used to mark the object `ref` when it is gray. |
| 6847 | SlowPathCode* slow_path = |
| 6848 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6849 | AddSlowPath(slow_path); |
| 6850 | |
| 6851 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6852 | // ref = ReadBarrier::Mark(ref); |
| 6853 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6854 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6855 | __ Bind(slow_path->GetExitLabel()); |
| 6856 | } |
| 6857 | |
| 6858 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6859 | Location out, |
| 6860 | Location ref, |
| 6861 | Location obj, |
| 6862 | uint32_t offset, |
| 6863 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6864 | DCHECK(kEmitCompilerReadBarrier); |
| 6865 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6866 | // Insert a slow path based read barrier *after* the reference load. |
| 6867 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6868 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6869 | // reference will be carried out by the runtime within the slow |
| 6870 | // path. |
| 6871 | // |
| 6872 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6873 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6874 | // not used by the artReadBarrierSlow entry point. |
| 6875 | // |
| 6876 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6877 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6878 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6879 | AddSlowPath(slow_path); |
| 6880 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6881 | __ jmp(slow_path->GetEntryLabel()); |
| 6882 | __ Bind(slow_path->GetExitLabel()); |
| 6883 | } |
| 6884 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6885 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6886 | Location out, |
| 6887 | Location ref, |
| 6888 | Location obj, |
| 6889 | uint32_t offset, |
| 6890 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6891 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6892 | // Baker's read barriers shall be handled by the fast path |
| 6893 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6894 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6895 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6896 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6897 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6898 | } else if (kPoisonHeapReferences) { |
| 6899 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6900 | } |
| 6901 | } |
| 6902 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6903 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6904 | Location out, |
| 6905 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6906 | DCHECK(kEmitCompilerReadBarrier); |
| 6907 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6908 | // Insert a slow path based read barrier *after* the GC root load. |
| 6909 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6910 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6911 | // not need to do anything special for this here. |
| 6912 | SlowPathCode* slow_path = |
| 6913 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6914 | AddSlowPath(slow_path); |
| 6915 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6916 | __ jmp(slow_path->GetEntryLabel()); |
| 6917 | __ Bind(slow_path->GetExitLabel()); |
| 6918 | } |
| 6919 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6920 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6921 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6922 | LOG(FATAL) << "Unreachable"; |
| 6923 | } |
| 6924 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6925 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6926 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6927 | LOG(FATAL) << "Unreachable"; |
| 6928 | } |
| 6929 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6930 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6931 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6932 | LocationSummary* locations = |
| 6933 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6934 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6935 | } |
| 6936 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6937 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6938 | int32_t lower_bound, |
| 6939 | uint32_t num_entries, |
| 6940 | HBasicBlock* switch_block, |
| 6941 | HBasicBlock* default_block) { |
| 6942 | // Figure out the correct compare values and jump conditions. |
| 6943 | // Handle the first compare/branch as a special case because it might |
| 6944 | // jump to the default case. |
| 6945 | DCHECK_GT(num_entries, 2u); |
| 6946 | Condition first_condition; |
| 6947 | uint32_t index; |
| 6948 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6949 | if (lower_bound != 0) { |
| 6950 | first_condition = kLess; |
| 6951 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6952 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6953 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6954 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6955 | index = 1; |
| 6956 | } else { |
| 6957 | // Handle all the compare/jumps below. |
| 6958 | first_condition = kBelow; |
| 6959 | index = 0; |
| 6960 | } |
| 6961 | |
| 6962 | // Handle the rest of the compare/jumps. |
| 6963 | for (; index + 1 < num_entries; index += 2) { |
| 6964 | int32_t compare_to_value = lower_bound + index + 1; |
| 6965 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6966 | // Jump to successors[index] if value < case_value[index]. |
| 6967 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6968 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6969 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6970 | } |
| 6971 | |
| 6972 | if (index != num_entries) { |
| 6973 | // There are an odd number of entries. Handle the last one. |
| 6974 | DCHECK_EQ(index + 1, num_entries); |
| 6975 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6976 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6980 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6981 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6982 | } |
| 6983 | } |
| 6984 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6985 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6986 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6987 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6988 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6989 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6990 | |
| 6991 | GenPackedSwitchWithCompares(value_reg, |
| 6992 | lower_bound, |
| 6993 | num_entries, |
| 6994 | switch_instr->GetBlock(), |
| 6995 | switch_instr->GetDefaultBlock()); |
| 6996 | } |
| 6997 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6998 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6999 | LocationSummary* locations = |
| 7000 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7001 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7002 | |
| 7003 | // Constant area pointer. |
| 7004 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7005 | |
| 7006 | // And the temporary we need. |
| 7007 | locations->AddTemp(Location::RequiresRegister()); |
| 7008 | } |
| 7009 | |
| 7010 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7011 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7012 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7013 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7014 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7015 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7016 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7017 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7018 | GenPackedSwitchWithCompares(value_reg, |
| 7019 | lower_bound, |
| 7020 | num_entries, |
| 7021 | switch_instr->GetBlock(), |
| 7022 | default_block); |
| 7023 | return; |
| 7024 | } |
| 7025 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7026 | // Optimizing has a jump area. |
| 7027 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7028 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7029 | |
| 7030 | // Remove the bias, if needed. |
| 7031 | if (lower_bound != 0) { |
| 7032 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7033 | value_reg = temp_reg; |
| 7034 | } |
| 7035 | |
| 7036 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7037 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7038 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7039 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7040 | |
| 7041 | // We are in the range of the table. |
| 7042 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7043 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7044 | |
| 7045 | // Compute the actual target address by adding in constant_area. |
| 7046 | __ addl(temp_reg, constant_area); |
| 7047 | |
| 7048 | // And jump. |
| 7049 | __ jmp(temp_reg); |
| 7050 | } |
| 7051 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7052 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7053 | HX86ComputeBaseMethodAddress* insn) { |
| 7054 | LocationSummary* locations = |
| 7055 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7056 | locations->SetOut(Location::RequiresRegister()); |
| 7057 | } |
| 7058 | |
| 7059 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7060 | HX86ComputeBaseMethodAddress* insn) { |
| 7061 | LocationSummary* locations = insn->GetLocations(); |
| 7062 | Register reg = locations->Out().AsRegister<Register>(); |
| 7063 | |
| 7064 | // Generate call to next instruction. |
| 7065 | Label next_instruction; |
| 7066 | __ call(&next_instruction); |
| 7067 | __ Bind(&next_instruction); |
| 7068 | |
| 7069 | // Remember this offset for later use with constant area. |
| 7070 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7071 | |
| 7072 | // Grab the return address off the stack. |
| 7073 | __ popl(reg); |
| 7074 | } |
| 7075 | |
| 7076 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7077 | HX86LoadFromConstantTable* insn) { |
| 7078 | LocationSummary* locations = |
| 7079 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7080 | |
| 7081 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7082 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7083 | |
| 7084 | // 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] | 7085 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7086 | return; |
| 7087 | } |
| 7088 | |
| 7089 | switch (insn->GetType()) { |
| 7090 | case Primitive::kPrimFloat: |
| 7091 | case Primitive::kPrimDouble: |
| 7092 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7093 | break; |
| 7094 | |
| 7095 | case Primitive::kPrimInt: |
| 7096 | locations->SetOut(Location::RequiresRegister()); |
| 7097 | break; |
| 7098 | |
| 7099 | default: |
| 7100 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7101 | } |
| 7102 | } |
| 7103 | |
| 7104 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7105 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7106 | return; |
| 7107 | } |
| 7108 | |
| 7109 | LocationSummary* locations = insn->GetLocations(); |
| 7110 | Location out = locations->Out(); |
| 7111 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7112 | HConstant *value = insn->GetConstant(); |
| 7113 | |
| 7114 | switch (insn->GetType()) { |
| 7115 | case Primitive::kPrimFloat: |
| 7116 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7117 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7118 | break; |
| 7119 | |
| 7120 | case Primitive::kPrimDouble: |
| 7121 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7122 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7123 | break; |
| 7124 | |
| 7125 | case Primitive::kPrimInt: |
| 7126 | __ movl(out.AsRegister<Register>(), |
| 7127 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7128 | break; |
| 7129 | |
| 7130 | default: |
| 7131 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7132 | } |
| 7133 | } |
| 7134 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7135 | /** |
| 7136 | * Class to handle late fixup of offsets into constant area. |
| 7137 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7138 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7139 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7140 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7141 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7142 | |
| 7143 | protected: |
| 7144 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7145 | |
| 7146 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7147 | |
| 7148 | private: |
| 7149 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7150 | // Patch the correct offset for the instruction. The place to patch is the |
| 7151 | // last 4 bytes of the instruction. |
| 7152 | // The value to patch is the distance from the offset in the constant area |
| 7153 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7154 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7155 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7156 | |
| 7157 | // Patch in the right value. |
| 7158 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7159 | } |
| 7160 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7161 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7162 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7163 | }; |
| 7164 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7165 | /** |
| 7166 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7167 | * constant area. |
| 7168 | */ |
| 7169 | class JumpTableRIPFixup : public RIPFixup { |
| 7170 | public: |
| 7171 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7172 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7173 | |
| 7174 | void CreateJumpTable() { |
| 7175 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7176 | |
| 7177 | // Ensure that the reference to the jump table has the correct offset. |
| 7178 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7179 | SetOffset(offset_in_constant_table); |
| 7180 | |
| 7181 | // The label values in the jump table are computed relative to the |
| 7182 | // instruction addressing the constant area. |
| 7183 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7184 | |
| 7185 | // Populate the jump table with the correct values for the jump table. |
| 7186 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7187 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7188 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7189 | // The value that we want is the target offset - the position of the table. |
| 7190 | for (int32_t i = 0; i < num_entries; i++) { |
| 7191 | HBasicBlock* b = successors[i]; |
| 7192 | Label* l = codegen_->GetLabelOf(b); |
| 7193 | DCHECK(l->IsBound()); |
| 7194 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7195 | assembler->AppendInt32(offset_to_block); |
| 7196 | } |
| 7197 | } |
| 7198 | |
| 7199 | private: |
| 7200 | const HX86PackedSwitch* switch_instr_; |
| 7201 | }; |
| 7202 | |
| 7203 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7204 | // Generate the constant area if needed. |
| 7205 | X86Assembler* assembler = GetAssembler(); |
| 7206 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7207 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7208 | // byte values. |
| 7209 | assembler->Align(4, 0); |
| 7210 | constant_area_start_ = assembler->CodeSize(); |
| 7211 | |
| 7212 | // Populate any jump tables. |
| 7213 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7214 | jump_table->CreateJumpTable(); |
| 7215 | } |
| 7216 | |
| 7217 | // And now add the constant area to the generated code. |
| 7218 | assembler->AddConstantArea(); |
| 7219 | } |
| 7220 | |
| 7221 | // And finish up. |
| 7222 | CodeGenerator::Finalize(allocator); |
| 7223 | } |
| 7224 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7225 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7226 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7227 | return Address(reg, kDummy32BitOffset, fixup); |
| 7228 | } |
| 7229 | |
| 7230 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7231 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7232 | return Address(reg, kDummy32BitOffset, fixup); |
| 7233 | } |
| 7234 | |
| 7235 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7236 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7237 | return Address(reg, kDummy32BitOffset, fixup); |
| 7238 | } |
| 7239 | |
| 7240 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7241 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7242 | return Address(reg, kDummy32BitOffset, fixup); |
| 7243 | } |
| 7244 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7245 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7246 | if (value == 0) { |
| 7247 | __ xorl(dest, dest); |
| 7248 | } else { |
| 7249 | __ movl(dest, Immediate(value)); |
| 7250 | } |
| 7251 | } |
| 7252 | |
| 7253 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7254 | if (value == 0) { |
| 7255 | __ testl(dest, dest); |
| 7256 | } else { |
| 7257 | __ cmpl(dest, Immediate(value)); |
| 7258 | } |
| 7259 | } |
| 7260 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7261 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7262 | Register reg, |
| 7263 | Register value) { |
| 7264 | // Create a fixup to be used to create and address the jump table. |
| 7265 | JumpTableRIPFixup* table_fixup = |
| 7266 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7267 | |
| 7268 | // We have to populate the jump tables. |
| 7269 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7270 | |
| 7271 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7272 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7273 | } |
| 7274 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7275 | // TODO: target as memory. |
| 7276 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7277 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7278 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7279 | return; |
| 7280 | } |
| 7281 | |
| 7282 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7283 | |
| 7284 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7285 | if (target.Equals(return_loc)) { |
| 7286 | return; |
| 7287 | } |
| 7288 | |
| 7289 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7290 | // with the else branch. |
| 7291 | if (type == Primitive::kPrimLong) { |
| 7292 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7293 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7294 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7295 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7296 | } else { |
| 7297 | // Let the parallel move resolver take care of all of this. |
| 7298 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7299 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7300 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7301 | } |
| 7302 | } |
| 7303 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7304 | #undef __ |
| 7305 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7306 | } // namespace x86 |
| 7307 | } // namespace art |