Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 29 | #include "pc_relative_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace x86 { |
| 42 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 47 | static constexpr int kC2ConditionMask = 0x400; |
| 48 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 49 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 50 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 54 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 58 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 61 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 62 | // Live registers will be restored in the catch block if caught. |
| 63 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 64 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 77 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 79 | }; |
| 80 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 81 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | public: |
| 83 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 84 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 85 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 86 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 88 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 89 | // Live registers will be restored in the catch block if caught. |
| 90 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 91 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 93 | instruction_, |
| 94 | instruction_->GetDexPc(), |
| 95 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 96 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 99 | bool IsFatal() const OVERRIDE { return true; } |
| 100 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 101 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | private: |
| 104 | HDivZeroCheck* const instruction_; |
| 105 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 106 | }; |
| 107 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 108 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 110 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 112 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | if (is_div_) { |
| 115 | __ negl(reg_); |
| 116 | } else { |
| 117 | __ movl(reg_, Immediate(0)); |
| 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
| 125 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | bool is_div_; |
| 127 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 130 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 132 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 134 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 135 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 136 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 137 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 138 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 139 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 140 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 141 | // Live registers will be restored in the catch block if caught. |
| 142 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 145 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 146 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 147 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 148 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 149 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 150 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 151 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 152 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 153 | instruction_, |
| 154 | instruction_->GetDexPc(), |
| 155 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 156 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 159 | bool IsFatal() const OVERRIDE { return true; } |
| 160 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 162 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 163 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 164 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 165 | |
| 166 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 167 | }; |
| 168 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 169 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 171 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 172 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 174 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 175 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 176 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 177 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 178 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 179 | instruction_, |
| 180 | instruction_->GetDexPc(), |
| 181 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 182 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 183 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 184 | if (successor_ == nullptr) { |
| 185 | __ jmp(GetReturnLabel()); |
| 186 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 187 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 188 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 191 | Label* GetReturnLabel() { |
| 192 | DCHECK(successor_ == nullptr); |
| 193 | return &return_label_; |
| 194 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 195 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 196 | HBasicBlock* GetSuccessor() const { |
| 197 | return successor_; |
| 198 | } |
| 199 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 200 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 201 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | private: |
| 203 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 204 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | Label return_label_; |
| 206 | |
| 207 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 208 | }; |
| 209 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 210 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 211 | public: |
| 212 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 213 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 214 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | LocationSummary* locations = instruction_->GetLocations(); |
| 216 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 217 | |
| 218 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 219 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 220 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 221 | |
| 222 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 223 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 224 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 225 | instruction_, |
| 226 | instruction_->GetDexPc(), |
| 227 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 228 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 229 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 230 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 231 | |
| 232 | __ jmp(GetExitLabel()); |
| 233 | } |
| 234 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 235 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 236 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 237 | private: |
| 238 | HLoadString* const instruction_; |
| 239 | |
| 240 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 241 | }; |
| 242 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 243 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | public: |
| 245 | LoadClassSlowPathX86(HLoadClass* cls, |
| 246 | HInstruction* at, |
| 247 | uint32_t dex_pc, |
| 248 | bool do_clinit) |
| 249 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 250 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 251 | } |
| 252 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 254 | LocationSummary* locations = at_->GetLocations(); |
| 255 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 256 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 257 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | |
| 259 | InvokeRuntimeCallingConvention calling_convention; |
| 260 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 261 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 262 | : QUICK_ENTRY_POINT(pInitializeType), |
| 263 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 264 | if (do_clinit_) { |
| 265 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 266 | } else { |
| 267 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 268 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | |
| 270 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 271 | Location out = locations->Out(); |
| 272 | if (out.IsValid()) { |
| 273 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 274 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 275 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 277 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 278 | __ jmp(GetExitLabel()); |
| 279 | } |
| 280 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 282 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | private: |
| 284 | // The class this slow path will load. |
| 285 | HLoadClass* const cls_; |
| 286 | |
| 287 | // The instruction where this slow path is happening. |
| 288 | // (Might be the load class or an initialization check). |
| 289 | HInstruction* const at_; |
| 290 | |
| 291 | // The dex PC of `at_`. |
| 292 | const uint32_t dex_pc_; |
| 293 | |
| 294 | // Whether to initialize the class. |
| 295 | const bool do_clinit_; |
| 296 | |
| 297 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 298 | }; |
| 299 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 300 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 302 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 303 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 305 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 307 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 308 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 309 | DCHECK(instruction_->IsCheckCast() |
| 310 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | |
| 312 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 313 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 314 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 315 | if (!is_fatal_) { |
| 316 | SaveLiveRegisters(codegen, locations); |
| 317 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 318 | |
| 319 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 320 | // move resolver. |
| 321 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 322 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 324 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 325 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 326 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 327 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 328 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 331 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 332 | instruction_, |
| 333 | instruction_->GetDexPc(), |
| 334 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 335 | CheckEntrypointTypes< |
| 336 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | } else { |
| 338 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 339 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 340 | instruction_, |
| 341 | instruction_->GetDexPc(), |
| 342 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 343 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | if (!is_fatal_) { |
| 347 | if (instruction_->IsInstanceOf()) { |
| 348 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 349 | } |
| 350 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 351 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 352 | __ jmp(GetExitLabel()); |
| 353 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 356 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 358 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 362 | |
| 363 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 364 | }; |
| 365 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 366 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 367 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 368 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 369 | : instruction_(instruction) {} |
| 370 | |
| 371 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 372 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 373 | __ Bind(GetEntryLabel()); |
| 374 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 375 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 376 | instruction_, |
| 377 | instruction_->GetDexPc(), |
| 378 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 379 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 383 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 385 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 387 | }; |
| 388 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 389 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 390 | public: |
| 391 | explicit ArraySetSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
| 392 | |
| 393 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 394 | LocationSummary* locations = instruction_->GetLocations(); |
| 395 | __ Bind(GetEntryLabel()); |
| 396 | SaveLiveRegisters(codegen, locations); |
| 397 | |
| 398 | InvokeRuntimeCallingConvention calling_convention; |
| 399 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 400 | parallel_move.AddMove( |
| 401 | locations->InAt(0), |
| 402 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 403 | Primitive::kPrimNot, |
| 404 | nullptr); |
| 405 | parallel_move.AddMove( |
| 406 | locations->InAt(1), |
| 407 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 408 | Primitive::kPrimInt, |
| 409 | nullptr); |
| 410 | parallel_move.AddMove( |
| 411 | locations->InAt(2), |
| 412 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 413 | Primitive::kPrimNot, |
| 414 | nullptr); |
| 415 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 416 | |
| 417 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 418 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 419 | instruction_, |
| 420 | instruction_->GetDexPc(), |
| 421 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 422 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 423 | RestoreLiveRegisters(codegen, locations); |
| 424 | __ jmp(GetExitLabel()); |
| 425 | } |
| 426 | |
| 427 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 428 | |
| 429 | private: |
| 430 | HInstruction* const instruction_; |
| 431 | |
| 432 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 433 | }; |
| 434 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 435 | // Slow path marking an object during a read barrier. |
| 436 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 437 | public: |
| 438 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
| 439 | : instruction_(instruction), out_(out), obj_(obj) { |
| 440 | DCHECK(kEmitCompilerReadBarrier); |
| 441 | } |
| 442 | |
| 443 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 444 | |
| 445 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 446 | LocationSummary* locations = instruction_->GetLocations(); |
| 447 | Register reg_out = out_.AsRegister<Register>(); |
| 448 | DCHECK(locations->CanCall()); |
| 449 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 450 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 451 | instruction_->IsStaticFieldGet() || |
| 452 | instruction_->IsArrayGet() || |
| 453 | instruction_->IsLoadClass() || |
| 454 | instruction_->IsLoadString() || |
| 455 | instruction_->IsInstanceOf() || |
| 456 | instruction_->IsCheckCast()) |
| 457 | << "Unexpected instruction in read barrier marking slow path: " |
| 458 | << instruction_->DebugName(); |
| 459 | |
| 460 | __ Bind(GetEntryLabel()); |
| 461 | SaveLiveRegisters(codegen, locations); |
| 462 | |
| 463 | InvokeRuntimeCallingConvention calling_convention; |
| 464 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 465 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 466 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 467 | instruction_, |
| 468 | instruction_->GetDexPc(), |
| 469 | this); |
| 470 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 471 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 472 | |
| 473 | RestoreLiveRegisters(codegen, locations); |
| 474 | __ jmp(GetExitLabel()); |
| 475 | } |
| 476 | |
| 477 | private: |
| 478 | HInstruction* const instruction_; |
| 479 | const Location out_; |
| 480 | const Location obj_; |
| 481 | |
| 482 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 483 | }; |
| 484 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 485 | // Slow path generating a read barrier for a heap reference. |
| 486 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 487 | public: |
| 488 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 489 | Location out, |
| 490 | Location ref, |
| 491 | Location obj, |
| 492 | uint32_t offset, |
| 493 | Location index) |
| 494 | : instruction_(instruction), |
| 495 | out_(out), |
| 496 | ref_(ref), |
| 497 | obj_(obj), |
| 498 | offset_(offset), |
| 499 | index_(index) { |
| 500 | DCHECK(kEmitCompilerReadBarrier); |
| 501 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 502 | // has been overwritten by (or after) the heap object reference load |
| 503 | // to be instrumented, e.g.: |
| 504 | // |
| 505 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 507 | // |
| 508 | // In that case, we have lost the information about the original |
| 509 | // object, and the emitted read barrier cannot work properly. |
| 510 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 511 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 512 | } |
| 513 | |
| 514 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 515 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 516 | LocationSummary* locations = instruction_->GetLocations(); |
| 517 | Register reg_out = out_.AsRegister<Register>(); |
| 518 | DCHECK(locations->CanCall()); |
| 519 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 520 | DCHECK(!instruction_->IsInvoke() || |
| 521 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 522 | instruction_->GetLocations()->Intrinsified())) |
| 523 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 524 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 525 | |
| 526 | __ Bind(GetEntryLabel()); |
| 527 | SaveLiveRegisters(codegen, locations); |
| 528 | |
| 529 | // We may have to change the index's value, but as `index_` is a |
| 530 | // constant member (like other "inputs" of this slow path), |
| 531 | // introduce a copy of it, `index`. |
| 532 | Location index = index_; |
| 533 | if (index_.IsValid()) { |
| 534 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 535 | if (instruction_->IsArrayGet()) { |
| 536 | // Compute the actual memory offset and store it in `index`. |
| 537 | Register index_reg = index_.AsRegister<Register>(); |
| 538 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 539 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 540 | // We are about to change the value of `index_reg` (see the |
| 541 | // calls to art::x86::X86Assembler::shll and |
| 542 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 543 | // not been saved by the previous call to |
| 544 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 545 | // callee-save register -- |
| 546 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 547 | // callee-save registers, as it has been designed with the |
| 548 | // assumption that callee-save registers are supposed to be |
| 549 | // handled by the called function. So, as a callee-save |
| 550 | // register, `index_reg` _would_ eventually be saved onto |
| 551 | // the stack, but it would be too late: we would have |
| 552 | // changed its value earlier. Therefore, we manually save |
| 553 | // it here into another freely available register, |
| 554 | // `free_reg`, chosen of course among the caller-save |
| 555 | // registers (as a callee-save `free_reg` register would |
| 556 | // exhibit the same problem). |
| 557 | // |
| 558 | // Note we could have requested a temporary register from |
| 559 | // the register allocator instead; but we prefer not to, as |
| 560 | // this is a slow path, and we know we can find a |
| 561 | // caller-save register that is available. |
| 562 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 563 | __ movl(free_reg, index_reg); |
| 564 | index_reg = free_reg; |
| 565 | index = Location::RegisterLocation(index_reg); |
| 566 | } else { |
| 567 | // The initial register stored in `index_` has already been |
| 568 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 569 | // (as it is not a callee-save register), so we can freely |
| 570 | // use it. |
| 571 | } |
| 572 | // Shifting the index value contained in `index_reg` by the scale |
| 573 | // factor (2) cannot overflow in practice, as the runtime is |
| 574 | // unable to allocate object arrays with a size larger than |
| 575 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 576 | __ shll(index_reg, Immediate(TIMES_4)); |
| 577 | static_assert( |
| 578 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 579 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 580 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 581 | } else { |
| 582 | DCHECK(instruction_->IsInvoke()); |
| 583 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 584 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 585 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 586 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 587 | DCHECK_EQ(offset_, 0U); |
| 588 | DCHECK(index_.IsRegisterPair()); |
| 589 | // UnsafeGet's offset location is a register pair, the low |
| 590 | // part contains the correct offset. |
| 591 | index = index_.ToLow(); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | // We're moving two or three locations to locations that could |
| 596 | // overlap, so we need a parallel move resolver. |
| 597 | InvokeRuntimeCallingConvention calling_convention; |
| 598 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 599 | parallel_move.AddMove(ref_, |
| 600 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 601 | Primitive::kPrimNot, |
| 602 | nullptr); |
| 603 | parallel_move.AddMove(obj_, |
| 604 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 605 | Primitive::kPrimNot, |
| 606 | nullptr); |
| 607 | if (index.IsValid()) { |
| 608 | parallel_move.AddMove(index, |
| 609 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 610 | Primitive::kPrimInt, |
| 611 | nullptr); |
| 612 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 613 | } else { |
| 614 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 615 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 616 | } |
| 617 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 618 | instruction_, |
| 619 | instruction_->GetDexPc(), |
| 620 | this); |
| 621 | CheckEntrypointTypes< |
| 622 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 623 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 624 | |
| 625 | RestoreLiveRegisters(codegen, locations); |
| 626 | __ jmp(GetExitLabel()); |
| 627 | } |
| 628 | |
| 629 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 630 | |
| 631 | private: |
| 632 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 633 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 634 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 635 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 636 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 637 | return static_cast<Register>(i); |
| 638 | } |
| 639 | } |
| 640 | // We shall never fail to find a free caller-save register, as |
| 641 | // there are more than two core caller-save registers on x86 |
| 642 | // (meaning it is possible to find one which is different from |
| 643 | // `ref` and `obj`). |
| 644 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 645 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 646 | UNREACHABLE(); |
| 647 | } |
| 648 | |
| 649 | HInstruction* const instruction_; |
| 650 | const Location out_; |
| 651 | const Location ref_; |
| 652 | const Location obj_; |
| 653 | const uint32_t offset_; |
| 654 | // An additional location containing an index to an array. |
| 655 | // Only used for HArrayGet and the UnsafeGetObject & |
| 656 | // UnsafeGetObjectVolatile intrinsics. |
| 657 | const Location index_; |
| 658 | |
| 659 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 660 | }; |
| 661 | |
| 662 | // Slow path generating a read barrier for a GC root. |
| 663 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 664 | public: |
| 665 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 666 | : instruction_(instruction), out_(out), root_(root) { |
| 667 | DCHECK(kEmitCompilerReadBarrier); |
| 668 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 669 | |
| 670 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 671 | LocationSummary* locations = instruction_->GetLocations(); |
| 672 | Register reg_out = out_.AsRegister<Register>(); |
| 673 | DCHECK(locations->CanCall()); |
| 674 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 675 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 676 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 677 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 678 | |
| 679 | __ Bind(GetEntryLabel()); |
| 680 | SaveLiveRegisters(codegen, locations); |
| 681 | |
| 682 | InvokeRuntimeCallingConvention calling_convention; |
| 683 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 684 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 685 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 686 | instruction_, |
| 687 | instruction_->GetDexPc(), |
| 688 | this); |
| 689 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 690 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 691 | |
| 692 | RestoreLiveRegisters(codegen, locations); |
| 693 | __ jmp(GetExitLabel()); |
| 694 | } |
| 695 | |
| 696 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 697 | |
| 698 | private: |
| 699 | HInstruction* const instruction_; |
| 700 | const Location out_; |
| 701 | const Location root_; |
| 702 | |
| 703 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 704 | }; |
| 705 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 706 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 707 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 708 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 709 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 710 | switch (cond) { |
| 711 | case kCondEQ: return kEqual; |
| 712 | case kCondNE: return kNotEqual; |
| 713 | case kCondLT: return kLess; |
| 714 | case kCondLE: return kLessEqual; |
| 715 | case kCondGT: return kGreater; |
| 716 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 717 | case kCondB: return kBelow; |
| 718 | case kCondBE: return kBelowEqual; |
| 719 | case kCondA: return kAbove; |
| 720 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 721 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 722 | LOG(FATAL) << "Unreachable"; |
| 723 | UNREACHABLE(); |
| 724 | } |
| 725 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 726 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 727 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 728 | switch (cond) { |
| 729 | case kCondEQ: return kEqual; |
| 730 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 731 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 732 | case kCondLT: return kBelow; |
| 733 | case kCondLE: return kBelowEqual; |
| 734 | case kCondGT: return kAbove; |
| 735 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 736 | // Unsigned remain unchanged. |
| 737 | case kCondB: return kBelow; |
| 738 | case kCondBE: return kBelowEqual; |
| 739 | case kCondA: return kAbove; |
| 740 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 741 | } |
| 742 | LOG(FATAL) << "Unreachable"; |
| 743 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 746 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 747 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 751 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 752 | } |
| 753 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 754 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 755 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 756 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 757 | } |
| 758 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 759 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 760 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 761 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 764 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 765 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 766 | return GetFloatingPointSpillSlotSize(); |
| 767 | } |
| 768 | |
| 769 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 770 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 771 | return GetFloatingPointSpillSlotSize(); |
| 772 | } |
| 773 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 774 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 775 | HInstruction* instruction, |
| 776 | uint32_t dex_pc, |
| 777 | SlowPathCode* slow_path) { |
| 778 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 779 | instruction, |
| 780 | dex_pc, |
| 781 | slow_path); |
| 782 | } |
| 783 | |
| 784 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 785 | HInstruction* instruction, |
| 786 | uint32_t dex_pc, |
| 787 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 788 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 789 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 790 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 791 | } |
| 792 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 793 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 794 | const X86InstructionSetFeatures& isa_features, |
| 795 | const CompilerOptions& compiler_options, |
| 796 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 797 | : CodeGenerator(graph, |
| 798 | kNumberOfCpuRegisters, |
| 799 | kNumberOfXmmRegisters, |
| 800 | kNumberOfRegisterPairs, |
| 801 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 802 | arraysize(kCoreCalleeSaves)) |
| 803 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 804 | 0, |
| 805 | compiler_options, |
| 806 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 807 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 808 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 809 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 810 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 811 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 812 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 813 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 814 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 815 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 816 | // Use a fake return address register to mimic Quick. |
| 817 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 818 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 819 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 820 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 821 | switch (type) { |
| 822 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 823 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 824 | X86ManagedRegister pair = |
| 825 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 826 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 827 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 828 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 829 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 830 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 831 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | case Primitive::kPrimByte: |
| 835 | case Primitive::kPrimBoolean: |
| 836 | case Primitive::kPrimChar: |
| 837 | case Primitive::kPrimShort: |
| 838 | case Primitive::kPrimInt: |
| 839 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 840 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 841 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 842 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 843 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 844 | X86ManagedRegister current = |
| 845 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 846 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 847 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 848 | } |
| 849 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 850 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 854 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 855 | return Location::FpuRegisterLocation( |
| 856 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 857 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 858 | |
| 859 | case Primitive::kPrimVoid: |
| 860 | LOG(FATAL) << "Unreachable type " << type; |
| 861 | } |
| 862 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 863 | return Location::NoLocation(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 864 | } |
| 865 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 866 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 867 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 868 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 869 | |
| 870 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 871 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 872 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 873 | if (is_baseline) { |
| 874 | blocked_core_registers_[EBP] = true; |
| 875 | blocked_core_registers_[ESI] = true; |
| 876 | blocked_core_registers_[EDI] = true; |
| 877 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 878 | |
| 879 | UpdateBlockedPairRegisters(); |
| 880 | } |
| 881 | |
| 882 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 883 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 884 | X86ManagedRegister current = |
| 885 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 886 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 887 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 888 | blocked_register_pairs_[i] = true; |
| 889 | } |
| 890 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 893 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 894 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 895 | assembler_(codegen->GetAssembler()), |
| 896 | codegen_(codegen) {} |
| 897 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 898 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 899 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 902 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 903 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 904 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 905 | bool skip_overflow_check = |
| 906 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 907 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 908 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 909 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 910 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 911 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 912 | } |
| 913 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 914 | if (HasEmptyFrame()) { |
| 915 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 916 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 917 | |
| 918 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 919 | Register reg = kCoreCalleeSaves[i]; |
| 920 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 921 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 922 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 923 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 924 | } |
| 925 | } |
| 926 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 927 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 928 | __ subl(ESP, Immediate(adjust)); |
| 929 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 930 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 934 | __ cfi().RememberState(); |
| 935 | if (!HasEmptyFrame()) { |
| 936 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 937 | __ addl(ESP, Immediate(adjust)); |
| 938 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 939 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 940 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 941 | Register reg = kCoreCalleeSaves[i]; |
| 942 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 943 | __ popl(reg); |
| 944 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 945 | __ cfi().Restore(DWARFReg(reg)); |
| 946 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 947 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 948 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 949 | __ ret(); |
| 950 | __ cfi().RestoreState(); |
| 951 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 954 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 955 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 958 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 959 | switch (load->GetType()) { |
| 960 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 961 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 962 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 963 | |
| 964 | case Primitive::kPrimInt: |
| 965 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 966 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 967 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 968 | |
| 969 | case Primitive::kPrimBoolean: |
| 970 | case Primitive::kPrimByte: |
| 971 | case Primitive::kPrimChar: |
| 972 | case Primitive::kPrimShort: |
| 973 | case Primitive::kPrimVoid: |
| 974 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 975 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 979 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 980 | } |
| 981 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 982 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 983 | switch (type) { |
| 984 | case Primitive::kPrimBoolean: |
| 985 | case Primitive::kPrimByte: |
| 986 | case Primitive::kPrimChar: |
| 987 | case Primitive::kPrimShort: |
| 988 | case Primitive::kPrimInt: |
| 989 | case Primitive::kPrimNot: |
| 990 | return Location::RegisterLocation(EAX); |
| 991 | |
| 992 | case Primitive::kPrimLong: |
| 993 | return Location::RegisterPairLocation(EAX, EDX); |
| 994 | |
| 995 | case Primitive::kPrimVoid: |
| 996 | return Location::NoLocation(); |
| 997 | |
| 998 | case Primitive::kPrimDouble: |
| 999 | case Primitive::kPrimFloat: |
| 1000 | return Location::FpuRegisterLocation(XMM0); |
| 1001 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1002 | |
| 1003 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1007 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1008 | } |
| 1009 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1010 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1011 | switch (type) { |
| 1012 | case Primitive::kPrimBoolean: |
| 1013 | case Primitive::kPrimByte: |
| 1014 | case Primitive::kPrimChar: |
| 1015 | case Primitive::kPrimShort: |
| 1016 | case Primitive::kPrimInt: |
| 1017 | case Primitive::kPrimNot: { |
| 1018 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1019 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1020 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1021 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1022 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1023 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1024 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1025 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1026 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1027 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1028 | uint32_t index = gp_index_; |
| 1029 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1030 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1031 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1032 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1033 | calling_convention.GetRegisterPairAt(index)); |
| 1034 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1035 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1036 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1041 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1042 | stack_index_++; |
| 1043 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1044 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1045 | } else { |
| 1046 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1051 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1052 | stack_index_ += 2; |
| 1053 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1054 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1055 | } else { |
| 1056 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1060 | case Primitive::kPrimVoid: |
| 1061 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1062 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1063 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1064 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1065 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1066 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1067 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1068 | if (source.Equals(destination)) { |
| 1069 | return; |
| 1070 | } |
| 1071 | if (destination.IsRegister()) { |
| 1072 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1073 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1074 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1075 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1076 | } else { |
| 1077 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1078 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1079 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1080 | } else if (destination.IsFpuRegister()) { |
| 1081 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1082 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1083 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1084 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1085 | } else { |
| 1086 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1087 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1088 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1089 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1090 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1091 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1092 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1093 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1094 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1095 | } else if (source.IsConstant()) { |
| 1096 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1097 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1098 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1099 | } else { |
| 1100 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1101 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1102 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1108 | if (source.Equals(destination)) { |
| 1109 | return; |
| 1110 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1111 | if (destination.IsRegisterPair()) { |
| 1112 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1113 | EmitParallelMoves( |
| 1114 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1115 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1116 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1117 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1118 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1119 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1120 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1121 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1122 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1123 | __ psrlq(src_reg, Immediate(32)); |
| 1124 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1125 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1126 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1127 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1128 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1129 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1130 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1131 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1132 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1133 | if (source.IsFpuRegister()) { |
| 1134 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1135 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1136 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1137 | } else if (source.IsRegisterPair()) { |
| 1138 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1139 | // Create stack space for 2 elements. |
| 1140 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1141 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1142 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1143 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1144 | // And remove the temporary stack space we allocated. |
| 1145 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1146 | } else { |
| 1147 | LOG(FATAL) << "Unimplemented"; |
| 1148 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1149 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1150 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1151 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1152 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1153 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1154 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1155 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1156 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1157 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1158 | } else if (source.IsConstant()) { |
| 1159 | HConstant* constant = source.GetConstant(); |
| 1160 | int64_t value; |
| 1161 | if (constant->IsLongConstant()) { |
| 1162 | value = constant->AsLongConstant()->GetValue(); |
| 1163 | } else { |
| 1164 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1165 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1166 | } |
| 1167 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1168 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1169 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1170 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1171 | EmitParallelMoves( |
| 1172 | Location::StackSlot(source.GetStackIndex()), |
| 1173 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1174 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1175 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1176 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1177 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1182 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1183 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1184 | if (instruction->IsCurrentMethod()) { |
| 1185 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1186 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1187 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1188 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1189 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1190 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1191 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1192 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1193 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1194 | } else if (location.IsStackSlot()) { |
| 1195 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 1196 | } else { |
| 1197 | DCHECK(location.IsConstant()); |
| 1198 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1199 | } |
| 1200 | } else if (const_to_move->IsLongConstant()) { |
| 1201 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1202 | if (location.IsRegisterPair()) { |
| 1203 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 1204 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 1205 | } else if (location.IsDoubleStackSlot()) { |
| 1206 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1207 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 1208 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1209 | } else { |
| 1210 | DCHECK(location.IsConstant()); |
| 1211 | DCHECK_EQ(location.GetConstant(), instruction); |
| 1212 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1213 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1214 | } else if (instruction->IsTemporary()) { |
| 1215 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1216 | if (temp_location.IsStackSlot()) { |
| 1217 | Move32(location, temp_location); |
| 1218 | } else { |
| 1219 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1220 | Move64(location, temp_location); |
| 1221 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1222 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1223 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1224 | switch (instruction->GetType()) { |
| 1225 | case Primitive::kPrimBoolean: |
| 1226 | case Primitive::kPrimByte: |
| 1227 | case Primitive::kPrimChar: |
| 1228 | case Primitive::kPrimShort: |
| 1229 | case Primitive::kPrimInt: |
| 1230 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1231 | case Primitive::kPrimFloat: |
| 1232 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1233 | break; |
| 1234 | |
| 1235 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1236 | case Primitive::kPrimDouble: |
| 1237 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1238 | break; |
| 1239 | |
| 1240 | default: |
| 1241 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 1242 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1243 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1244 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | switch (instruction->GetType()) { |
| 1246 | case Primitive::kPrimBoolean: |
| 1247 | case Primitive::kPrimByte: |
| 1248 | case Primitive::kPrimChar: |
| 1249 | case Primitive::kPrimShort: |
| 1250 | case Primitive::kPrimInt: |
| 1251 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1253 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1254 | break; |
| 1255 | |
| 1256 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1257 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1258 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1259 | break; |
| 1260 | |
| 1261 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1262 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1263 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1267 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1268 | DCHECK(location.IsRegister()); |
| 1269 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1270 | } |
| 1271 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1272 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1273 | if (Primitive::Is64BitType(dst_type)) { |
| 1274 | Move64(dst, src); |
| 1275 | } else { |
| 1276 | Move32(dst, src); |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1281 | if (location.IsRegister()) { |
| 1282 | locations->AddTemp(location); |
| 1283 | } else if (location.IsRegisterPair()) { |
| 1284 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1285 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1286 | } else { |
| 1287 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1288 | } |
| 1289 | } |
| 1290 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1291 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1292 | DCHECK(!successor->IsExitBlock()); |
| 1293 | |
| 1294 | HBasicBlock* block = got->GetBlock(); |
| 1295 | HInstruction* previous = got->GetPrevious(); |
| 1296 | |
| 1297 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1298 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1299 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1300 | return; |
| 1301 | } |
| 1302 | |
| 1303 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1304 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1305 | } |
| 1306 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1307 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1311 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1312 | got->SetLocations(nullptr); |
| 1313 | } |
| 1314 | |
| 1315 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1316 | HandleGoto(got, got->GetSuccessor()); |
| 1317 | } |
| 1318 | |
| 1319 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1320 | try_boundary->SetLocations(nullptr); |
| 1321 | } |
| 1322 | |
| 1323 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1324 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1325 | if (!successor->IsExitBlock()) { |
| 1326 | HandleGoto(try_boundary, successor); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1330 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1331 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1334 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1337 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1338 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1339 | LabelType* true_label, |
| 1340 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1341 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1342 | __ j(kUnordered, true_label); |
| 1343 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1344 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1346 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1349 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1350 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1351 | LabelType* true_label, |
| 1352 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1353 | LocationSummary* locations = cond->GetLocations(); |
| 1354 | Location left = locations->InAt(0); |
| 1355 | Location right = locations->InAt(1); |
| 1356 | IfCondition if_cond = cond->GetCondition(); |
| 1357 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1358 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1359 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1360 | IfCondition true_high_cond = if_cond; |
| 1361 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1362 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1363 | |
| 1364 | // Set the conditions for the test, remembering that == needs to be |
| 1365 | // decided using the low words. |
| 1366 | switch (if_cond) { |
| 1367 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1368 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1369 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1370 | break; |
| 1371 | case kCondLT: |
| 1372 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1373 | break; |
| 1374 | case kCondLE: |
| 1375 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | break; |
| 1377 | case kCondGT: |
| 1378 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1379 | break; |
| 1380 | case kCondGE: |
| 1381 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1382 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1383 | case kCondB: |
| 1384 | false_high_cond = kCondA; |
| 1385 | break; |
| 1386 | case kCondBE: |
| 1387 | true_high_cond = kCondB; |
| 1388 | break; |
| 1389 | case kCondA: |
| 1390 | false_high_cond = kCondB; |
| 1391 | break; |
| 1392 | case kCondAE: |
| 1393 | true_high_cond = kCondA; |
| 1394 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | if (right.IsConstant()) { |
| 1398 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1399 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1400 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1401 | |
| 1402 | if (val_high == 0) { |
| 1403 | __ testl(left_high, left_high); |
| 1404 | } else { |
| 1405 | __ cmpl(left_high, Immediate(val_high)); |
| 1406 | } |
| 1407 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1408 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1409 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1410 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1411 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1412 | __ j(X86Condition(true_high_cond), true_label); |
| 1413 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | } |
| 1415 | // Must be equal high, so compare the lows. |
| 1416 | if (val_low == 0) { |
| 1417 | __ testl(left_low, left_low); |
| 1418 | } else { |
| 1419 | __ cmpl(left_low, Immediate(val_low)); |
| 1420 | } |
| 1421 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1422 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1423 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1424 | |
| 1425 | __ cmpl(left_high, right_high); |
| 1426 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1427 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1428 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1429 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1430 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1431 | __ j(X86Condition(true_high_cond), true_label); |
| 1432 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | } |
| 1434 | // Must be equal high, so compare the lows. |
| 1435 | __ cmpl(left_low, right_low); |
| 1436 | } |
| 1437 | // The last comparison might be unsigned. |
| 1438 | __ j(final_condition, true_label); |
| 1439 | } |
| 1440 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1441 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1442 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1443 | LabelType* true_target_in, |
| 1444 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1445 | // Generated branching requires both targets to be explicit. If either of the |
| 1446 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1447 | LabelType fallthrough_target; |
| 1448 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1449 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1451 | LocationSummary* locations = condition->GetLocations(); |
| 1452 | Location left = locations->InAt(0); |
| 1453 | Location right = locations->InAt(1); |
| 1454 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1455 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1456 | switch (type) { |
| 1457 | case Primitive::kPrimLong: |
| 1458 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1459 | break; |
| 1460 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1461 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1462 | GenerateFPJumps(condition, true_target, false_target); |
| 1463 | break; |
| 1464 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1466 | GenerateFPJumps(condition, true_target, false_target); |
| 1467 | break; |
| 1468 | default: |
| 1469 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1470 | } |
| 1471 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1472 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1473 | __ jmp(false_target); |
| 1474 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1475 | |
| 1476 | if (fallthrough_target.IsLinked()) { |
| 1477 | __ Bind(&fallthrough_target); |
| 1478 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1481 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1482 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1483 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1484 | // conditions if they are materialized due to the complex branching. |
| 1485 | return cond->IsCondition() && |
| 1486 | cond->GetNext() == branch && |
| 1487 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1488 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1489 | } |
| 1490 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1491 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1492 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1493 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1494 | LabelType* true_target, |
| 1495 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1496 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1497 | |
| 1498 | if (true_target == nullptr && false_target == nullptr) { |
| 1499 | // Nothing to do. The code always falls through. |
| 1500 | return; |
| 1501 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1502 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1503 | if (cond->AsIntConstant()->IsOne()) { |
| 1504 | if (true_target != nullptr) { |
| 1505 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1506 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1507 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1508 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1509 | if (false_target != nullptr) { |
| 1510 | __ jmp(false_target); |
| 1511 | } |
| 1512 | } |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | // The following code generates these patterns: |
| 1517 | // (1) true_target == nullptr && false_target != nullptr |
| 1518 | // - opposite condition true => branch to false_target |
| 1519 | // (2) true_target != nullptr && false_target == nullptr |
| 1520 | // - condition true => branch to true_target |
| 1521 | // (3) true_target != nullptr && false_target != nullptr |
| 1522 | // - condition true => branch to true_target |
| 1523 | // - branch to false_target |
| 1524 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1525 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1526 | if (true_target == nullptr) { |
| 1527 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1528 | } else { |
| 1529 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1530 | } |
| 1531 | } else { |
| 1532 | // Materialized condition, compare against 0. |
| 1533 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1534 | if (lhs.IsRegister()) { |
| 1535 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1536 | } else { |
| 1537 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1538 | } |
| 1539 | if (true_target == nullptr) { |
| 1540 | __ j(kEqual, false_target); |
| 1541 | } else { |
| 1542 | __ j(kNotEqual, true_target); |
| 1543 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1544 | } |
| 1545 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1546 | // Condition has not been materialized, use its inputs as the comparison and |
| 1547 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1548 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1549 | |
| 1550 | // If this is a long or FP comparison that has been folded into |
| 1551 | // the HCondition, generate the comparison directly. |
| 1552 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1553 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1554 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | Location lhs = condition->GetLocations()->InAt(0); |
| 1559 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1560 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1561 | if (rhs.IsRegister()) { |
| 1562 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1563 | } else if (rhs.IsConstant()) { |
| 1564 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1565 | if (constant == 0) { |
| 1566 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1567 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1568 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1569 | } |
| 1570 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1571 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1572 | } |
| 1573 | if (true_target == nullptr) { |
| 1574 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1575 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1576 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1577 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1578 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1579 | |
| 1580 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1581 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1582 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1583 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1587 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1588 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1589 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1590 | locations->SetInAt(0, Location::Any()); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1595 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1596 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1597 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1598 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1599 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1600 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1601 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1605 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1606 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1607 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1608 | locations->SetInAt(0, Location::Any()); |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1613 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1614 | GenerateTestAndBranch(deoptimize, |
| 1615 | /* condition_input_index */ 0, |
| 1616 | slow_path->GetEntryLabel(), |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1617 | /* false_target */ static_cast<Label*>(nullptr)); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1620 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1621 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1622 | } |
| 1623 | |
| 1624 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1625 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1626 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1627 | __ nop(); |
| 1628 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1629 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1630 | } |
| 1631 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1632 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1633 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1636 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1637 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1640 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1641 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1644 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1645 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1648 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1649 | LocationSummary* locations = |
| 1650 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1651 | switch (store->InputAt(1)->GetType()) { |
| 1652 | case Primitive::kPrimBoolean: |
| 1653 | case Primitive::kPrimByte: |
| 1654 | case Primitive::kPrimChar: |
| 1655 | case Primitive::kPrimShort: |
| 1656 | case Primitive::kPrimInt: |
| 1657 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1658 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1659 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1660 | break; |
| 1661 | |
| 1662 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1663 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1664 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1665 | break; |
| 1666 | |
| 1667 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1668 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1669 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1672 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1675 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1676 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1677 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1678 | // Handle the long/FP comparisons made in instruction simplification. |
| 1679 | switch (cond->InputAt(0)->GetType()) { |
| 1680 | case Primitive::kPrimLong: { |
| 1681 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1682 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1683 | if (cond->NeedsMaterialization()) { |
| 1684 | locations->SetOut(Location::RequiresRegister()); |
| 1685 | } |
| 1686 | break; |
| 1687 | } |
| 1688 | case Primitive::kPrimFloat: |
| 1689 | case Primitive::kPrimDouble: { |
| 1690 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1691 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1692 | if (cond->NeedsMaterialization()) { |
| 1693 | locations->SetOut(Location::RequiresRegister()); |
| 1694 | } |
| 1695 | break; |
| 1696 | } |
| 1697 | default: |
| 1698 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1699 | locations->SetInAt(1, Location::Any()); |
| 1700 | if (cond->NeedsMaterialization()) { |
| 1701 | // We need a byte register. |
| 1702 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1703 | } |
| 1704 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1705 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1708 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1709 | if (!cond->NeedsMaterialization()) { |
| 1710 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1711 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1712 | |
| 1713 | LocationSummary* locations = cond->GetLocations(); |
| 1714 | Location lhs = locations->InAt(0); |
| 1715 | Location rhs = locations->InAt(1); |
| 1716 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1717 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1718 | |
| 1719 | switch (cond->InputAt(0)->GetType()) { |
| 1720 | default: { |
| 1721 | // Integer case. |
| 1722 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1723 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1724 | __ xorl(reg, reg); |
| 1725 | |
| 1726 | if (rhs.IsRegister()) { |
| 1727 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1728 | } else if (rhs.IsConstant()) { |
| 1729 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1730 | if (constant == 0) { |
| 1731 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1732 | } else { |
| 1733 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1734 | } |
| 1735 | } else { |
| 1736 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1737 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1738 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1739 | return; |
| 1740 | } |
| 1741 | case Primitive::kPrimLong: |
| 1742 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1743 | break; |
| 1744 | case Primitive::kPrimFloat: |
| 1745 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1746 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1747 | break; |
| 1748 | case Primitive::kPrimDouble: |
| 1749 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1750 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1751 | break; |
| 1752 | } |
| 1753 | |
| 1754 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1755 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1756 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1757 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1758 | __ Bind(&false_label); |
| 1759 | __ xorl(reg, reg); |
| 1760 | __ jmp(&done_label); |
| 1761 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1762 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1763 | __ Bind(&true_label); |
| 1764 | __ movl(reg, Immediate(1)); |
| 1765 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1769 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1773 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1777 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1781 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1797 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1801 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1805 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1809 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1813 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1816 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1817 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1821 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1825 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1829 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1833 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1837 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1841 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1845 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1848 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1849 | LocationSummary* locations = |
| 1850 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1851 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1852 | } |
| 1853 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1854 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1855 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1858 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1859 | LocationSummary* locations = |
| 1860 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1861 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1862 | } |
| 1863 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1864 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1865 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1868 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1869 | LocationSummary* locations = |
| 1870 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1871 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1872 | } |
| 1873 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1874 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1875 | // Will be generated at use site. |
| 1876 | } |
| 1877 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1878 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1879 | LocationSummary* locations = |
| 1880 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1881 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1882 | } |
| 1883 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1884 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1885 | // Will be generated at use site. |
| 1886 | } |
| 1887 | |
| 1888 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1889 | LocationSummary* locations = |
| 1890 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1891 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1892 | } |
| 1893 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1894 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1895 | // Will be generated at use site. |
| 1896 | } |
| 1897 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1898 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1899 | memory_barrier->SetLocations(nullptr); |
| 1900 | } |
| 1901 | |
| 1902 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1903 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1904 | } |
| 1905 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1906 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1907 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1910 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1911 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1914 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1915 | LocationSummary* locations = |
| 1916 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1917 | switch (ret->InputAt(0)->GetType()) { |
| 1918 | case Primitive::kPrimBoolean: |
| 1919 | case Primitive::kPrimByte: |
| 1920 | case Primitive::kPrimChar: |
| 1921 | case Primitive::kPrimShort: |
| 1922 | case Primitive::kPrimInt: |
| 1923 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1924 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1925 | break; |
| 1926 | |
| 1927 | case Primitive::kPrimLong: |
| 1928 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1929 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1930 | break; |
| 1931 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1932 | case Primitive::kPrimFloat: |
| 1933 | case Primitive::kPrimDouble: |
| 1934 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1935 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1936 | break; |
| 1937 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1938 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1939 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1940 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1943 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1944 | if (kIsDebugBuild) { |
| 1945 | switch (ret->InputAt(0)->GetType()) { |
| 1946 | case Primitive::kPrimBoolean: |
| 1947 | case Primitive::kPrimByte: |
| 1948 | case Primitive::kPrimChar: |
| 1949 | case Primitive::kPrimShort: |
| 1950 | case Primitive::kPrimInt: |
| 1951 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1952 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1953 | break; |
| 1954 | |
| 1955 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1956 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1957 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1958 | break; |
| 1959 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1960 | case Primitive::kPrimFloat: |
| 1961 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1962 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1963 | break; |
| 1964 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1965 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1966 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1967 | } |
| 1968 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1969 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1972 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1973 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1974 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1975 | // the method_idx. |
| 1976 | HandleInvoke(invoke); |
| 1977 | } |
| 1978 | |
| 1979 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1980 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1981 | } |
| 1982 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1983 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1984 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1985 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1986 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1987 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1988 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1989 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1990 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1991 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1992 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1993 | return; |
| 1994 | } |
| 1995 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1996 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1997 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1998 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1999 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2000 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2003 | if (codegen_->IsBaseline()) { |
| 2004 | // Baseline does not have enough registers if the current method also |
| 2005 | // needs a register. We therefore do not require a register for it, and let |
| 2006 | // the code generation of the invoke handle it. |
| 2007 | LocationSummary* locations = invoke->GetLocations(); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2008 | Location location = locations->InAt(invoke->GetSpecialInputIndex()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2009 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2010 | locations->SetInAt(invoke->GetSpecialInputIndex(), Location::NoLocation()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2011 | } |
| 2012 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2013 | } |
| 2014 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2015 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2016 | if (invoke->GetLocations()->Intrinsified()) { |
| 2017 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2018 | intrinsic.Dispatch(invoke); |
| 2019 | return true; |
| 2020 | } |
| 2021 | return false; |
| 2022 | } |
| 2023 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2024 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2025 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2026 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2027 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2028 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2029 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2030 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2031 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2032 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2033 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2034 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2035 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2036 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2040 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2041 | if (intrinsic.TryDispatch(invoke)) { |
| 2042 | return; |
| 2043 | } |
| 2044 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2045 | HandleInvoke(invoke); |
| 2046 | } |
| 2047 | |
| 2048 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2049 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2050 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2053 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2054 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2055 | return; |
| 2056 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2057 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2058 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2059 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2060 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2063 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2064 | // This call to HandleInvoke allocates a temporary (core) register |
| 2065 | // which is also used to transfer the hidden argument from FP to |
| 2066 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2067 | HandleInvoke(invoke); |
| 2068 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2069 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2073 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2074 | LocationSummary* locations = invoke->GetLocations(); |
| 2075 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2076 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2077 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2078 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2079 | Location receiver = locations->InAt(0); |
| 2080 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2081 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2082 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2083 | // won't be modified thereafter, before the `call` instruction. |
| 2084 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2085 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2086 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2087 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2088 | if (receiver.IsStackSlot()) { |
| 2089 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2090 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2091 | __ movl(temp, Address(temp, class_offset)); |
| 2092 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2093 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2094 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2095 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2096 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2097 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2098 | // emit a read barrier for the previous class reference load. |
| 2099 | // However this is not required in practice, as this is an |
| 2100 | // intermediate/temporary reference and because the current |
| 2101 | // concurrent copying collector keeps the from-space memory |
| 2102 | // intact/accessible until the end of the marking phase (the |
| 2103 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2104 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2105 | // temp = temp->GetImtEntryAt(method_offset); |
| 2106 | __ movl(temp, Address(temp, method_offset)); |
| 2107 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2108 | __ call(Address(temp, |
| 2109 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2110 | |
| 2111 | DCHECK(!codegen_->IsLeafMethod()); |
| 2112 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2113 | } |
| 2114 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2115 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2116 | LocationSummary* locations = |
| 2117 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2118 | switch (neg->GetResultType()) { |
| 2119 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2120 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2121 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2122 | locations->SetOut(Location::SameAsFirstInput()); |
| 2123 | break; |
| 2124 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2125 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2126 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2127 | locations->SetOut(Location::SameAsFirstInput()); |
| 2128 | locations->AddTemp(Location::RequiresRegister()); |
| 2129 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2130 | break; |
| 2131 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2132 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2133 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2134 | locations->SetOut(Location::SameAsFirstInput()); |
| 2135 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2136 | break; |
| 2137 | |
| 2138 | default: |
| 2139 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2144 | LocationSummary* locations = neg->GetLocations(); |
| 2145 | Location out = locations->Out(); |
| 2146 | Location in = locations->InAt(0); |
| 2147 | switch (neg->GetResultType()) { |
| 2148 | case Primitive::kPrimInt: |
| 2149 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2150 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2151 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2152 | break; |
| 2153 | |
| 2154 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2155 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2156 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2157 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2158 | // Negation is similar to subtraction from zero. The least |
| 2159 | // significant byte triggers a borrow when it is different from |
| 2160 | // zero; to take it into account, add 1 to the most significant |
| 2161 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2162 | // operation. |
| 2163 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2164 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2165 | break; |
| 2166 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2167 | case Primitive::kPrimFloat: { |
| 2168 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2169 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2170 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2171 | // Implement float negation with an exclusive or with value |
| 2172 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2173 | // single-precision floating-point number). |
| 2174 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2175 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2176 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2177 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2178 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2179 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimDouble: { |
| 2181 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2182 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2183 | // Implement double negation with an exclusive or with value |
| 2184 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2185 | // a double-precision floating-point number). |
| 2186 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2187 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2188 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2189 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2190 | |
| 2191 | default: |
| 2192 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2193 | } |
| 2194 | } |
| 2195 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2196 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2197 | Primitive::Type result_type = conversion->GetResultType(); |
| 2198 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2199 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2200 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2201 | // The float-to-long and double-to-long type conversions rely on a |
| 2202 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2203 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2204 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2205 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2206 | ? LocationSummary::kCall |
| 2207 | : LocationSummary::kNoCall; |
| 2208 | LocationSummary* locations = |
| 2209 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2210 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2211 | // The Java language does not allow treating boolean as an integral type but |
| 2212 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2213 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2214 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2215 | case Primitive::kPrimByte: |
| 2216 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2217 | case Primitive::kPrimBoolean: |
| 2218 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2219 | case Primitive::kPrimShort: |
| 2220 | case Primitive::kPrimInt: |
| 2221 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2222 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2223 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2224 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2225 | // the validation of the linear scan implementation |
| 2226 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2227 | break; |
| 2228 | |
| 2229 | default: |
| 2230 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2231 | << " to " << result_type; |
| 2232 | } |
| 2233 | break; |
| 2234 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2235 | case Primitive::kPrimShort: |
| 2236 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2237 | case Primitive::kPrimBoolean: |
| 2238 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2239 | case Primitive::kPrimByte: |
| 2240 | case Primitive::kPrimInt: |
| 2241 | case Primitive::kPrimChar: |
| 2242 | // Processing a Dex `int-to-short' instruction. |
| 2243 | locations->SetInAt(0, Location::Any()); |
| 2244 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2245 | break; |
| 2246 | |
| 2247 | default: |
| 2248 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2249 | << " to " << result_type; |
| 2250 | } |
| 2251 | break; |
| 2252 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2253 | case Primitive::kPrimInt: |
| 2254 | switch (input_type) { |
| 2255 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2256 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2257 | locations->SetInAt(0, Location::Any()); |
| 2258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2259 | break; |
| 2260 | |
| 2261 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2262 | // Processing a Dex `float-to-int' instruction. |
| 2263 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2264 | locations->SetOut(Location::RequiresRegister()); |
| 2265 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2266 | break; |
| 2267 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2268 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2269 | // Processing a Dex `double-to-int' instruction. |
| 2270 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2271 | locations->SetOut(Location::RequiresRegister()); |
| 2272 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2273 | break; |
| 2274 | |
| 2275 | default: |
| 2276 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2277 | << " to " << result_type; |
| 2278 | } |
| 2279 | break; |
| 2280 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimLong: |
| 2282 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimBoolean: |
| 2284 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2285 | case Primitive::kPrimByte: |
| 2286 | case Primitive::kPrimShort: |
| 2287 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2289 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2290 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2291 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2292 | break; |
| 2293 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2294 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2295 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2296 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2297 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2298 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2299 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2300 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2301 | // The runtime helper puts the result in EAX, EDX. |
| 2302 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2303 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2304 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2305 | |
| 2306 | default: |
| 2307 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2308 | << " to " << result_type; |
| 2309 | } |
| 2310 | break; |
| 2311 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimChar: |
| 2313 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimBoolean: |
| 2315 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2316 | case Primitive::kPrimByte: |
| 2317 | case Primitive::kPrimShort: |
| 2318 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2319 | // Processing a Dex `int-to-char' instruction. |
| 2320 | locations->SetInAt(0, Location::Any()); |
| 2321 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2322 | break; |
| 2323 | |
| 2324 | default: |
| 2325 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2326 | << " to " << result_type; |
| 2327 | } |
| 2328 | break; |
| 2329 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2331 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimBoolean: |
| 2333 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2334 | case Primitive::kPrimByte: |
| 2335 | case Primitive::kPrimShort: |
| 2336 | case Primitive::kPrimInt: |
| 2337 | case Primitive::kPrimChar: |
| 2338 | // Processing a Dex `int-to-float' instruction. |
| 2339 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2340 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2341 | break; |
| 2342 | |
| 2343 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2344 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2345 | locations->SetInAt(0, Location::Any()); |
| 2346 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2347 | break; |
| 2348 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2349 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2350 | // Processing a Dex `double-to-float' instruction. |
| 2351 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2352 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2353 | break; |
| 2354 | |
| 2355 | default: |
| 2356 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2357 | << " to " << result_type; |
| 2358 | }; |
| 2359 | break; |
| 2360 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2362 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimBoolean: |
| 2364 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimByte: |
| 2366 | case Primitive::kPrimShort: |
| 2367 | case Primitive::kPrimInt: |
| 2368 | case Primitive::kPrimChar: |
| 2369 | // Processing a Dex `int-to-double' instruction. |
| 2370 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2371 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2372 | break; |
| 2373 | |
| 2374 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2375 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2376 | locations->SetInAt(0, Location::Any()); |
| 2377 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2380 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2381 | // Processing a Dex `float-to-double' instruction. |
| 2382 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2383 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2384 | break; |
| 2385 | |
| 2386 | default: |
| 2387 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2388 | << " to " << result_type; |
| 2389 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2390 | break; |
| 2391 | |
| 2392 | default: |
| 2393 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2394 | << " to " << result_type; |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2399 | LocationSummary* locations = conversion->GetLocations(); |
| 2400 | Location out = locations->Out(); |
| 2401 | Location in = locations->InAt(0); |
| 2402 | Primitive::Type result_type = conversion->GetResultType(); |
| 2403 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2404 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2405 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimByte: |
| 2407 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2408 | case Primitive::kPrimBoolean: |
| 2409 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2410 | case Primitive::kPrimShort: |
| 2411 | case Primitive::kPrimInt: |
| 2412 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2413 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2414 | if (in.IsRegister()) { |
| 2415 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2416 | } else { |
| 2417 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2418 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2419 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2420 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2421 | break; |
| 2422 | |
| 2423 | default: |
| 2424 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2425 | << " to " << result_type; |
| 2426 | } |
| 2427 | break; |
| 2428 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimShort: |
| 2430 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimBoolean: |
| 2432 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimInt: |
| 2435 | case Primitive::kPrimChar: |
| 2436 | // Processing a Dex `int-to-short' instruction. |
| 2437 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2438 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2439 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2440 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2441 | } else { |
| 2442 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2443 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2444 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2445 | } |
| 2446 | break; |
| 2447 | |
| 2448 | default: |
| 2449 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2450 | << " to " << result_type; |
| 2451 | } |
| 2452 | break; |
| 2453 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2454 | case Primitive::kPrimInt: |
| 2455 | switch (input_type) { |
| 2456 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2457 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2458 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2459 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2460 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2461 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2462 | } else { |
| 2463 | DCHECK(in.IsConstant()); |
| 2464 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2465 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2466 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2467 | } |
| 2468 | break; |
| 2469 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimFloat: { |
| 2471 | // Processing a Dex `float-to-int' instruction. |
| 2472 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2473 | Register output = out.AsRegister<Register>(); |
| 2474 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2475 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2476 | |
| 2477 | __ movl(output, Immediate(kPrimIntMax)); |
| 2478 | // temp = int-to-float(output) |
| 2479 | __ cvtsi2ss(temp, output); |
| 2480 | // if input >= temp goto done |
| 2481 | __ comiss(input, temp); |
| 2482 | __ j(kAboveEqual, &done); |
| 2483 | // if input == NaN goto nan |
| 2484 | __ j(kUnordered, &nan); |
| 2485 | // output = float-to-int-truncate(input) |
| 2486 | __ cvttss2si(output, input); |
| 2487 | __ jmp(&done); |
| 2488 | __ Bind(&nan); |
| 2489 | // output = 0 |
| 2490 | __ xorl(output, output); |
| 2491 | __ Bind(&done); |
| 2492 | break; |
| 2493 | } |
| 2494 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimDouble: { |
| 2496 | // Processing a Dex `double-to-int' instruction. |
| 2497 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2498 | Register output = out.AsRegister<Register>(); |
| 2499 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2500 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2501 | |
| 2502 | __ movl(output, Immediate(kPrimIntMax)); |
| 2503 | // temp = int-to-double(output) |
| 2504 | __ cvtsi2sd(temp, output); |
| 2505 | // if input >= temp goto done |
| 2506 | __ comisd(input, temp); |
| 2507 | __ j(kAboveEqual, &done); |
| 2508 | // if input == NaN goto nan |
| 2509 | __ j(kUnordered, &nan); |
| 2510 | // output = double-to-int-truncate(input) |
| 2511 | __ cvttsd2si(output, input); |
| 2512 | __ jmp(&done); |
| 2513 | __ Bind(&nan); |
| 2514 | // output = 0 |
| 2515 | __ xorl(output, output); |
| 2516 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2517 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2518 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2519 | |
| 2520 | default: |
| 2521 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2522 | << " to " << result_type; |
| 2523 | } |
| 2524 | break; |
| 2525 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimLong: |
| 2527 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimBoolean: |
| 2529 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimByte: |
| 2531 | case Primitive::kPrimShort: |
| 2532 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2533 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2534 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2535 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2536 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2537 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2538 | __ cdq(); |
| 2539 | break; |
| 2540 | |
| 2541 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2542 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2543 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2544 | conversion, |
| 2545 | conversion->GetDexPc(), |
| 2546 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2547 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2548 | break; |
| 2549 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2551 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2552 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2553 | conversion, |
| 2554 | conversion->GetDexPc(), |
| 2555 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2556 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2557 | break; |
| 2558 | |
| 2559 | default: |
| 2560 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2561 | << " to " << result_type; |
| 2562 | } |
| 2563 | break; |
| 2564 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimChar: |
| 2566 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimBoolean: |
| 2568 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimByte: |
| 2570 | case Primitive::kPrimShort: |
| 2571 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2572 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2573 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2574 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2575 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2576 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2577 | } else { |
| 2578 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2579 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2580 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2581 | } |
| 2582 | break; |
| 2583 | |
| 2584 | default: |
| 2585 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2586 | << " to " << result_type; |
| 2587 | } |
| 2588 | break; |
| 2589 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2591 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimBoolean: |
| 2593 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2594 | case Primitive::kPrimByte: |
| 2595 | case Primitive::kPrimShort: |
| 2596 | case Primitive::kPrimInt: |
| 2597 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2598 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2600 | break; |
| 2601 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimLong: { |
| 2603 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2604 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2605 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2606 | // Create stack space for the call to |
| 2607 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2608 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2609 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2610 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2611 | __ subl(ESP, Immediate(adjustment)); |
| 2612 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2613 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2614 | // Load the value to the FP stack, using temporaries if needed. |
| 2615 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2616 | |
| 2617 | if (out.IsStackSlot()) { |
| 2618 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2619 | } else { |
| 2620 | __ fstps(Address(ESP, 0)); |
| 2621 | Location stack_temp = Location::StackSlot(0); |
| 2622 | codegen_->Move32(out, stack_temp); |
| 2623 | } |
| 2624 | |
| 2625 | // Remove the temporary stack space we allocated. |
| 2626 | if (adjustment != 0) { |
| 2627 | __ addl(ESP, Immediate(adjustment)); |
| 2628 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2629 | break; |
| 2630 | } |
| 2631 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2632 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2633 | // Processing a Dex `double-to-float' instruction. |
| 2634 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2635 | break; |
| 2636 | |
| 2637 | default: |
| 2638 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2639 | << " to " << result_type; |
| 2640 | }; |
| 2641 | break; |
| 2642 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2644 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2645 | case Primitive::kPrimBoolean: |
| 2646 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2647 | case Primitive::kPrimByte: |
| 2648 | case Primitive::kPrimShort: |
| 2649 | case Primitive::kPrimInt: |
| 2650 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2651 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2652 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2653 | break; |
| 2654 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimLong: { |
| 2656 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2657 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2658 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2659 | // Create stack space for the call to |
| 2660 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2661 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2662 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2663 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2664 | __ subl(ESP, Immediate(adjustment)); |
| 2665 | } |
| 2666 | |
| 2667 | // Load the value to the FP stack, using temporaries if needed. |
| 2668 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2669 | |
| 2670 | if (out.IsDoubleStackSlot()) { |
| 2671 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2672 | } else { |
| 2673 | __ fstpl(Address(ESP, 0)); |
| 2674 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2675 | codegen_->Move64(out, stack_temp); |
| 2676 | } |
| 2677 | |
| 2678 | // Remove the temporary stack space we allocated. |
| 2679 | if (adjustment != 0) { |
| 2680 | __ addl(ESP, Immediate(adjustment)); |
| 2681 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2682 | break; |
| 2683 | } |
| 2684 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2685 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2686 | // Processing a Dex `float-to-double' instruction. |
| 2687 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2688 | break; |
| 2689 | |
| 2690 | default: |
| 2691 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2692 | << " to " << result_type; |
| 2693 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | |
| 2696 | default: |
| 2697 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2698 | << " to " << result_type; |
| 2699 | } |
| 2700 | } |
| 2701 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2702 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2703 | LocationSummary* locations = |
| 2704 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2705 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2706 | case Primitive::kPrimInt: { |
| 2707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2708 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2709 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2710 | break; |
| 2711 | } |
| 2712 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2713 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2714 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2715 | locations->SetInAt(1, Location::Any()); |
| 2716 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2717 | break; |
| 2718 | } |
| 2719 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2720 | case Primitive::kPrimFloat: |
| 2721 | case Primitive::kPrimDouble: { |
| 2722 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2723 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2724 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2725 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2726 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2727 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2728 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2729 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2730 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2731 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2735 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2736 | Location first = locations->InAt(0); |
| 2737 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2738 | Location out = locations->Out(); |
| 2739 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2740 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2741 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2742 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2743 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2744 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2745 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2746 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2747 | } else { |
| 2748 | __ leal(out.AsRegister<Register>(), Address( |
| 2749 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2750 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2751 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2752 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2753 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2754 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2755 | } else { |
| 2756 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2757 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2758 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2759 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2760 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2761 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2762 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2766 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2767 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2768 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2769 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2770 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2771 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2772 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2773 | } else { |
| 2774 | DCHECK(second.IsConstant()) << second; |
| 2775 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2776 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2777 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2778 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2779 | break; |
| 2780 | } |
| 2781 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2782 | case Primitive::kPrimFloat: { |
| 2783 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2784 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2785 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2786 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2787 | DCHECK(!const_area->NeedsMaterialization()); |
| 2788 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2789 | codegen_->LiteralFloatAddress( |
| 2790 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2791 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2792 | } else { |
| 2793 | DCHECK(second.IsStackSlot()); |
| 2794 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2795 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2796 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | case Primitive::kPrimDouble: { |
| 2800 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2801 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2802 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2803 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2804 | DCHECK(!const_area->NeedsMaterialization()); |
| 2805 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2806 | codegen_->LiteralDoubleAddress( |
| 2807 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2808 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2809 | } else { |
| 2810 | DCHECK(second.IsDoubleStackSlot()); |
| 2811 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2812 | } |
| 2813 | break; |
| 2814 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2815 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2816 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2817 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2818 | } |
| 2819 | } |
| 2820 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2821 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2822 | LocationSummary* locations = |
| 2823 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2824 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2825 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2826 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2827 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2828 | locations->SetInAt(1, Location::Any()); |
| 2829 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2830 | break; |
| 2831 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2832 | case Primitive::kPrimFloat: |
| 2833 | case Primitive::kPrimDouble: { |
| 2834 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2835 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2836 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2837 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2838 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2839 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2840 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2841 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2842 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2846 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2847 | Location first = locations->InAt(0); |
| 2848 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2849 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2850 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2851 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2852 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2853 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2854 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2855 | __ subl(first.AsRegister<Register>(), |
| 2856 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2857 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2858 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2859 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2860 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2864 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2865 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2866 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2867 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2868 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2869 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2870 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2871 | } else { |
| 2872 | DCHECK(second.IsConstant()) << second; |
| 2873 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2874 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2875 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2876 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2877 | break; |
| 2878 | } |
| 2879 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2880 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2881 | if (second.IsFpuRegister()) { |
| 2882 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2883 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2884 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2885 | DCHECK(!const_area->NeedsMaterialization()); |
| 2886 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2887 | codegen_->LiteralFloatAddress( |
| 2888 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2889 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2890 | } else { |
| 2891 | DCHECK(second.IsStackSlot()); |
| 2892 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2893 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2894 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2898 | if (second.IsFpuRegister()) { |
| 2899 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2900 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2901 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2902 | DCHECK(!const_area->NeedsMaterialization()); |
| 2903 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2904 | codegen_->LiteralDoubleAddress( |
| 2905 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2906 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2907 | } else { |
| 2908 | DCHECK(second.IsDoubleStackSlot()); |
| 2909 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2910 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2911 | break; |
| 2912 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2913 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2914 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2915 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2916 | } |
| 2917 | } |
| 2918 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2919 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2920 | LocationSummary* locations = |
| 2921 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2922 | switch (mul->GetResultType()) { |
| 2923 | case Primitive::kPrimInt: |
| 2924 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2925 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2926 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2927 | // Can use 3 operand multiply. |
| 2928 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2929 | } else { |
| 2930 | locations->SetOut(Location::SameAsFirstInput()); |
| 2931 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2932 | break; |
| 2933 | case Primitive::kPrimLong: { |
| 2934 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2935 | locations->SetInAt(1, Location::Any()); |
| 2936 | locations->SetOut(Location::SameAsFirstInput()); |
| 2937 | // Needed for imul on 32bits with 64bits output. |
| 2938 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2939 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2940 | break; |
| 2941 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2942 | case Primitive::kPrimFloat: |
| 2943 | case Primitive::kPrimDouble: { |
| 2944 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2945 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2946 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2947 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2948 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2949 | |
| 2950 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2951 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2956 | LocationSummary* locations = mul->GetLocations(); |
| 2957 | Location first = locations->InAt(0); |
| 2958 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2959 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2960 | |
| 2961 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2962 | case Primitive::kPrimInt: |
| 2963 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2964 | // problems where the output may not be the same as the first operand. |
| 2965 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2966 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2967 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2968 | } else if (second.IsRegister()) { |
| 2969 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2970 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2971 | } else { |
| 2972 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2973 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2974 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2975 | } |
| 2976 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2977 | |
| 2978 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2979 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2980 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2981 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2982 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2983 | |
| 2984 | DCHECK_EQ(EAX, eax); |
| 2985 | DCHECK_EQ(EDX, edx); |
| 2986 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2987 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2988 | // output: in1 |
| 2989 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2990 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2991 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2992 | if (second.IsConstant()) { |
| 2993 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2994 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2995 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2996 | int32_t low_value = Low32Bits(value); |
| 2997 | int32_t high_value = High32Bits(value); |
| 2998 | Immediate low(low_value); |
| 2999 | Immediate high(high_value); |
| 3000 | |
| 3001 | __ movl(eax, high); |
| 3002 | // eax <- in1.lo * in2.hi |
| 3003 | __ imull(eax, in1_lo); |
| 3004 | // in1.hi <- in1.hi * in2.lo |
| 3005 | __ imull(in1_hi, low); |
| 3006 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3007 | __ addl(in1_hi, eax); |
| 3008 | // move in2_lo to eax to prepare for double precision |
| 3009 | __ movl(eax, low); |
| 3010 | // edx:eax <- in1.lo * in2.lo |
| 3011 | __ mull(in1_lo); |
| 3012 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3013 | __ addl(in1_hi, edx); |
| 3014 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3015 | __ movl(in1_lo, eax); |
| 3016 | } else if (second.IsRegisterPair()) { |
| 3017 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3018 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3019 | |
| 3020 | __ movl(eax, in2_hi); |
| 3021 | // eax <- in1.lo * in2.hi |
| 3022 | __ imull(eax, in1_lo); |
| 3023 | // in1.hi <- in1.hi * in2.lo |
| 3024 | __ imull(in1_hi, in2_lo); |
| 3025 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3026 | __ addl(in1_hi, eax); |
| 3027 | // move in1_lo to eax to prepare for double precision |
| 3028 | __ movl(eax, in1_lo); |
| 3029 | // edx:eax <- in1.lo * in2.lo |
| 3030 | __ mull(in2_lo); |
| 3031 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3032 | __ addl(in1_hi, edx); |
| 3033 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3034 | __ movl(in1_lo, eax); |
| 3035 | } else { |
| 3036 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3037 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3038 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3039 | |
| 3040 | __ movl(eax, in2_hi); |
| 3041 | // eax <- in1.lo * in2.hi |
| 3042 | __ imull(eax, in1_lo); |
| 3043 | // in1.hi <- in1.hi * in2.lo |
| 3044 | __ imull(in1_hi, in2_lo); |
| 3045 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3046 | __ addl(in1_hi, eax); |
| 3047 | // move in1_lo to eax to prepare for double precision |
| 3048 | __ movl(eax, in1_lo); |
| 3049 | // edx:eax <- in1.lo * in2.lo |
| 3050 | __ mull(in2_lo); |
| 3051 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3052 | __ addl(in1_hi, edx); |
| 3053 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3054 | __ movl(in1_lo, eax); |
| 3055 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3056 | |
| 3057 | break; |
| 3058 | } |
| 3059 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3060 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3061 | DCHECK(first.Equals(locations->Out())); |
| 3062 | if (second.IsFpuRegister()) { |
| 3063 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3064 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3065 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3066 | DCHECK(!const_area->NeedsMaterialization()); |
| 3067 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3068 | codegen_->LiteralFloatAddress( |
| 3069 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3070 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3071 | } else { |
| 3072 | DCHECK(second.IsStackSlot()); |
| 3073 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3074 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3075 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3079 | DCHECK(first.Equals(locations->Out())); |
| 3080 | if (second.IsFpuRegister()) { |
| 3081 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3082 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3083 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3084 | DCHECK(!const_area->NeedsMaterialization()); |
| 3085 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3086 | codegen_->LiteralDoubleAddress( |
| 3087 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3088 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3089 | } else { |
| 3090 | DCHECK(second.IsDoubleStackSlot()); |
| 3091 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3092 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3093 | break; |
| 3094 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3095 | |
| 3096 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3097 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3098 | } |
| 3099 | } |
| 3100 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3101 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3102 | uint32_t temp_offset, |
| 3103 | uint32_t stack_adjustment, |
| 3104 | bool is_fp, |
| 3105 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3106 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3107 | DCHECK(!is_wide); |
| 3108 | if (is_fp) { |
| 3109 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3110 | } else { |
| 3111 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3112 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3113 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3114 | DCHECK(is_wide); |
| 3115 | if (is_fp) { |
| 3116 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3117 | } else { |
| 3118 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3119 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3120 | } else { |
| 3121 | // 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] | 3122 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3123 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3124 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3125 | if (is_fp) { |
| 3126 | __ flds(Address(ESP, temp_offset)); |
| 3127 | } else { |
| 3128 | __ filds(Address(ESP, temp_offset)); |
| 3129 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3130 | } else { |
| 3131 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3132 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3133 | if (is_fp) { |
| 3134 | __ fldl(Address(ESP, temp_offset)); |
| 3135 | } else { |
| 3136 | __ fildl(Address(ESP, temp_offset)); |
| 3137 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3143 | Primitive::Type type = rem->GetResultType(); |
| 3144 | bool is_float = type == Primitive::kPrimFloat; |
| 3145 | size_t elem_size = Primitive::ComponentSize(type); |
| 3146 | LocationSummary* locations = rem->GetLocations(); |
| 3147 | Location first = locations->InAt(0); |
| 3148 | Location second = locations->InAt(1); |
| 3149 | Location out = locations->Out(); |
| 3150 | |
| 3151 | // Create stack space for 2 elements. |
| 3152 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3153 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3154 | |
| 3155 | // 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] | 3156 | const bool is_wide = !is_float; |
| 3157 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3158 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3159 | |
| 3160 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3161 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3162 | __ Bind(&retry); |
| 3163 | __ fprem(); |
| 3164 | |
| 3165 | // Move FP status to AX. |
| 3166 | __ fstsw(); |
| 3167 | |
| 3168 | // And see if the argument reduction is complete. This is signaled by the |
| 3169 | // C2 FPU flag bit set to 0. |
| 3170 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3171 | __ j(kNotEqual, &retry); |
| 3172 | |
| 3173 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3174 | // Store FP top of stack to real stack. |
| 3175 | if (is_float) { |
| 3176 | __ fsts(Address(ESP, 0)); |
| 3177 | } else { |
| 3178 | __ fstl(Address(ESP, 0)); |
| 3179 | } |
| 3180 | |
| 3181 | // Pop the 2 items from the FP stack. |
| 3182 | __ fucompp(); |
| 3183 | |
| 3184 | // Load the value from the stack into an XMM register. |
| 3185 | DCHECK(out.IsFpuRegister()) << out; |
| 3186 | if (is_float) { |
| 3187 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3188 | } else { |
| 3189 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3190 | } |
| 3191 | |
| 3192 | // And remove the temporary stack space we allocated. |
| 3193 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3194 | } |
| 3195 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3196 | |
| 3197 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3198 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3199 | |
| 3200 | LocationSummary* locations = instruction->GetLocations(); |
| 3201 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3202 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3203 | |
| 3204 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3205 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3206 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3207 | |
| 3208 | DCHECK(imm == 1 || imm == -1); |
| 3209 | |
| 3210 | if (instruction->IsRem()) { |
| 3211 | __ xorl(out_register, out_register); |
| 3212 | } else { |
| 3213 | __ movl(out_register, input_register); |
| 3214 | if (imm == -1) { |
| 3215 | __ negl(out_register); |
| 3216 | } |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3221 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3222 | LocationSummary* locations = instruction->GetLocations(); |
| 3223 | |
| 3224 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3225 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3226 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3227 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3228 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3229 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3230 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3231 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3232 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3233 | __ testl(input_register, input_register); |
| 3234 | __ cmovl(kGreaterEqual, num, input_register); |
| 3235 | int shift = CTZ(imm); |
| 3236 | __ sarl(num, Immediate(shift)); |
| 3237 | |
| 3238 | if (imm < 0) { |
| 3239 | __ negl(num); |
| 3240 | } |
| 3241 | |
| 3242 | __ movl(out_register, num); |
| 3243 | } |
| 3244 | |
| 3245 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3246 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3247 | |
| 3248 | LocationSummary* locations = instruction->GetLocations(); |
| 3249 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3250 | |
| 3251 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3252 | Register out = locations->Out().AsRegister<Register>(); |
| 3253 | Register num; |
| 3254 | Register edx; |
| 3255 | |
| 3256 | if (instruction->IsDiv()) { |
| 3257 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3258 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3259 | } else { |
| 3260 | edx = locations->Out().AsRegister<Register>(); |
| 3261 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3262 | } |
| 3263 | |
| 3264 | DCHECK_EQ(EAX, eax); |
| 3265 | DCHECK_EQ(EDX, edx); |
| 3266 | if (instruction->IsDiv()) { |
| 3267 | DCHECK_EQ(EAX, out); |
| 3268 | } else { |
| 3269 | DCHECK_EQ(EDX, out); |
| 3270 | } |
| 3271 | |
| 3272 | int64_t magic; |
| 3273 | int shift; |
| 3274 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3275 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3276 | NearLabel ndiv; |
| 3277 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3278 | // If numerator is 0, the result is 0, no computation needed. |
| 3279 | __ testl(eax, eax); |
| 3280 | __ j(kNotEqual, &ndiv); |
| 3281 | |
| 3282 | __ xorl(out, out); |
| 3283 | __ jmp(&end); |
| 3284 | |
| 3285 | __ Bind(&ndiv); |
| 3286 | |
| 3287 | // Save the numerator. |
| 3288 | __ movl(num, eax); |
| 3289 | |
| 3290 | // EAX = magic |
| 3291 | __ movl(eax, Immediate(magic)); |
| 3292 | |
| 3293 | // EDX:EAX = magic * numerator |
| 3294 | __ imull(num); |
| 3295 | |
| 3296 | if (imm > 0 && magic < 0) { |
| 3297 | // EDX += num |
| 3298 | __ addl(edx, num); |
| 3299 | } else if (imm < 0 && magic > 0) { |
| 3300 | __ subl(edx, num); |
| 3301 | } |
| 3302 | |
| 3303 | // Shift if needed. |
| 3304 | if (shift != 0) { |
| 3305 | __ sarl(edx, Immediate(shift)); |
| 3306 | } |
| 3307 | |
| 3308 | // EDX += 1 if EDX < 0 |
| 3309 | __ movl(eax, edx); |
| 3310 | __ shrl(edx, Immediate(31)); |
| 3311 | __ addl(edx, eax); |
| 3312 | |
| 3313 | if (instruction->IsRem()) { |
| 3314 | __ movl(eax, num); |
| 3315 | __ imull(edx, Immediate(imm)); |
| 3316 | __ subl(eax, edx); |
| 3317 | __ movl(edx, eax); |
| 3318 | } else { |
| 3319 | __ movl(eax, edx); |
| 3320 | } |
| 3321 | __ Bind(&end); |
| 3322 | } |
| 3323 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3324 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3325 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3326 | |
| 3327 | LocationSummary* locations = instruction->GetLocations(); |
| 3328 | Location out = locations->Out(); |
| 3329 | Location first = locations->InAt(0); |
| 3330 | Location second = locations->InAt(1); |
| 3331 | bool is_div = instruction->IsDiv(); |
| 3332 | |
| 3333 | switch (instruction->GetResultType()) { |
| 3334 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3335 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3336 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3337 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3338 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3339 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3340 | |
| 3341 | if (imm == 0) { |
| 3342 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3343 | } else if (imm == 1 || imm == -1) { |
| 3344 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3345 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3346 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3347 | } else { |
| 3348 | DCHECK(imm <= -2 || imm >= 2); |
| 3349 | GenerateDivRemWithAnyConstant(instruction); |
| 3350 | } |
| 3351 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3352 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3353 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3354 | is_div); |
| 3355 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3356 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3357 | Register second_reg = second.AsRegister<Register>(); |
| 3358 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3359 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3360 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3361 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3362 | __ cmpl(second_reg, Immediate(-1)); |
| 3363 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3364 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3365 | // edx:eax <- sign-extended of eax |
| 3366 | __ cdq(); |
| 3367 | // eax = quotient, edx = remainder |
| 3368 | __ idivl(second_reg); |
| 3369 | __ Bind(slow_path->GetExitLabel()); |
| 3370 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3371 | break; |
| 3372 | } |
| 3373 | |
| 3374 | case Primitive::kPrimLong: { |
| 3375 | InvokeRuntimeCallingConvention calling_convention; |
| 3376 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3377 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3378 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3379 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3380 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3381 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3382 | |
| 3383 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3384 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3385 | instruction, |
| 3386 | instruction->GetDexPc(), |
| 3387 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3388 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3389 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3390 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3391 | instruction, |
| 3392 | instruction->GetDexPc(), |
| 3393 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3394 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3395 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3396 | break; |
| 3397 | } |
| 3398 | |
| 3399 | default: |
| 3400 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3401 | } |
| 3402 | } |
| 3403 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3404 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3405 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3406 | ? LocationSummary::kCall |
| 3407 | : LocationSummary::kNoCall; |
| 3408 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3409 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3410 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3411 | case Primitive::kPrimInt: { |
| 3412 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3413 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3414 | locations->SetOut(Location::SameAsFirstInput()); |
| 3415 | // Intel uses edx:eax as the dividend. |
| 3416 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3417 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3418 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3419 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3420 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3421 | locations->AddTemp(Location::RequiresRegister()); |
| 3422 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3423 | break; |
| 3424 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3425 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3426 | InvokeRuntimeCallingConvention calling_convention; |
| 3427 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3428 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3429 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3430 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3431 | // Runtime helper puts the result in EAX, EDX. |
| 3432 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3433 | break; |
| 3434 | } |
| 3435 | case Primitive::kPrimFloat: |
| 3436 | case Primitive::kPrimDouble: { |
| 3437 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3438 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3439 | locations->SetOut(Location::SameAsFirstInput()); |
| 3440 | break; |
| 3441 | } |
| 3442 | |
| 3443 | default: |
| 3444 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3445 | } |
| 3446 | } |
| 3447 | |
| 3448 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3449 | LocationSummary* locations = div->GetLocations(); |
| 3450 | Location first = locations->InAt(0); |
| 3451 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3452 | |
| 3453 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3454 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3455 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3456 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3457 | break; |
| 3458 | } |
| 3459 | |
| 3460 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3461 | if (second.IsFpuRegister()) { |
| 3462 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3463 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3464 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3465 | DCHECK(!const_area->NeedsMaterialization()); |
| 3466 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3467 | codegen_->LiteralFloatAddress( |
| 3468 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3469 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3470 | } else { |
| 3471 | DCHECK(second.IsStackSlot()); |
| 3472 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3473 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3474 | break; |
| 3475 | } |
| 3476 | |
| 3477 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3478 | if (second.IsFpuRegister()) { |
| 3479 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3480 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3481 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3482 | DCHECK(!const_area->NeedsMaterialization()); |
| 3483 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3484 | codegen_->LiteralDoubleAddress( |
| 3485 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3486 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3487 | } else { |
| 3488 | DCHECK(second.IsDoubleStackSlot()); |
| 3489 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3490 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3491 | break; |
| 3492 | } |
| 3493 | |
| 3494 | default: |
| 3495 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3496 | } |
| 3497 | } |
| 3498 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3499 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3500 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3501 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3502 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3503 | ? LocationSummary::kCall |
| 3504 | : LocationSummary::kNoCall; |
| 3505 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3506 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3507 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3508 | case Primitive::kPrimInt: { |
| 3509 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3510 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3511 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3512 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3513 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3514 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3515 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3516 | locations->AddTemp(Location::RequiresRegister()); |
| 3517 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3518 | break; |
| 3519 | } |
| 3520 | case Primitive::kPrimLong: { |
| 3521 | InvokeRuntimeCallingConvention calling_convention; |
| 3522 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3523 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3524 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3525 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3526 | // Runtime helper puts the result in EAX, EDX. |
| 3527 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3528 | break; |
| 3529 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3530 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3531 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3532 | locations->SetInAt(0, Location::Any()); |
| 3533 | locations->SetInAt(1, Location::Any()); |
| 3534 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3535 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | break; |
| 3537 | } |
| 3538 | |
| 3539 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3540 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3545 | Primitive::Type type = rem->GetResultType(); |
| 3546 | switch (type) { |
| 3547 | case Primitive::kPrimInt: |
| 3548 | case Primitive::kPrimLong: { |
| 3549 | GenerateDivRemIntegral(rem); |
| 3550 | break; |
| 3551 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3552 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3554 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3555 | break; |
| 3556 | } |
| 3557 | default: |
| 3558 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3559 | } |
| 3560 | } |
| 3561 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3562 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3563 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3564 | ? LocationSummary::kCallOnSlowPath |
| 3565 | : LocationSummary::kNoCall; |
| 3566 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3567 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3568 | case Primitive::kPrimByte: |
| 3569 | case Primitive::kPrimChar: |
| 3570 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3571 | case Primitive::kPrimInt: { |
| 3572 | locations->SetInAt(0, Location::Any()); |
| 3573 | break; |
| 3574 | } |
| 3575 | case Primitive::kPrimLong: { |
| 3576 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3577 | if (!instruction->IsConstant()) { |
| 3578 | locations->AddTemp(Location::RequiresRegister()); |
| 3579 | } |
| 3580 | break; |
| 3581 | } |
| 3582 | default: |
| 3583 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3584 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3585 | if (instruction->HasUses()) { |
| 3586 | locations->SetOut(Location::SameAsFirstInput()); |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3591 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3592 | codegen_->AddSlowPath(slow_path); |
| 3593 | |
| 3594 | LocationSummary* locations = instruction->GetLocations(); |
| 3595 | Location value = locations->InAt(0); |
| 3596 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3597 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3598 | case Primitive::kPrimByte: |
| 3599 | case Primitive::kPrimChar: |
| 3600 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3601 | case Primitive::kPrimInt: { |
| 3602 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3603 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3604 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3605 | } else if (value.IsStackSlot()) { |
| 3606 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3607 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3608 | } else { |
| 3609 | DCHECK(value.IsConstant()) << value; |
| 3610 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3611 | __ jmp(slow_path->GetEntryLabel()); |
| 3612 | } |
| 3613 | } |
| 3614 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3615 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3616 | case Primitive::kPrimLong: { |
| 3617 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3618 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3619 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3620 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3621 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3622 | } else { |
| 3623 | DCHECK(value.IsConstant()) << value; |
| 3624 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3625 | __ jmp(slow_path->GetEntryLabel()); |
| 3626 | } |
| 3627 | } |
| 3628 | break; |
| 3629 | } |
| 3630 | default: |
| 3631 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3632 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3635 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3636 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3637 | |
| 3638 | LocationSummary* locations = |
| 3639 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3640 | |
| 3641 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3642 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3643 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3644 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3645 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3646 | // The shift count needs to be in CL or a constant. |
| 3647 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3648 | locations->SetOut(Location::SameAsFirstInput()); |
| 3649 | break; |
| 3650 | } |
| 3651 | default: |
| 3652 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3653 | } |
| 3654 | } |
| 3655 | |
| 3656 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3657 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3658 | |
| 3659 | LocationSummary* locations = op->GetLocations(); |
| 3660 | Location first = locations->InAt(0); |
| 3661 | Location second = locations->InAt(1); |
| 3662 | DCHECK(first.Equals(locations->Out())); |
| 3663 | |
| 3664 | switch (op->GetResultType()) { |
| 3665 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3666 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3667 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3668 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3669 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3670 | DCHECK_EQ(ECX, second_reg); |
| 3671 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3672 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3673 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3674 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3675 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3676 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3677 | } |
| 3678 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3679 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3680 | if (shift == 0) { |
| 3681 | return; |
| 3682 | } |
| 3683 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3684 | if (op->IsShl()) { |
| 3685 | __ shll(first_reg, imm); |
| 3686 | } else if (op->IsShr()) { |
| 3687 | __ sarl(first_reg, imm); |
| 3688 | } else { |
| 3689 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | break; |
| 3693 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3694 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3695 | if (second.IsRegister()) { |
| 3696 | Register second_reg = second.AsRegister<Register>(); |
| 3697 | DCHECK_EQ(ECX, second_reg); |
| 3698 | if (op->IsShl()) { |
| 3699 | GenerateShlLong(first, second_reg); |
| 3700 | } else if (op->IsShr()) { |
| 3701 | GenerateShrLong(first, second_reg); |
| 3702 | } else { |
| 3703 | GenerateUShrLong(first, second_reg); |
| 3704 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3705 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3706 | // Shift by a constant. |
| 3707 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3708 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3709 | if (shift != 0) { |
| 3710 | if (op->IsShl()) { |
| 3711 | GenerateShlLong(first, shift); |
| 3712 | } else if (op->IsShr()) { |
| 3713 | GenerateShrLong(first, shift); |
| 3714 | } else { |
| 3715 | GenerateUShrLong(first, shift); |
| 3716 | } |
| 3717 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3718 | } |
| 3719 | break; |
| 3720 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3721 | default: |
| 3722 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3723 | } |
| 3724 | } |
| 3725 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3726 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3727 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3728 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3729 | if (shift == 1) { |
| 3730 | // This is just an addition. |
| 3731 | __ addl(low, low); |
| 3732 | __ adcl(high, high); |
| 3733 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3734 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3735 | codegen_->EmitParallelMoves( |
| 3736 | loc.ToLow(), |
| 3737 | loc.ToHigh(), |
| 3738 | Primitive::kPrimInt, |
| 3739 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3740 | loc.ToLow(), |
| 3741 | Primitive::kPrimInt); |
| 3742 | } else if (shift > 32) { |
| 3743 | // Low part becomes 0. High part is low part << (shift-32). |
| 3744 | __ movl(high, low); |
| 3745 | __ shll(high, Immediate(shift - 32)); |
| 3746 | __ xorl(low, low); |
| 3747 | } else { |
| 3748 | // Between 1 and 31. |
| 3749 | __ shld(high, low, Immediate(shift)); |
| 3750 | __ shll(low, Immediate(shift)); |
| 3751 | } |
| 3752 | } |
| 3753 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3754 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3755 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3756 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3757 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3758 | __ testl(shifter, Immediate(32)); |
| 3759 | __ j(kEqual, &done); |
| 3760 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3761 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3762 | __ Bind(&done); |
| 3763 | } |
| 3764 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3765 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3766 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3767 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3768 | if (shift == 32) { |
| 3769 | // Need to copy the sign. |
| 3770 | DCHECK_NE(low, high); |
| 3771 | __ movl(low, high); |
| 3772 | __ sarl(high, Immediate(31)); |
| 3773 | } else if (shift > 32) { |
| 3774 | DCHECK_NE(low, high); |
| 3775 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3776 | __ movl(low, high); |
| 3777 | __ sarl(high, Immediate(31)); |
| 3778 | __ sarl(low, Immediate(shift - 32)); |
| 3779 | } else { |
| 3780 | // Between 1 and 31. |
| 3781 | __ shrd(low, high, Immediate(shift)); |
| 3782 | __ sarl(high, Immediate(shift)); |
| 3783 | } |
| 3784 | } |
| 3785 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3786 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3787 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3788 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3789 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3790 | __ testl(shifter, Immediate(32)); |
| 3791 | __ j(kEqual, &done); |
| 3792 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3793 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3794 | __ Bind(&done); |
| 3795 | } |
| 3796 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3797 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3798 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3799 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3800 | if (shift == 32) { |
| 3801 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3802 | codegen_->EmitParallelMoves( |
| 3803 | loc.ToHigh(), |
| 3804 | loc.ToLow(), |
| 3805 | Primitive::kPrimInt, |
| 3806 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3807 | loc.ToHigh(), |
| 3808 | Primitive::kPrimInt); |
| 3809 | } else if (shift > 32) { |
| 3810 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3811 | __ movl(low, high); |
| 3812 | __ shrl(low, Immediate(shift - 32)); |
| 3813 | __ xorl(high, high); |
| 3814 | } else { |
| 3815 | // Between 1 and 31. |
| 3816 | __ shrd(low, high, Immediate(shift)); |
| 3817 | __ shrl(high, Immediate(shift)); |
| 3818 | } |
| 3819 | } |
| 3820 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3821 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3822 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3823 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3824 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3825 | __ testl(shifter, Immediate(32)); |
| 3826 | __ j(kEqual, &done); |
| 3827 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3828 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3829 | __ Bind(&done); |
| 3830 | } |
| 3831 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3832 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3833 | LocationSummary* locations = |
| 3834 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3835 | |
| 3836 | switch (ror->GetResultType()) { |
| 3837 | case Primitive::kPrimLong: |
| 3838 | // Add the temporary needed. |
| 3839 | locations->AddTemp(Location::RequiresRegister()); |
| 3840 | FALLTHROUGH_INTENDED; |
| 3841 | case Primitive::kPrimInt: |
| 3842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3843 | // The shift count needs to be in CL (unless it is a constant). |
| 3844 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3845 | locations->SetOut(Location::SameAsFirstInput()); |
| 3846 | break; |
| 3847 | default: |
| 3848 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3849 | UNREACHABLE(); |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3854 | LocationSummary* locations = ror->GetLocations(); |
| 3855 | Location first = locations->InAt(0); |
| 3856 | Location second = locations->InAt(1); |
| 3857 | |
| 3858 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3859 | Register first_reg = first.AsRegister<Register>(); |
| 3860 | if (second.IsRegister()) { |
| 3861 | Register second_reg = second.AsRegister<Register>(); |
| 3862 | __ rorl(first_reg, second_reg); |
| 3863 | } else { |
| 3864 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3865 | __ rorl(first_reg, imm); |
| 3866 | } |
| 3867 | return; |
| 3868 | } |
| 3869 | |
| 3870 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3871 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3872 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3873 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3874 | if (second.IsRegister()) { |
| 3875 | Register second_reg = second.AsRegister<Register>(); |
| 3876 | DCHECK_EQ(second_reg, ECX); |
| 3877 | __ movl(temp_reg, first_reg_hi); |
| 3878 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3879 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3880 | __ movl(temp_reg, first_reg_hi); |
| 3881 | __ testl(second_reg, Immediate(32)); |
| 3882 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3883 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3884 | } else { |
| 3885 | int32_t shift_amt = |
| 3886 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3887 | if (shift_amt == 0) { |
| 3888 | // Already fine. |
| 3889 | return; |
| 3890 | } |
| 3891 | if (shift_amt == 32) { |
| 3892 | // Just swap. |
| 3893 | __ movl(temp_reg, first_reg_lo); |
| 3894 | __ movl(first_reg_lo, first_reg_hi); |
| 3895 | __ movl(first_reg_hi, temp_reg); |
| 3896 | return; |
| 3897 | } |
| 3898 | |
| 3899 | Immediate imm(shift_amt); |
| 3900 | // Save the constents of the low value. |
| 3901 | __ movl(temp_reg, first_reg_lo); |
| 3902 | |
| 3903 | // Shift right into low, feeding bits from high. |
| 3904 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3905 | |
| 3906 | // Shift right into high, feeding bits from the original low. |
| 3907 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3908 | |
| 3909 | // Swap if needed. |
| 3910 | if (shift_amt > 32) { |
| 3911 | __ movl(temp_reg, first_reg_lo); |
| 3912 | __ movl(first_reg_lo, first_reg_hi); |
| 3913 | __ movl(first_reg_hi, temp_reg); |
| 3914 | } |
| 3915 | } |
| 3916 | } |
| 3917 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3918 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3919 | HandleShift(shl); |
| 3920 | } |
| 3921 | |
| 3922 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3923 | HandleShift(shl); |
| 3924 | } |
| 3925 | |
| 3926 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3927 | HandleShift(shr); |
| 3928 | } |
| 3929 | |
| 3930 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3931 | HandleShift(shr); |
| 3932 | } |
| 3933 | |
| 3934 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3935 | HandleShift(ushr); |
| 3936 | } |
| 3937 | |
| 3938 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3939 | HandleShift(ushr); |
| 3940 | } |
| 3941 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3942 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3943 | LocationSummary* locations = |
| 3944 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3945 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3946 | if (instruction->IsStringAlloc()) { |
| 3947 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3948 | } else { |
| 3949 | InvokeRuntimeCallingConvention calling_convention; |
| 3950 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3951 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3952 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3956 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3957 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3958 | if (instruction->IsStringAlloc()) { |
| 3959 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3960 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3961 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3962 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3963 | __ call(Address(temp, code_offset.Int32Value())); |
| 3964 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3965 | } else { |
| 3966 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3967 | instruction, |
| 3968 | instruction->GetDexPc(), |
| 3969 | nullptr); |
| 3970 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3971 | DCHECK(!codegen_->IsLeafMethod()); |
| 3972 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3973 | } |
| 3974 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3975 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3976 | LocationSummary* locations = |
| 3977 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3978 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3979 | InvokeRuntimeCallingConvention calling_convention; |
| 3980 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3981 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3982 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3986 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3987 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3988 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3989 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3990 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3991 | instruction, |
| 3992 | instruction->GetDexPc(), |
| 3993 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3994 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3995 | DCHECK(!codegen_->IsLeafMethod()); |
| 3996 | } |
| 3997 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3998 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3999 | LocationSummary* locations = |
| 4000 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4001 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4002 | if (location.IsStackSlot()) { |
| 4003 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4004 | } else if (location.IsDoubleStackSlot()) { |
| 4005 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4006 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4007 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4008 | } |
| 4009 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4010 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4011 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4012 | } |
| 4013 | |
| 4014 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4015 | LocationSummary* locations = |
| 4016 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4017 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4018 | } |
| 4019 | |
| 4020 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4021 | } |
| 4022 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4023 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4024 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4025 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4027 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4028 | } |
| 4029 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4030 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4031 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4032 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4033 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4034 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4035 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4036 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4037 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4038 | break; |
| 4039 | |
| 4040 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4041 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4042 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4043 | break; |
| 4044 | |
| 4045 | default: |
| 4046 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4047 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4048 | } |
| 4049 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4050 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4051 | LocationSummary* locations = |
| 4052 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4053 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4054 | locations->SetOut(Location::SameAsFirstInput()); |
| 4055 | } |
| 4056 | |
| 4057 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4058 | LocationSummary* locations = bool_not->GetLocations(); |
| 4059 | Location in = locations->InAt(0); |
| 4060 | Location out = locations->Out(); |
| 4061 | DCHECK(in.Equals(out)); |
| 4062 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4063 | } |
| 4064 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4065 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4066 | LocationSummary* locations = |
| 4067 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4068 | switch (compare->InputAt(0)->GetType()) { |
| 4069 | case Primitive::kPrimLong: { |
| 4070 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4071 | locations->SetInAt(1, Location::Any()); |
| 4072 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4073 | break; |
| 4074 | } |
| 4075 | case Primitive::kPrimFloat: |
| 4076 | case Primitive::kPrimDouble: { |
| 4077 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4078 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4079 | locations->SetOut(Location::RequiresRegister()); |
| 4080 | break; |
| 4081 | } |
| 4082 | default: |
| 4083 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4084 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4085 | } |
| 4086 | |
| 4087 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4088 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4089 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4090 | Location left = locations->InAt(0); |
| 4091 | Location right = locations->InAt(1); |
| 4092 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4093 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4094 | switch (compare->InputAt(0)->GetType()) { |
| 4095 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4096 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4097 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4098 | int32_t val_low = 0; |
| 4099 | int32_t val_high = 0; |
| 4100 | bool right_is_const = false; |
| 4101 | |
| 4102 | if (right.IsConstant()) { |
| 4103 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4104 | right_is_const = true; |
| 4105 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4106 | val_low = Low32Bits(val); |
| 4107 | val_high = High32Bits(val); |
| 4108 | } |
| 4109 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4110 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4111 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4112 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4113 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4114 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4115 | DCHECK(right_is_const) << right; |
| 4116 | if (val_high == 0) { |
| 4117 | __ testl(left_high, left_high); |
| 4118 | } else { |
| 4119 | __ cmpl(left_high, Immediate(val_high)); |
| 4120 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4121 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4122 | __ j(kLess, &less); // Signed compare. |
| 4123 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4124 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4125 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4126 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4127 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4128 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4129 | DCHECK(right_is_const) << right; |
| 4130 | if (val_low == 0) { |
| 4131 | __ testl(left_low, left_low); |
| 4132 | } else { |
| 4133 | __ cmpl(left_low, Immediate(val_low)); |
| 4134 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4135 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4136 | break; |
| 4137 | } |
| 4138 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4139 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4140 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4141 | break; |
| 4142 | } |
| 4143 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4144 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4145 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4146 | break; |
| 4147 | } |
| 4148 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4149 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4150 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4151 | __ movl(out, Immediate(0)); |
| 4152 | __ j(kEqual, &done); |
| 4153 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4154 | |
| 4155 | __ Bind(&greater); |
| 4156 | __ movl(out, Immediate(1)); |
| 4157 | __ jmp(&done); |
| 4158 | |
| 4159 | __ Bind(&less); |
| 4160 | __ movl(out, Immediate(-1)); |
| 4161 | |
| 4162 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4163 | } |
| 4164 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4165 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4166 | LocationSummary* locations = |
| 4167 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4168 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4169 | locations->SetInAt(i, Location::Any()); |
| 4170 | } |
| 4171 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4174 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4175 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4178 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4179 | /* |
| 4180 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4181 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4182 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4183 | */ |
| 4184 | switch (kind) { |
| 4185 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4186 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4187 | break; |
| 4188 | } |
| 4189 | case MemBarrierKind::kAnyStore: |
| 4190 | case MemBarrierKind::kLoadAny: |
| 4191 | case MemBarrierKind::kStoreStore: { |
| 4192 | // nop |
| 4193 | break; |
| 4194 | } |
| 4195 | default: |
| 4196 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4197 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4200 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4201 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4202 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4203 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4204 | |
| 4205 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4206 | // is incompatible with it. |
| 4207 | if (GetGraph()->HasIrreducibleLoops() && |
| 4208 | (dispatch_info.method_load_kind == |
| 4209 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4210 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4211 | } |
| 4212 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4213 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4214 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4215 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4216 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4217 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4218 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4219 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4220 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4221 | 0u |
| 4222 | }; |
| 4223 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4224 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4225 | } |
| 4226 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4227 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4228 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4229 | Register temp) { |
| 4230 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4231 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4232 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4233 | return location.AsRegister<Register>(); |
| 4234 | } |
| 4235 | // For intrinsics we allow any location, so it may be on the stack. |
| 4236 | if (!location.IsRegister()) { |
| 4237 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4238 | return temp; |
| 4239 | } |
| 4240 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4241 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4242 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4243 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4244 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4245 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4246 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4247 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4248 | __ movl(temp, Address(ESP, stack_offset)); |
| 4249 | return temp; |
| 4250 | } |
| 4251 | return location.AsRegister<Register>(); |
| 4252 | } |
| 4253 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4254 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4255 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4256 | switch (invoke->GetMethodLoadKind()) { |
| 4257 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4258 | // temp = thread->string_init_entrypoint |
| 4259 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4260 | break; |
| 4261 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4262 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4263 | break; |
| 4264 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4265 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4266 | break; |
| 4267 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4268 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4269 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4270 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4271 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4272 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4273 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4274 | temp.AsRegister<Register>()); |
| 4275 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4276 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4277 | // Add the patch entry and bind its label at the end of the instruction. |
| 4278 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4279 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4280 | break; |
| 4281 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4282 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4283 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4284 | Register method_reg; |
| 4285 | Register reg = temp.AsRegister<Register>(); |
| 4286 | if (current_method.IsRegister()) { |
| 4287 | method_reg = current_method.AsRegister<Register>(); |
| 4288 | } else { |
| 4289 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 4290 | DCHECK(!current_method.IsValid()); |
| 4291 | method_reg = reg; |
| 4292 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4293 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4294 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4295 | __ movl(reg, Address(method_reg, |
| 4296 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4297 | // temp = temp[index_in_cache] |
| 4298 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4299 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4300 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4301 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | switch (invoke->GetCodePtrLocation()) { |
| 4305 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4306 | __ call(GetFrameEntryLabel()); |
| 4307 | break; |
| 4308 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4309 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4310 | Label* label = &relative_call_patches_.back().label; |
| 4311 | __ call(label); // Bind to the patch label, override at link time. |
| 4312 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4313 | break; |
| 4314 | } |
| 4315 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4316 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4317 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4318 | LOG(FATAL) << "Unsupported"; |
| 4319 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4320 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4321 | // (callee_method + offset_of_quick_compiled_code)() |
| 4322 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4323 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4324 | kX86WordSize).Int32Value())); |
| 4325 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4329 | } |
| 4330 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4331 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4332 | Register temp = temp_in.AsRegister<Register>(); |
| 4333 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4334 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4335 | |
| 4336 | // Use the calling convention instead of the location of the receiver, as |
| 4337 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4338 | // slow path, the arguments have been moved to the right place, so here we are |
| 4339 | // guaranteed that the receiver is the first register of the calling convention. |
| 4340 | InvokeDexCallingConvention calling_convention; |
| 4341 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4342 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4343 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4344 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4345 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4346 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4347 | // emit a read barrier for the previous class reference load. |
| 4348 | // However this is not required in practice, as this is an |
| 4349 | // intermediate/temporary reference and because the current |
| 4350 | // concurrent copying collector keeps the from-space memory |
| 4351 | // intact/accessible until the end of the marking phase (the |
| 4352 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4353 | __ MaybeUnpoisonHeapReference(temp); |
| 4354 | // temp = temp->GetMethodAt(method_offset); |
| 4355 | __ movl(temp, Address(temp, method_offset)); |
| 4356 | // call temp->GetEntryPoint(); |
| 4357 | __ call(Address( |
| 4358 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4359 | } |
| 4360 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4361 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4362 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4363 | size_t size = |
| 4364 | method_patches_.size() + |
| 4365 | relative_call_patches_.size() + |
| 4366 | pc_relative_dex_cache_patches_.size(); |
| 4367 | linker_patches->reserve(size); |
| 4368 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4369 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4370 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4371 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4372 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4373 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4374 | info.target_method.dex_file, |
| 4375 | info.target_method.dex_method_index)); |
| 4376 | } |
| 4377 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4378 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4379 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4380 | info.target_method.dex_file, |
| 4381 | info.target_method.dex_method_index)); |
| 4382 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4383 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4384 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4385 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4386 | &info.target_dex_file, |
| 4387 | GetMethodAddressOffset(), |
| 4388 | info.element_offset)); |
| 4389 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4390 | } |
| 4391 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4392 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4393 | Register card, |
| 4394 | Register object, |
| 4395 | Register value, |
| 4396 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4397 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4398 | if (value_can_be_null) { |
| 4399 | __ testl(value, value); |
| 4400 | __ j(kEqual, &is_null); |
| 4401 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4402 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4403 | __ movl(temp, object); |
| 4404 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4405 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4406 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4407 | if (value_can_be_null) { |
| 4408 | __ Bind(&is_null); |
| 4409 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4410 | } |
| 4411 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4412 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4413 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4414 | |
| 4415 | bool object_field_get_with_read_barrier = |
| 4416 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4417 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4418 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4419 | kEmitCompilerReadBarrier ? |
| 4420 | LocationSummary::kCallOnSlowPath : |
| 4421 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4422 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4423 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4424 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4425 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4426 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4427 | // The output overlaps in case of long: we don't want the low move |
| 4428 | // to overwrite the object's location. Likewise, in the case of |
| 4429 | // an object field get with read barriers enabled, we do not want |
| 4430 | // the move to overwrite the object's location, as we need it to emit |
| 4431 | // the read barrier. |
| 4432 | locations->SetOut( |
| 4433 | Location::RequiresRegister(), |
| 4434 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4435 | Location::kOutputOverlap : |
| 4436 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4437 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4438 | |
| 4439 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4440 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4441 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4442 | // load the temp into the XMM and then copy the XMM into the |
| 4443 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4444 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4445 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4446 | // We need a temporary register for the read barrier marking slow |
| 4447 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4448 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4449 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4450 | } |
| 4451 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4452 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4453 | const FieldInfo& field_info) { |
| 4454 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4455 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4456 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4457 | Location base_loc = locations->InAt(0); |
| 4458 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4459 | Location out = locations->Out(); |
| 4460 | bool is_volatile = field_info.IsVolatile(); |
| 4461 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4462 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4463 | |
| 4464 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4465 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4466 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | break; |
| 4468 | } |
| 4469 | |
| 4470 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4471 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4472 | break; |
| 4473 | } |
| 4474 | |
| 4475 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4476 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4477 | break; |
| 4478 | } |
| 4479 | |
| 4480 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4481 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4482 | break; |
| 4483 | } |
| 4484 | |
| 4485 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4486 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4487 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4488 | |
| 4489 | case Primitive::kPrimNot: { |
| 4490 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4491 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4492 | Location temp_loc = locations->GetTemp(0); |
| 4493 | // Note that a potential implicit null check is handled in this |
| 4494 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4495 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4496 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4497 | if (is_volatile) { |
| 4498 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4499 | } |
| 4500 | } else { |
| 4501 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4502 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4503 | if (is_volatile) { |
| 4504 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4505 | } |
| 4506 | // If read barriers are enabled, emit read barriers other than |
| 4507 | // Baker's using a slow path (and also unpoison the loaded |
| 4508 | // reference, if heap poisoning is enabled). |
| 4509 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4510 | } |
| 4511 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4515 | if (is_volatile) { |
| 4516 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4517 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4518 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4519 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4520 | __ psrlq(temp, Immediate(32)); |
| 4521 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4522 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4523 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4524 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4525 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4526 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4527 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4528 | break; |
| 4529 | } |
| 4530 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4531 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4533 | break; |
| 4534 | } |
| 4535 | |
| 4536 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4537 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4538 | break; |
| 4539 | } |
| 4540 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4541 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4542 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4543 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4544 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4546 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4547 | // Potential implicit null checks, in the case of reference or |
| 4548 | // long fields, are handled in the previous switch statement. |
| 4549 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4550 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4551 | } |
| 4552 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4553 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4554 | if (field_type == Primitive::kPrimNot) { |
| 4555 | // Memory barriers, in the case of references, are also handled |
| 4556 | // in the previous switch statement. |
| 4557 | } else { |
| 4558 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4559 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4560 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4564 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4565 | |
| 4566 | LocationSummary* locations = |
| 4567 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4568 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4569 | bool is_volatile = field_info.IsVolatile(); |
| 4570 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4571 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4572 | || (field_type == Primitive::kPrimByte); |
| 4573 | |
| 4574 | // The register allocator does not support multiple |
| 4575 | // inputs that die at entry with one in a specific register. |
| 4576 | if (is_byte_type) { |
| 4577 | // Ensure the value is in a byte register. |
| 4578 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4579 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4580 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4581 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4582 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4583 | } else { |
| 4584 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4585 | } |
| 4586 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4587 | // 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] | 4588 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4589 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4590 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4591 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4592 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4593 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4594 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4595 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4596 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4597 | } else { |
| 4598 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4599 | |
| 4600 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4601 | // Temporary registers for the write barrier. |
| 4602 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4603 | // Ensure the card is in a byte register. |
| 4604 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4605 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4610 | const FieldInfo& field_info, |
| 4611 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4613 | |
| 4614 | LocationSummary* locations = instruction->GetLocations(); |
| 4615 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4616 | Location value = locations->InAt(1); |
| 4617 | bool is_volatile = field_info.IsVolatile(); |
| 4618 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4619 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4620 | bool needs_write_barrier = |
| 4621 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | |
| 4623 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4624 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4627 | bool maybe_record_implicit_null_check_done = false; |
| 4628 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4629 | switch (field_type) { |
| 4630 | case Primitive::kPrimBoolean: |
| 4631 | case Primitive::kPrimByte: { |
| 4632 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4633 | break; |
| 4634 | } |
| 4635 | |
| 4636 | case Primitive::kPrimShort: |
| 4637 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4638 | if (value.IsConstant()) { |
| 4639 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4640 | __ movw(Address(base, offset), Immediate(v)); |
| 4641 | } else { |
| 4642 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4643 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | break; |
| 4645 | } |
| 4646 | |
| 4647 | case Primitive::kPrimInt: |
| 4648 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4649 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4650 | // Note that in the case where `value` is a null reference, |
| 4651 | // we do not enter this block, as the reference does not |
| 4652 | // need poisoning. |
| 4653 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4654 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4655 | __ movl(temp, value.AsRegister<Register>()); |
| 4656 | __ PoisonHeapReference(temp); |
| 4657 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4658 | } else if (value.IsConstant()) { |
| 4659 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4660 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4661 | } else { |
| 4662 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4663 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4664 | break; |
| 4665 | } |
| 4666 | |
| 4667 | case Primitive::kPrimLong: { |
| 4668 | if (is_volatile) { |
| 4669 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4670 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4671 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4672 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4673 | __ punpckldq(temp1, temp2); |
| 4674 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4675 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4676 | } else if (value.IsConstant()) { |
| 4677 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4678 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4679 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4680 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4681 | } else { |
| 4682 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4683 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4684 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4685 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4686 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | break; |
| 4688 | } |
| 4689 | |
| 4690 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4691 | if (value.IsConstant()) { |
| 4692 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4693 | __ movl(Address(base, offset), Immediate(v)); |
| 4694 | } else { |
| 4695 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4696 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4697 | break; |
| 4698 | } |
| 4699 | |
| 4700 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4701 | if (value.IsConstant()) { |
| 4702 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4703 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4704 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4705 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4706 | maybe_record_implicit_null_check_done = true; |
| 4707 | } else { |
| 4708 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4709 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4710 | break; |
| 4711 | } |
| 4712 | |
| 4713 | case Primitive::kPrimVoid: |
| 4714 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4715 | UNREACHABLE(); |
| 4716 | } |
| 4717 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4718 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4719 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4720 | } |
| 4721 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4722 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4723 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4724 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4725 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4726 | } |
| 4727 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4728 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4729 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4734 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4735 | } |
| 4736 | |
| 4737 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4738 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4739 | } |
| 4740 | |
| 4741 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4742 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4743 | } |
| 4744 | |
| 4745 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4746 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4750 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4751 | } |
| 4752 | |
| 4753 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4754 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4758 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4759 | } |
| 4760 | |
| 4761 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4762 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4763 | } |
| 4764 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4765 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4766 | HUnresolvedInstanceFieldGet* instruction) { |
| 4767 | FieldAccessCallingConventionX86 calling_convention; |
| 4768 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4769 | instruction, instruction->GetFieldType(), calling_convention); |
| 4770 | } |
| 4771 | |
| 4772 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4773 | HUnresolvedInstanceFieldGet* instruction) { |
| 4774 | FieldAccessCallingConventionX86 calling_convention; |
| 4775 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4776 | instruction->GetFieldType(), |
| 4777 | instruction->GetFieldIndex(), |
| 4778 | instruction->GetDexPc(), |
| 4779 | calling_convention); |
| 4780 | } |
| 4781 | |
| 4782 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4783 | HUnresolvedInstanceFieldSet* instruction) { |
| 4784 | FieldAccessCallingConventionX86 calling_convention; |
| 4785 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4786 | instruction, instruction->GetFieldType(), calling_convention); |
| 4787 | } |
| 4788 | |
| 4789 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4790 | HUnresolvedInstanceFieldSet* instruction) { |
| 4791 | FieldAccessCallingConventionX86 calling_convention; |
| 4792 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4793 | instruction->GetFieldType(), |
| 4794 | instruction->GetFieldIndex(), |
| 4795 | instruction->GetDexPc(), |
| 4796 | calling_convention); |
| 4797 | } |
| 4798 | |
| 4799 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4800 | HUnresolvedStaticFieldGet* instruction) { |
| 4801 | FieldAccessCallingConventionX86 calling_convention; |
| 4802 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4803 | instruction, instruction->GetFieldType(), calling_convention); |
| 4804 | } |
| 4805 | |
| 4806 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4807 | HUnresolvedStaticFieldGet* instruction) { |
| 4808 | FieldAccessCallingConventionX86 calling_convention; |
| 4809 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4810 | instruction->GetFieldType(), |
| 4811 | instruction->GetFieldIndex(), |
| 4812 | instruction->GetDexPc(), |
| 4813 | calling_convention); |
| 4814 | } |
| 4815 | |
| 4816 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4817 | HUnresolvedStaticFieldSet* instruction) { |
| 4818 | FieldAccessCallingConventionX86 calling_convention; |
| 4819 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4820 | instruction, instruction->GetFieldType(), calling_convention); |
| 4821 | } |
| 4822 | |
| 4823 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4824 | HUnresolvedStaticFieldSet* instruction) { |
| 4825 | FieldAccessCallingConventionX86 calling_convention; |
| 4826 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4827 | instruction->GetFieldType(), |
| 4828 | instruction->GetFieldIndex(), |
| 4829 | instruction->GetDexPc(), |
| 4830 | calling_convention); |
| 4831 | } |
| 4832 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4833 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4834 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4835 | ? LocationSummary::kCallOnSlowPath |
| 4836 | : LocationSummary::kNoCall; |
| 4837 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4838 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4839 | ? Location::RequiresRegister() |
| 4840 | : Location::Any(); |
| 4841 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4842 | if (instruction->HasUses()) { |
| 4843 | locations->SetOut(Location::SameAsFirstInput()); |
| 4844 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4845 | } |
| 4846 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4847 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4848 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4849 | return; |
| 4850 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4851 | LocationSummary* locations = instruction->GetLocations(); |
| 4852 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4853 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4854 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4855 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4856 | } |
| 4857 | |
| 4858 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4859 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4860 | codegen_->AddSlowPath(slow_path); |
| 4861 | |
| 4862 | LocationSummary* locations = instruction->GetLocations(); |
| 4863 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4864 | |
| 4865 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4866 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4867 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4868 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4869 | } else { |
| 4870 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4871 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4872 | __ jmp(slow_path->GetEntryLabel()); |
| 4873 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4874 | } |
| 4875 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4876 | } |
| 4877 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4878 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4879 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4880 | GenerateImplicitNullCheck(instruction); |
| 4881 | } else { |
| 4882 | GenerateExplicitNullCheck(instruction); |
| 4883 | } |
| 4884 | } |
| 4885 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4886 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4887 | bool object_array_get_with_read_barrier = |
| 4888 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4889 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4890 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4891 | object_array_get_with_read_barrier ? |
| 4892 | LocationSummary::kCallOnSlowPath : |
| 4893 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4894 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4895 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4896 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4897 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4898 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4899 | // The output overlaps in case of long: we don't want the low move |
| 4900 | // to overwrite the array's location. Likewise, in the case of an |
| 4901 | // object array get with read barriers enabled, we do not want the |
| 4902 | // move to overwrite the array's location, as we need it to emit |
| 4903 | // the read barrier. |
| 4904 | locations->SetOut( |
| 4905 | Location::RequiresRegister(), |
| 4906 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4907 | Location::kOutputOverlap : |
| 4908 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4909 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4910 | // We need a temporary register for the read barrier marking slow |
| 4911 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4912 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4913 | locations->AddTemp(Location::RequiresRegister()); |
| 4914 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4918 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4919 | Location obj_loc = locations->InAt(0); |
| 4920 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4921 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4922 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4923 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4924 | Primitive::Type type = instruction->GetType(); |
| 4925 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4926 | case Primitive::kPrimBoolean: { |
| 4927 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4928 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4929 | if (index.IsConstant()) { |
| 4930 | __ movzxb(out, Address(obj, |
| 4931 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4932 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4933 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4934 | } |
| 4935 | break; |
| 4936 | } |
| 4937 | |
| 4938 | case Primitive::kPrimByte: { |
| 4939 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4940 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4941 | if (index.IsConstant()) { |
| 4942 | __ movsxb(out, Address(obj, |
| 4943 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4944 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4945 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4946 | } |
| 4947 | break; |
| 4948 | } |
| 4949 | |
| 4950 | case Primitive::kPrimShort: { |
| 4951 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4952 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4953 | if (index.IsConstant()) { |
| 4954 | __ movsxw(out, Address(obj, |
| 4955 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4956 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4957 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4958 | } |
| 4959 | break; |
| 4960 | } |
| 4961 | |
| 4962 | case Primitive::kPrimChar: { |
| 4963 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4964 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4965 | if (index.IsConstant()) { |
| 4966 | __ movzxw(out, Address(obj, |
| 4967 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4968 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4969 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4970 | } |
| 4971 | break; |
| 4972 | } |
| 4973 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4974 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4975 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4976 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4977 | if (index.IsConstant()) { |
| 4978 | __ movl(out, Address(obj, |
| 4979 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4980 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4981 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4982 | } |
| 4983 | break; |
| 4984 | } |
| 4985 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4986 | case Primitive::kPrimNot: { |
| 4987 | static_assert( |
| 4988 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4989 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4990 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4991 | // /* HeapReference<Object> */ out = |
| 4992 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4993 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4994 | Location temp = locations->GetTemp(0); |
| 4995 | // Note that a potential implicit null check is handled in this |
| 4996 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4997 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4998 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4999 | } else { |
| 5000 | Register out = out_loc.AsRegister<Register>(); |
| 5001 | if (index.IsConstant()) { |
| 5002 | uint32_t offset = |
| 5003 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5004 | __ movl(out, Address(obj, offset)); |
| 5005 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5006 | // If read barriers are enabled, emit read barriers other than |
| 5007 | // Baker's using a slow path (and also unpoison the loaded |
| 5008 | // reference, if heap poisoning is enabled). |
| 5009 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5010 | } else { |
| 5011 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5012 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5013 | // If read barriers are enabled, emit read barriers other than |
| 5014 | // Baker's using a slow path (and also unpoison the loaded |
| 5015 | // reference, if heap poisoning is enabled). |
| 5016 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5017 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5018 | } |
| 5019 | } |
| 5020 | break; |
| 5021 | } |
| 5022 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5023 | case Primitive::kPrimLong: { |
| 5024 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5025 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5026 | if (index.IsConstant()) { |
| 5027 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5028 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5029 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5030 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5031 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5032 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5033 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5034 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5035 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5036 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5037 | } |
| 5038 | break; |
| 5039 | } |
| 5040 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5041 | case Primitive::kPrimFloat: { |
| 5042 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5043 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5044 | if (index.IsConstant()) { |
| 5045 | __ movss(out, Address(obj, |
| 5046 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5047 | } else { |
| 5048 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5049 | } |
| 5050 | break; |
| 5051 | } |
| 5052 | |
| 5053 | case Primitive::kPrimDouble: { |
| 5054 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5055 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5056 | if (index.IsConstant()) { |
| 5057 | __ movsd(out, Address(obj, |
| 5058 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5059 | } else { |
| 5060 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5061 | } |
| 5062 | break; |
| 5063 | } |
| 5064 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5065 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5066 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5067 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5069 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5070 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5071 | // Potential implicit null checks, in the case of reference or |
| 5072 | // long arrays, are handled in the previous switch statement. |
| 5073 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5074 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5075 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 5079 | // This location builder might end up asking to up to four registers, which is |
| 5080 | // not currently possible for baseline. The situation in which we need four |
| 5081 | // registers cannot be met by baseline though, because it has not run any |
| 5082 | // optimization. |
| 5083 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5084 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5085 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5086 | bool needs_write_barrier = |
| 5087 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5088 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5089 | bool object_array_set_with_read_barrier = |
| 5090 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5091 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5092 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5093 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5094 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5095 | LocationSummary::kCallOnSlowPath : |
| 5096 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5097 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5098 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5099 | || (value_type == Primitive::kPrimByte); |
| 5100 | // We need the inputs to be different than the output in case of long operation. |
| 5101 | // In case of a byte operation, the register allocator does not support multiple |
| 5102 | // inputs that die at entry with one in a specific register. |
| 5103 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5104 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5105 | if (is_byte_type) { |
| 5106 | // Ensure the value is in a byte register. |
| 5107 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5108 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5109 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5110 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5111 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5112 | } |
| 5113 | if (needs_write_barrier) { |
| 5114 | // Temporary registers for the write barrier. |
| 5115 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5116 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5117 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5118 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5122 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5123 | Location array_loc = locations->InAt(0); |
| 5124 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5125 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5126 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5127 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5128 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5129 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5130 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5131 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5132 | bool needs_write_barrier = |
| 5133 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5134 | |
| 5135 | switch (value_type) { |
| 5136 | case Primitive::kPrimBoolean: |
| 5137 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5138 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5139 | Address address = index.IsConstant() |
| 5140 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5141 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5142 | if (value.IsRegister()) { |
| 5143 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5145 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5146 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5147 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5148 | break; |
| 5149 | } |
| 5150 | |
| 5151 | case Primitive::kPrimShort: |
| 5152 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5153 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5154 | Address address = index.IsConstant() |
| 5155 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5156 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5157 | if (value.IsRegister()) { |
| 5158 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5160 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5161 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5162 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | break; |
| 5164 | } |
| 5165 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5166 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5167 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5168 | Address address = index.IsConstant() |
| 5169 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5170 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5171 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5172 | if (!value.IsRegister()) { |
| 5173 | // Just setting null. |
| 5174 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5175 | DCHECK(value.IsConstant()) << value; |
| 5176 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5177 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5178 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5179 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5180 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5181 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5182 | |
| 5183 | DCHECK(needs_write_barrier); |
| 5184 | Register register_value = value.AsRegister<Register>(); |
| 5185 | NearLabel done, not_null, do_put; |
| 5186 | SlowPathCode* slow_path = nullptr; |
| 5187 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5188 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5189 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5190 | codegen_->AddSlowPath(slow_path); |
| 5191 | if (instruction->GetValueCanBeNull()) { |
| 5192 | __ testl(register_value, register_value); |
| 5193 | __ j(kNotEqual, ¬_null); |
| 5194 | __ movl(address, Immediate(0)); |
| 5195 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5196 | __ jmp(&done); |
| 5197 | __ Bind(¬_null); |
| 5198 | } |
| 5199 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5200 | if (kEmitCompilerReadBarrier) { |
| 5201 | // When read barriers are enabled, the type checking |
| 5202 | // instrumentation requires two read barriers: |
| 5203 | // |
| 5204 | // __ movl(temp2, temp); |
| 5205 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5206 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5207 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5208 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5209 | // |
| 5210 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5211 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5212 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5213 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5214 | // |
| 5215 | // __ cmpl(temp, temp2); |
| 5216 | // |
| 5217 | // However, the second read barrier may trash `temp`, as it |
| 5218 | // is a temporary register, and as such would not be saved |
| 5219 | // along with live registers before calling the runtime (nor |
| 5220 | // restored afterwards). So in this case, we bail out and |
| 5221 | // delegate the work to the array set slow path. |
| 5222 | // |
| 5223 | // TODO: Extend the register allocator to support a new |
| 5224 | // "(locally) live temp" location so as to avoid always |
| 5225 | // going into the slow path when read barriers are enabled. |
| 5226 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5227 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5228 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5229 | __ movl(temp, Address(array, class_offset)); |
| 5230 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5231 | __ MaybeUnpoisonHeapReference(temp); |
| 5232 | |
| 5233 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5234 | __ movl(temp, Address(temp, component_offset)); |
| 5235 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5236 | // nor the object reference in `register_value->klass`, as |
| 5237 | // we are comparing two poisoned references. |
| 5238 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5239 | |
| 5240 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5241 | __ j(kEqual, &do_put); |
| 5242 | // If heap poisoning is enabled, the `temp` reference has |
| 5243 | // not been unpoisoned yet; unpoison it now. |
| 5244 | __ MaybeUnpoisonHeapReference(temp); |
| 5245 | |
| 5246 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5247 | __ movl(temp, Address(temp, super_offset)); |
| 5248 | // If heap poisoning is enabled, no need to unpoison |
| 5249 | // `temp`, as we are comparing against null below. |
| 5250 | __ testl(temp, temp); |
| 5251 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5252 | __ Bind(&do_put); |
| 5253 | } else { |
| 5254 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5255 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | if (kPoisonHeapReferences) { |
| 5260 | __ movl(temp, register_value); |
| 5261 | __ PoisonHeapReference(temp); |
| 5262 | __ movl(address, temp); |
| 5263 | } else { |
| 5264 | __ movl(address, register_value); |
| 5265 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5266 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5267 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5268 | } |
| 5269 | |
| 5270 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5271 | codegen_->MarkGCCard( |
| 5272 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5273 | __ Bind(&done); |
| 5274 | |
| 5275 | if (slow_path != nullptr) { |
| 5276 | __ Bind(slow_path->GetExitLabel()); |
| 5277 | } |
| 5278 | |
| 5279 | break; |
| 5280 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5281 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5282 | case Primitive::kPrimInt: { |
| 5283 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5284 | Address address = index.IsConstant() |
| 5285 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5286 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5287 | if (value.IsRegister()) { |
| 5288 | __ movl(address, value.AsRegister<Register>()); |
| 5289 | } else { |
| 5290 | DCHECK(value.IsConstant()) << value; |
| 5291 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5292 | __ movl(address, Immediate(v)); |
| 5293 | } |
| 5294 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5295 | break; |
| 5296 | } |
| 5297 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | case Primitive::kPrimLong: { |
| 5299 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5300 | if (index.IsConstant()) { |
| 5301 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5302 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5303 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5304 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5306 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5307 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5308 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5309 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5310 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5311 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5312 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5313 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5314 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5315 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5316 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5317 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5318 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5319 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5320 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5321 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5322 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5323 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5324 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5325 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5326 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5327 | Immediate(High32Bits(val))); |
| 5328 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5329 | } |
| 5330 | break; |
| 5331 | } |
| 5332 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5333 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5334 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5335 | Address address = index.IsConstant() |
| 5336 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5337 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5338 | if (value.IsFpuRegister()) { |
| 5339 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5340 | } else { |
| 5341 | DCHECK(value.IsConstant()); |
| 5342 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5343 | __ movl(address, Immediate(v)); |
| 5344 | } |
| 5345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5346 | break; |
| 5347 | } |
| 5348 | |
| 5349 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5350 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5351 | Address address = index.IsConstant() |
| 5352 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5353 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5354 | if (value.IsFpuRegister()) { |
| 5355 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5356 | } else { |
| 5357 | DCHECK(value.IsConstant()); |
| 5358 | Address address_hi = index.IsConstant() ? |
| 5359 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5360 | offset + kX86WordSize) : |
| 5361 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5362 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5363 | __ movl(address, Immediate(Low32Bits(v))); |
| 5364 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5365 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5366 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5367 | break; |
| 5368 | } |
| 5369 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5370 | case Primitive::kPrimVoid: |
| 5371 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5372 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | } |
| 5374 | } |
| 5375 | |
| 5376 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5377 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5378 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5379 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5383 | LocationSummary* locations = instruction->GetLocations(); |
| 5384 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5385 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5386 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5388 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5389 | } |
| 5390 | |
| 5391 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5392 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5393 | ? LocationSummary::kCallOnSlowPath |
| 5394 | : LocationSummary::kNoCall; |
| 5395 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5396 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5397 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5398 | if (instruction->HasUses()) { |
| 5399 | locations->SetOut(Location::SameAsFirstInput()); |
| 5400 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5404 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5405 | Location index_loc = locations->InAt(0); |
| 5406 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5407 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5408 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5409 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5410 | if (length_loc.IsConstant()) { |
| 5411 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5412 | if (index_loc.IsConstant()) { |
| 5413 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5414 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5415 | if (index < 0 || index >= length) { |
| 5416 | codegen_->AddSlowPath(slow_path); |
| 5417 | __ jmp(slow_path->GetEntryLabel()); |
| 5418 | } else { |
| 5419 | // Some optimization after BCE may have generated this, and we should not |
| 5420 | // generate a bounds check if it is a valid range. |
| 5421 | } |
| 5422 | return; |
| 5423 | } |
| 5424 | |
| 5425 | // We have to reverse the jump condition because the length is the constant. |
| 5426 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5427 | __ cmpl(index_reg, Immediate(length)); |
| 5428 | codegen_->AddSlowPath(slow_path); |
| 5429 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5430 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5431 | Register length = length_loc.AsRegister<Register>(); |
| 5432 | if (index_loc.IsConstant()) { |
| 5433 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5434 | __ cmpl(length, Immediate(value)); |
| 5435 | } else { |
| 5436 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5437 | } |
| 5438 | codegen_->AddSlowPath(slow_path); |
| 5439 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5440 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5441 | } |
| 5442 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5443 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5444 | temp->SetLocations(nullptr); |
| 5445 | } |
| 5446 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5447 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5448 | // Nothing to do, this is driven by the code generator. |
| 5449 | } |
| 5450 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5451 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5452 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5456 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5457 | } |
| 5458 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5459 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5460 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5461 | } |
| 5462 | |
| 5463 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5464 | HBasicBlock* block = instruction->GetBlock(); |
| 5465 | if (block->GetLoopInformation() != nullptr) { |
| 5466 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5467 | // The back edge will generate the suspend check. |
| 5468 | return; |
| 5469 | } |
| 5470 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5471 | // The goto will generate the suspend check. |
| 5472 | return; |
| 5473 | } |
| 5474 | GenerateSuspendCheck(instruction, nullptr); |
| 5475 | } |
| 5476 | |
| 5477 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5478 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5479 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5480 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5481 | if (slow_path == nullptr) { |
| 5482 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5483 | instruction->SetSlowPath(slow_path); |
| 5484 | codegen_->AddSlowPath(slow_path); |
| 5485 | if (successor != nullptr) { |
| 5486 | DCHECK(successor->IsLoopHeader()); |
| 5487 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5488 | } |
| 5489 | } else { |
| 5490 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5491 | } |
| 5492 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5493 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5494 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5495 | if (successor == nullptr) { |
| 5496 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5497 | __ Bind(slow_path->GetReturnLabel()); |
| 5498 | } else { |
| 5499 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5500 | __ jmp(slow_path->GetEntryLabel()); |
| 5501 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5502 | } |
| 5503 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5504 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5505 | return codegen_->GetAssembler(); |
| 5506 | } |
| 5507 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5508 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5509 | ScratchRegisterScope ensure_scratch( |
| 5510 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5511 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5512 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5513 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5514 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5518 | ScratchRegisterScope ensure_scratch( |
| 5519 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5520 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5521 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5522 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5523 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5524 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5525 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5529 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5530 | Location source = move->GetSource(); |
| 5531 | Location destination = move->GetDestination(); |
| 5532 | |
| 5533 | if (source.IsRegister()) { |
| 5534 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5535 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5536 | } else { |
| 5537 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5538 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5539 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5540 | } else if (source.IsFpuRegister()) { |
| 5541 | if (destination.IsFpuRegister()) { |
| 5542 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5543 | } else if (destination.IsStackSlot()) { |
| 5544 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5545 | } else { |
| 5546 | DCHECK(destination.IsDoubleStackSlot()); |
| 5547 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5548 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5549 | } else if (source.IsStackSlot()) { |
| 5550 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5551 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5552 | } else if (destination.IsFpuRegister()) { |
| 5553 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5554 | } else { |
| 5555 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5556 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5557 | } |
| 5558 | } else if (source.IsDoubleStackSlot()) { |
| 5559 | if (destination.IsFpuRegister()) { |
| 5560 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5561 | } else { |
| 5562 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5563 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5564 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5565 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5566 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5567 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5568 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5569 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5570 | if (value == 0) { |
| 5571 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5572 | } else { |
| 5573 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5574 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5575 | } else { |
| 5576 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5577 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5578 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5579 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5580 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5581 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5582 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5583 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5584 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5585 | if (value == 0) { |
| 5586 | // Easy handling of 0.0. |
| 5587 | __ xorps(dest, dest); |
| 5588 | } else { |
| 5589 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5590 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5591 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5592 | __ movl(temp, Immediate(value)); |
| 5593 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5594 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5595 | } else { |
| 5596 | DCHECK(destination.IsStackSlot()) << destination; |
| 5597 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5598 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5599 | } else if (constant->IsLongConstant()) { |
| 5600 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5601 | int32_t low_value = Low32Bits(value); |
| 5602 | int32_t high_value = High32Bits(value); |
| 5603 | Immediate low(low_value); |
| 5604 | Immediate high(high_value); |
| 5605 | if (destination.IsDoubleStackSlot()) { |
| 5606 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5607 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5608 | } else { |
| 5609 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5610 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5611 | } |
| 5612 | } else { |
| 5613 | DCHECK(constant->IsDoubleConstant()); |
| 5614 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5615 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5616 | int32_t low_value = Low32Bits(value); |
| 5617 | int32_t high_value = High32Bits(value); |
| 5618 | Immediate low(low_value); |
| 5619 | Immediate high(high_value); |
| 5620 | if (destination.IsFpuRegister()) { |
| 5621 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5622 | if (value == 0) { |
| 5623 | // Easy handling of 0.0. |
| 5624 | __ xorpd(dest, dest); |
| 5625 | } else { |
| 5626 | __ pushl(high); |
| 5627 | __ pushl(low); |
| 5628 | __ movsd(dest, Address(ESP, 0)); |
| 5629 | __ addl(ESP, Immediate(8)); |
| 5630 | } |
| 5631 | } else { |
| 5632 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5633 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5634 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5635 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5636 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5637 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5638 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5639 | } |
| 5640 | } |
| 5641 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5642 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5643 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5644 | ScratchRegisterScope ensure_scratch( |
| 5645 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5646 | |
| 5647 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5648 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5649 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5650 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5651 | } |
| 5652 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5653 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5654 | ScratchRegisterScope ensure_scratch( |
| 5655 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5656 | |
| 5657 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5658 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5659 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5660 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5661 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5662 | } |
| 5663 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5664 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5665 | ScratchRegisterScope ensure_scratch1( |
| 5666 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5667 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5668 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5669 | ScratchRegisterScope ensure_scratch2( |
| 5670 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5671 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5672 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5673 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5674 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5675 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5676 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5677 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5678 | } |
| 5679 | |
| 5680 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5681 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5682 | Location source = move->GetSource(); |
| 5683 | Location destination = move->GetDestination(); |
| 5684 | |
| 5685 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5686 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5687 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5688 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5689 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5690 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5691 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5692 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5693 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5694 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5695 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5696 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5697 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5698 | // Use XOR Swap algorithm to avoid a temporary. |
| 5699 | DCHECK_NE(source.reg(), destination.reg()); |
| 5700 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5701 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5702 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5703 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5704 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5705 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5706 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5707 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5708 | // Take advantage of the 16 bytes in the XMM register. |
| 5709 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5710 | Address stack(ESP, destination.GetStackIndex()); |
| 5711 | // Load the double into the high doubleword. |
| 5712 | __ movhpd(reg, stack); |
| 5713 | |
| 5714 | // Store the low double into the destination. |
| 5715 | __ movsd(stack, reg); |
| 5716 | |
| 5717 | // Move the high double to the low double. |
| 5718 | __ psrldq(reg, Immediate(8)); |
| 5719 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5720 | // Take advantage of the 16 bytes in the XMM register. |
| 5721 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5722 | Address stack(ESP, source.GetStackIndex()); |
| 5723 | // Load the double into the high doubleword. |
| 5724 | __ movhpd(reg, stack); |
| 5725 | |
| 5726 | // Store the low double into the destination. |
| 5727 | __ movsd(stack, reg); |
| 5728 | |
| 5729 | // Move the high double to the low double. |
| 5730 | __ psrldq(reg, Immediate(8)); |
| 5731 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5732 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5733 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5734 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5735 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5736 | } |
| 5737 | } |
| 5738 | |
| 5739 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5740 | __ pushl(static_cast<Register>(reg)); |
| 5741 | } |
| 5742 | |
| 5743 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5744 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5745 | } |
| 5746 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5747 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5748 | InvokeRuntimeCallingConvention calling_convention; |
| 5749 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5750 | cls, |
| 5751 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5752 | Location::RegisterLocation(EAX), |
| 5753 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5757 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5758 | if (cls->NeedsAccessCheck()) { |
| 5759 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5760 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5761 | cls, |
| 5762 | cls->GetDexPc(), |
| 5763 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5764 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5765 | return; |
| 5766 | } |
| 5767 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5768 | Location out_loc = locations->Out(); |
| 5769 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5770 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5771 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5772 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5773 | DCHECK(!cls->CanCallRuntime()); |
| 5774 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5775 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5776 | GenerateGcRootFieldLoad( |
| 5777 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5778 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5779 | // /* GcRoot<mirror::Class>[] */ out = |
| 5780 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5781 | __ movl(out, Address(current_method, |
| 5782 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5783 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5784 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5785 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5786 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5787 | DCHECK(cls->CanCallRuntime()); |
| 5788 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5789 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5790 | codegen_->AddSlowPath(slow_path); |
| 5791 | |
| 5792 | if (!cls->IsInDexCache()) { |
| 5793 | __ testl(out, out); |
| 5794 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5795 | } |
| 5796 | |
| 5797 | if (cls->MustGenerateClinitCheck()) { |
| 5798 | GenerateClassInitializationCheck(slow_path, out); |
| 5799 | } else { |
| 5800 | __ Bind(slow_path->GetExitLabel()); |
| 5801 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5802 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5807 | LocationSummary* locations = |
| 5808 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5809 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5810 | if (check->HasUses()) { |
| 5811 | locations->SetOut(Location::SameAsFirstInput()); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5816 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5817 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5818 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5819 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5820 | GenerateClassInitializationCheck(slow_path, |
| 5821 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5822 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5823 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5824 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5825 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5826 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5827 | Immediate(mirror::Class::kStatusInitialized)); |
| 5828 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5829 | __ Bind(slow_path->GetExitLabel()); |
| 5830 | // No need for memory fence, thanks to the X86 memory model. |
| 5831 | } |
| 5832 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5833 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5834 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5835 | ? LocationSummary::kCallOnSlowPath |
| 5836 | : LocationSummary::kNoCall; |
| 5837 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5838 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5839 | locations->SetOut(Location::RequiresRegister()); |
| 5840 | } |
| 5841 | |
| 5842 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5843 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5844 | Location out_loc = locations->Out(); |
| 5845 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5846 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5847 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5848 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5849 | GenerateGcRootFieldLoad( |
| 5850 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5851 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5852 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5853 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5854 | GenerateGcRootFieldLoad( |
| 5855 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5856 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5857 | if (!load->IsInDexCache()) { |
| 5858 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5859 | codegen_->AddSlowPath(slow_path); |
| 5860 | __ testl(out, out); |
| 5861 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5862 | __ Bind(slow_path->GetExitLabel()); |
| 5863 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5866 | static Address GetExceptionTlsAddress() { |
| 5867 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5868 | } |
| 5869 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5870 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5871 | LocationSummary* locations = |
| 5872 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5873 | locations->SetOut(Location::RequiresRegister()); |
| 5874 | } |
| 5875 | |
| 5876 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5877 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5878 | } |
| 5879 | |
| 5880 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5881 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5882 | } |
| 5883 | |
| 5884 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5885 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5889 | LocationSummary* locations = |
| 5890 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5891 | InvokeRuntimeCallingConvention calling_convention; |
| 5892 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5893 | } |
| 5894 | |
| 5895 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5896 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5897 | instruction, |
| 5898 | instruction->GetDexPc(), |
| 5899 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5900 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5901 | } |
| 5902 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5903 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5904 | return kEmitCompilerReadBarrier && |
| 5905 | (kUseBakerReadBarrier || |
| 5906 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5907 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5908 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5909 | } |
| 5910 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5911 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5912 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5913 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5914 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5915 | case TypeCheckKind::kExactCheck: |
| 5916 | case TypeCheckKind::kAbstractClassCheck: |
| 5917 | case TypeCheckKind::kClassHierarchyCheck: |
| 5918 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5919 | call_kind = |
| 5920 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5921 | break; |
| 5922 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5923 | case TypeCheckKind::kUnresolvedCheck: |
| 5924 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5925 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5926 | break; |
| 5927 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5928 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5929 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5930 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5931 | locations->SetInAt(1, Location::Any()); |
| 5932 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5933 | locations->SetOut(Location::RequiresRegister()); |
| 5934 | // When read barriers are enabled, we need a temporary register for |
| 5935 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5936 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5937 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5941 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5942 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5943 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5944 | Location obj_loc = locations->InAt(0); |
| 5945 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5946 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5947 | Location out_loc = locations->Out(); |
| 5948 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5949 | Location temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5950 | locations->GetTemp(0) : |
| 5951 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5952 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5953 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5954 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5955 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5956 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5958 | |
| 5959 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5960 | // Avoid null check if we know obj is not null. |
| 5961 | if (instruction->MustDoNullCheck()) { |
| 5962 | __ testl(obj, obj); |
| 5963 | __ j(kEqual, &zero); |
| 5964 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5965 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5966 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5967 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5968 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5969 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5970 | case TypeCheckKind::kExactCheck: { |
| 5971 | if (cls.IsRegister()) { |
| 5972 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5973 | } else { |
| 5974 | DCHECK(cls.IsStackSlot()) << cls; |
| 5975 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5976 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5977 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5978 | // Classes must be equal for the instanceof to succeed. |
| 5979 | __ j(kNotEqual, &zero); |
| 5980 | __ movl(out, Immediate(1)); |
| 5981 | __ jmp(&done); |
| 5982 | break; |
| 5983 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5984 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5985 | case TypeCheckKind::kAbstractClassCheck: { |
| 5986 | // If the class is abstract, we eagerly fetch the super class of the |
| 5987 | // object to avoid doing a comparison we know will fail. |
| 5988 | NearLabel loop; |
| 5989 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5990 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5991 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5992 | __ testl(out, out); |
| 5993 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5994 | __ j(kEqual, &done); |
| 5995 | if (cls.IsRegister()) { |
| 5996 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5997 | } else { |
| 5998 | DCHECK(cls.IsStackSlot()) << cls; |
| 5999 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6000 | } |
| 6001 | __ j(kNotEqual, &loop); |
| 6002 | __ movl(out, Immediate(1)); |
| 6003 | if (zero.IsLinked()) { |
| 6004 | __ jmp(&done); |
| 6005 | } |
| 6006 | break; |
| 6007 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6008 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6009 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6010 | // Walk over the class hierarchy to find a match. |
| 6011 | NearLabel loop, success; |
| 6012 | __ Bind(&loop); |
| 6013 | if (cls.IsRegister()) { |
| 6014 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6015 | } else { |
| 6016 | DCHECK(cls.IsStackSlot()) << cls; |
| 6017 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6018 | } |
| 6019 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6020 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6021 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6022 | __ testl(out, out); |
| 6023 | __ j(kNotEqual, &loop); |
| 6024 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6025 | __ jmp(&done); |
| 6026 | __ Bind(&success); |
| 6027 | __ movl(out, Immediate(1)); |
| 6028 | if (zero.IsLinked()) { |
| 6029 | __ jmp(&done); |
| 6030 | } |
| 6031 | break; |
| 6032 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6033 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6034 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6035 | // Do an exact check. |
| 6036 | NearLabel exact_check; |
| 6037 | if (cls.IsRegister()) { |
| 6038 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6039 | } else { |
| 6040 | DCHECK(cls.IsStackSlot()) << cls; |
| 6041 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6042 | } |
| 6043 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6044 | // 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] | 6045 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6046 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6047 | __ testl(out, out); |
| 6048 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6049 | __ j(kEqual, &done); |
| 6050 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6051 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6052 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6053 | __ movl(out, Immediate(1)); |
| 6054 | __ jmp(&done); |
| 6055 | break; |
| 6056 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6057 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6058 | case TypeCheckKind::kArrayCheck: { |
| 6059 | if (cls.IsRegister()) { |
| 6060 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6061 | } else { |
| 6062 | DCHECK(cls.IsStackSlot()) << cls; |
| 6063 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6064 | } |
| 6065 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6066 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6067 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6068 | codegen_->AddSlowPath(slow_path); |
| 6069 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6070 | __ movl(out, Immediate(1)); |
| 6071 | if (zero.IsLinked()) { |
| 6072 | __ jmp(&done); |
| 6073 | } |
| 6074 | break; |
| 6075 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6076 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6077 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6078 | case TypeCheckKind::kInterfaceCheck: { |
| 6079 | // Note that we indeed only call on slow path, but we always go |
| 6080 | // into the slow path for the unresolved & interface check |
| 6081 | // cases. |
| 6082 | // |
| 6083 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6084 | // entry point without resorting to a type checking slow path |
| 6085 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6086 | // require to assign fixed registers for the inputs of this |
| 6087 | // HInstanceOf instruction (following the runtime calling |
| 6088 | // convention), which might be cluttered by the potential first |
| 6089 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6090 | // |
| 6091 | // TODO: Introduce a new runtime entry point taking the object |
| 6092 | // to test (instead of its class) as argument, and let it deal |
| 6093 | // with the read barrier issues. This will let us refactor this |
| 6094 | // case of the `switch` code as it was previously (with a direct |
| 6095 | // call to the runtime not using a type checking slow path). |
| 6096 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6097 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6098 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6099 | /* is_fatal */ false); |
| 6100 | codegen_->AddSlowPath(slow_path); |
| 6101 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6102 | if (zero.IsLinked()) { |
| 6103 | __ jmp(&done); |
| 6104 | } |
| 6105 | break; |
| 6106 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6107 | } |
| 6108 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6110 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6111 | __ xorl(out, out); |
| 6112 | } |
| 6113 | |
| 6114 | if (done.IsLinked()) { |
| 6115 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6116 | } |
| 6117 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6118 | if (slow_path != nullptr) { |
| 6119 | __ Bind(slow_path->GetExitLabel()); |
| 6120 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6121 | } |
| 6122 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6123 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6124 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6125 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6126 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6127 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6128 | case TypeCheckKind::kExactCheck: |
| 6129 | case TypeCheckKind::kAbstractClassCheck: |
| 6130 | case TypeCheckKind::kClassHierarchyCheck: |
| 6131 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6132 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6133 | LocationSummary::kCallOnSlowPath : |
| 6134 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6135 | break; |
| 6136 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6137 | case TypeCheckKind::kUnresolvedCheck: |
| 6138 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6139 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6140 | break; |
| 6141 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6142 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6143 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6144 | locations->SetInAt(1, Location::Any()); |
| 6145 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6146 | locations->AddTemp(Location::RequiresRegister()); |
| 6147 | // When read barriers are enabled, we need an additional temporary |
| 6148 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6149 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6150 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6151 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6155 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6156 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6157 | Location obj_loc = locations->InAt(0); |
| 6158 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6159 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6160 | Location temp_loc = locations->GetTemp(0); |
| 6161 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6162 | Location temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 6163 | locations->GetTemp(1) : |
| 6164 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6165 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6166 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6167 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6168 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6169 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6170 | bool is_type_check_slow_path_fatal = |
| 6171 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6172 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6173 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6174 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6175 | !instruction->CanThrowIntoCatchBlock(); |
| 6176 | SlowPathCode* type_check_slow_path = |
| 6177 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6178 | is_type_check_slow_path_fatal); |
| 6179 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6180 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6181 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6182 | // Avoid null check if we know obj is not null. |
| 6183 | if (instruction->MustDoNullCheck()) { |
| 6184 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6185 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6186 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6187 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6188 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6189 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6191 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6192 | case TypeCheckKind::kExactCheck: |
| 6193 | case TypeCheckKind::kArrayCheck: { |
| 6194 | if (cls.IsRegister()) { |
| 6195 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6196 | } else { |
| 6197 | DCHECK(cls.IsStackSlot()) << cls; |
| 6198 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6199 | } |
| 6200 | // Jump to slow path for throwing the exception or doing a |
| 6201 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6202 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 | break; |
| 6204 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6205 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | case TypeCheckKind::kAbstractClassCheck: { |
| 6207 | // If the class is abstract, we eagerly fetch the super class of the |
| 6208 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6209 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6212 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6213 | |
| 6214 | // If the class reference currently in `temp` is not null, jump |
| 6215 | // to the `compare_classes` label to compare it with the checked |
| 6216 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6217 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6218 | __ j(kNotEqual, &compare_classes); |
| 6219 | // Otherwise, jump to the slow path to throw the exception. |
| 6220 | // |
| 6221 | // But before, move back the object's class into `temp` before |
| 6222 | // going into the slow path, as it has been overwritten in the |
| 6223 | // meantime. |
| 6224 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6225 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6226 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6227 | |
| 6228 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6229 | if (cls.IsRegister()) { |
| 6230 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6231 | } else { |
| 6232 | DCHECK(cls.IsStackSlot()) << cls; |
| 6233 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6234 | } |
| 6235 | __ j(kNotEqual, &loop); |
| 6236 | break; |
| 6237 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6238 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6240 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6241 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6242 | __ Bind(&loop); |
| 6243 | if (cls.IsRegister()) { |
| 6244 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6245 | } else { |
| 6246 | DCHECK(cls.IsStackSlot()) << cls; |
| 6247 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6248 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6249 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6250 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6251 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6252 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6253 | |
| 6254 | // If the class reference currently in `temp` is not null, jump |
| 6255 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6256 | __ testl(temp, temp); |
| 6257 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6258 | // Otherwise, jump to the slow path to throw the exception. |
| 6259 | // |
| 6260 | // But before, move back the object's class into `temp` before |
| 6261 | // going into the slow path, as it has been overwritten in the |
| 6262 | // meantime. |
| 6263 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6264 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6265 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6266 | break; |
| 6267 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6268 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6269 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6270 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6272 | if (cls.IsRegister()) { |
| 6273 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6274 | } else { |
| 6275 | DCHECK(cls.IsStackSlot()) << cls; |
| 6276 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6277 | } |
| 6278 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6279 | |
| 6280 | // 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] | 6281 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6282 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | |
| 6284 | // If the component type is not null (i.e. the object is indeed |
| 6285 | // an array), jump to label `check_non_primitive_component_type` |
| 6286 | // to further check that this component type is not a primitive |
| 6287 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6289 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6290 | // Otherwise, jump to the slow path to throw the exception. |
| 6291 | // |
| 6292 | // But before, move back the object's class into `temp` before |
| 6293 | // going into the slow path, as it has been overwritten in the |
| 6294 | // meantime. |
| 6295 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6296 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6297 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6298 | |
| 6299 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6300 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6301 | __ j(kEqual, &done); |
| 6302 | // Same comment as above regarding `temp` and the slow path. |
| 6303 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6304 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6305 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6306 | break; |
| 6307 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6308 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6309 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6310 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6311 | // We always go into the type check slow path for the unresolved & |
| 6312 | // interface check cases. |
| 6313 | // |
| 6314 | // We cannot directly call the CheckCast runtime entry point |
| 6315 | // without resorting to a type checking slow path here (i.e. by |
| 6316 | // calling InvokeRuntime directly), as it would require to |
| 6317 | // assign fixed registers for the inputs of this HInstanceOf |
| 6318 | // instruction (following the runtime calling convention), which |
| 6319 | // might be cluttered by the potential first read barrier |
| 6320 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6321 | // |
| 6322 | // TODO: Introduce a new runtime entry point taking the object |
| 6323 | // to test (instead of its class) as argument, and let it deal |
| 6324 | // with the read barrier issues. This will let us refactor this |
| 6325 | // case of the `switch` code as it was previously (with a direct |
| 6326 | // call to the runtime not using a type checking slow path). |
| 6327 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6328 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6329 | break; |
| 6330 | } |
| 6331 | __ Bind(&done); |
| 6332 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6333 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6334 | } |
| 6335 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6336 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6337 | LocationSummary* locations = |
| 6338 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6339 | InvokeRuntimeCallingConvention calling_convention; |
| 6340 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6341 | } |
| 6342 | |
| 6343 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6344 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6345 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6346 | instruction, |
| 6347 | instruction->GetDexPc(), |
| 6348 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6349 | if (instruction->IsEnter()) { |
| 6350 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6351 | } else { |
| 6352 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6353 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6356 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6357 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6358 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6359 | |
| 6360 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6361 | LocationSummary* locations = |
| 6362 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6363 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6364 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6366 | locations->SetInAt(1, Location::Any()); |
| 6367 | locations->SetOut(Location::SameAsFirstInput()); |
| 6368 | } |
| 6369 | |
| 6370 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6371 | HandleBitwiseOperation(instruction); |
| 6372 | } |
| 6373 | |
| 6374 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6375 | HandleBitwiseOperation(instruction); |
| 6376 | } |
| 6377 | |
| 6378 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6379 | HandleBitwiseOperation(instruction); |
| 6380 | } |
| 6381 | |
| 6382 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6383 | LocationSummary* locations = instruction->GetLocations(); |
| 6384 | Location first = locations->InAt(0); |
| 6385 | Location second = locations->InAt(1); |
| 6386 | DCHECK(first.Equals(locations->Out())); |
| 6387 | |
| 6388 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6389 | if (second.IsRegister()) { |
| 6390 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6391 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6392 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6393 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6394 | } else { |
| 6395 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6396 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6397 | } |
| 6398 | } else if (second.IsConstant()) { |
| 6399 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6400 | __ andl(first.AsRegister<Register>(), |
| 6401 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6402 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6403 | __ orl(first.AsRegister<Register>(), |
| 6404 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6405 | } else { |
| 6406 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6407 | __ xorl(first.AsRegister<Register>(), |
| 6408 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6409 | } |
| 6410 | } else { |
| 6411 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6412 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6413 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6414 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6415 | } else { |
| 6416 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6417 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6418 | } |
| 6419 | } |
| 6420 | } else { |
| 6421 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6422 | if (second.IsRegisterPair()) { |
| 6423 | if (instruction->IsAnd()) { |
| 6424 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6425 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6426 | } else if (instruction->IsOr()) { |
| 6427 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6428 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6429 | } else { |
| 6430 | DCHECK(instruction->IsXor()); |
| 6431 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6432 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6433 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6434 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6435 | if (instruction->IsAnd()) { |
| 6436 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6437 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6438 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6439 | } else if (instruction->IsOr()) { |
| 6440 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6441 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6442 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6443 | } else { |
| 6444 | DCHECK(instruction->IsXor()); |
| 6445 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6446 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6447 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6448 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6449 | } else { |
| 6450 | DCHECK(second.IsConstant()) << second; |
| 6451 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6452 | int32_t low_value = Low32Bits(value); |
| 6453 | int32_t high_value = High32Bits(value); |
| 6454 | Immediate low(low_value); |
| 6455 | Immediate high(high_value); |
| 6456 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6457 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6458 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6459 | if (low_value == 0) { |
| 6460 | __ xorl(first_low, first_low); |
| 6461 | } else if (low_value != -1) { |
| 6462 | __ andl(first_low, low); |
| 6463 | } |
| 6464 | if (high_value == 0) { |
| 6465 | __ xorl(first_high, first_high); |
| 6466 | } else if (high_value != -1) { |
| 6467 | __ andl(first_high, high); |
| 6468 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6469 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6470 | if (low_value != 0) { |
| 6471 | __ orl(first_low, low); |
| 6472 | } |
| 6473 | if (high_value != 0) { |
| 6474 | __ orl(first_high, high); |
| 6475 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6476 | } else { |
| 6477 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6478 | if (low_value != 0) { |
| 6479 | __ xorl(first_low, low); |
| 6480 | } |
| 6481 | if (high_value != 0) { |
| 6482 | __ xorl(first_high, high); |
| 6483 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6484 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6485 | } |
| 6486 | } |
| 6487 | } |
| 6488 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6489 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6490 | Location out, |
| 6491 | uint32_t offset, |
| 6492 | Location temp) { |
| 6493 | Register out_reg = out.AsRegister<Register>(); |
| 6494 | if (kEmitCompilerReadBarrier) { |
| 6495 | if (kUseBakerReadBarrier) { |
| 6496 | // Load with fast path based Baker's read barrier. |
| 6497 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6498 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6499 | instruction, out, out_reg, offset, temp, /* needs_null_check */ false); |
| 6500 | } else { |
| 6501 | // Load with slow path based read barrier. |
| 6502 | // Save the value of `out` into `temp` before overwriting it |
| 6503 | // in the following move operation, as we will need it for the |
| 6504 | // read barrier below. |
| 6505 | __ movl(temp.AsRegister<Register>(), out_reg); |
| 6506 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6507 | __ movl(out_reg, Address(out_reg, offset)); |
| 6508 | codegen_->GenerateReadBarrierSlow(instruction, out, out, temp, offset); |
| 6509 | } |
| 6510 | } else { |
| 6511 | // Plain load with no read barrier. |
| 6512 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6513 | __ movl(out_reg, Address(out_reg, offset)); |
| 6514 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6519 | Location out, |
| 6520 | Location obj, |
| 6521 | uint32_t offset, |
| 6522 | Location temp) { |
| 6523 | Register out_reg = out.AsRegister<Register>(); |
| 6524 | Register obj_reg = obj.AsRegister<Register>(); |
| 6525 | if (kEmitCompilerReadBarrier) { |
| 6526 | if (kUseBakerReadBarrier) { |
| 6527 | // Load with fast path based Baker's read barrier. |
| 6528 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6529 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6530 | instruction, out, obj_reg, offset, temp, /* needs_null_check */ false); |
| 6531 | } else { |
| 6532 | // Load with slow path based read barrier. |
| 6533 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6534 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6535 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6536 | } |
| 6537 | } else { |
| 6538 | // Plain load with no read barrier. |
| 6539 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6540 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6541 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6542 | } |
| 6543 | } |
| 6544 | |
| 6545 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6546 | Location root, |
| 6547 | Register obj, |
| 6548 | uint32_t offset) { |
| 6549 | Register root_reg = root.AsRegister<Register>(); |
| 6550 | if (kEmitCompilerReadBarrier) { |
| 6551 | if (kUseBakerReadBarrier) { |
| 6552 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6553 | // Baker's read barrier are used: |
| 6554 | // |
| 6555 | // root = obj.field; |
| 6556 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6557 | // root = ReadBarrier::Mark(root) |
| 6558 | // } |
| 6559 | |
| 6560 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6561 | __ movl(root_reg, Address(obj, offset)); |
| 6562 | static_assert( |
| 6563 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6564 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6565 | "have different sizes."); |
| 6566 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6567 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6568 | "have different sizes."); |
| 6569 | |
| 6570 | // Slow path used to mark the GC root `root`. |
| 6571 | SlowPathCode* slow_path = |
| 6572 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6573 | codegen_->AddSlowPath(slow_path); |
| 6574 | |
| 6575 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6576 | Immediate(0)); |
| 6577 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6578 | __ Bind(slow_path->GetExitLabel()); |
| 6579 | } else { |
| 6580 | // GC root loaded through a slow path for read barriers other |
| 6581 | // than Baker's. |
| 6582 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6583 | __ leal(root_reg, Address(obj, offset)); |
| 6584 | // /* mirror::Object* */ root = root->Read() |
| 6585 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6586 | } |
| 6587 | } else { |
| 6588 | // Plain GC root load with no read barrier. |
| 6589 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6590 | __ movl(root_reg, Address(obj, offset)); |
| 6591 | } |
| 6592 | } |
| 6593 | |
| 6594 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6595 | Location ref, |
| 6596 | Register obj, |
| 6597 | uint32_t offset, |
| 6598 | Location temp, |
| 6599 | bool needs_null_check) { |
| 6600 | DCHECK(kEmitCompilerReadBarrier); |
| 6601 | DCHECK(kUseBakerReadBarrier); |
| 6602 | |
| 6603 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6604 | Address src(obj, offset); |
| 6605 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6606 | } |
| 6607 | |
| 6608 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6609 | Location ref, |
| 6610 | Register obj, |
| 6611 | uint32_t data_offset, |
| 6612 | Location index, |
| 6613 | Location temp, |
| 6614 | bool needs_null_check) { |
| 6615 | DCHECK(kEmitCompilerReadBarrier); |
| 6616 | DCHECK(kUseBakerReadBarrier); |
| 6617 | |
| 6618 | // /* HeapReference<Object> */ ref = |
| 6619 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6620 | Address src = index.IsConstant() ? |
| 6621 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6622 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6623 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6624 | } |
| 6625 | |
| 6626 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6627 | Location ref, |
| 6628 | Register obj, |
| 6629 | const Address& src, |
| 6630 | Location temp, |
| 6631 | bool needs_null_check) { |
| 6632 | DCHECK(kEmitCompilerReadBarrier); |
| 6633 | DCHECK(kUseBakerReadBarrier); |
| 6634 | |
| 6635 | // In slow path based read barriers, the read barrier call is |
| 6636 | // inserted after the original load. However, in fast path based |
| 6637 | // Baker's read barriers, we need to perform the load of |
| 6638 | // mirror::Object::monitor_ *before* the original reference load. |
| 6639 | // This load-load ordering is required by the read barrier. |
| 6640 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6641 | // |
| 6642 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6643 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6644 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6645 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6646 | // if (is_gray) { |
| 6647 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6648 | // } |
| 6649 | // |
| 6650 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6651 | // slightly more complex as: |
| 6652 | // - it implements the load-load fence using a data dependency on |
| 6653 | // the high-bits of rb_state, which are expected to be all zeroes; |
| 6654 | // - it performs additional checks that we do not do here for |
| 6655 | // performance reasons. |
| 6656 | |
| 6657 | Register ref_reg = ref.AsRegister<Register>(); |
| 6658 | Register temp_reg = temp.AsRegister<Register>(); |
| 6659 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6660 | |
| 6661 | // /* int32_t */ monitor = obj->monitor_ |
| 6662 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6663 | if (needs_null_check) { |
| 6664 | MaybeRecordImplicitNullCheck(instruction); |
| 6665 | } |
| 6666 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6667 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6668 | "art::LockWord and int32_t have different sizes."); |
| 6669 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6670 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6671 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6672 | static_assert( |
| 6673 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6674 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6675 | |
| 6676 | // Load fence to prevent load-load reordering. |
| 6677 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6678 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6679 | |
| 6680 | // The actual reference load. |
| 6681 | // /* HeapReference<Object> */ ref = *src |
| 6682 | __ movl(ref_reg, src); |
| 6683 | |
| 6684 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6685 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6686 | |
| 6687 | // Slow path used to mark the object `ref` when it is gray. |
| 6688 | SlowPathCode* slow_path = |
| 6689 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6690 | AddSlowPath(slow_path); |
| 6691 | |
| 6692 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6693 | // ref = ReadBarrier::Mark(ref); |
| 6694 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6695 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6696 | __ Bind(slow_path->GetExitLabel()); |
| 6697 | } |
| 6698 | |
| 6699 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6700 | Location out, |
| 6701 | Location ref, |
| 6702 | Location obj, |
| 6703 | uint32_t offset, |
| 6704 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | DCHECK(kEmitCompilerReadBarrier); |
| 6706 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6707 | // Insert a slow path based read barrier *after* the reference load. |
| 6708 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6709 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6710 | // reference will be carried out by the runtime within the slow |
| 6711 | // path. |
| 6712 | // |
| 6713 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6714 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6715 | // not used by the artReadBarrierSlow entry point. |
| 6716 | // |
| 6717 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6718 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6719 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6720 | AddSlowPath(slow_path); |
| 6721 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6722 | __ jmp(slow_path->GetEntryLabel()); |
| 6723 | __ Bind(slow_path->GetExitLabel()); |
| 6724 | } |
| 6725 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6726 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6727 | Location out, |
| 6728 | Location ref, |
| 6729 | Location obj, |
| 6730 | uint32_t offset, |
| 6731 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6732 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6733 | // Baker's read barriers shall be handled by the fast path |
| 6734 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6735 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6736 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6737 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6738 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | } else if (kPoisonHeapReferences) { |
| 6740 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6741 | } |
| 6742 | } |
| 6743 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6744 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6745 | Location out, |
| 6746 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6747 | DCHECK(kEmitCompilerReadBarrier); |
| 6748 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6749 | // Insert a slow path based read barrier *after* the GC root load. |
| 6750 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6751 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6752 | // not need to do anything special for this here. |
| 6753 | SlowPathCode* slow_path = |
| 6754 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6755 | AddSlowPath(slow_path); |
| 6756 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6757 | __ jmp(slow_path->GetEntryLabel()); |
| 6758 | __ Bind(slow_path->GetExitLabel()); |
| 6759 | } |
| 6760 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6761 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6762 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6763 | LOG(FATAL) << "Unreachable"; |
| 6764 | } |
| 6765 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6766 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6767 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6768 | LOG(FATAL) << "Unreachable"; |
| 6769 | } |
| 6770 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6771 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6772 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6773 | LocationSummary* locations = |
| 6774 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6775 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6776 | } |
| 6777 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6778 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6779 | int32_t lower_bound, |
| 6780 | uint32_t num_entries, |
| 6781 | HBasicBlock* switch_block, |
| 6782 | HBasicBlock* default_block) { |
| 6783 | // Figure out the correct compare values and jump conditions. |
| 6784 | // Handle the first compare/branch as a special case because it might |
| 6785 | // jump to the default case. |
| 6786 | DCHECK_GT(num_entries, 2u); |
| 6787 | Condition first_condition; |
| 6788 | uint32_t index; |
| 6789 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6790 | if (lower_bound != 0) { |
| 6791 | first_condition = kLess; |
| 6792 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6793 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6794 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6795 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6796 | index = 1; |
| 6797 | } else { |
| 6798 | // Handle all the compare/jumps below. |
| 6799 | first_condition = kBelow; |
| 6800 | index = 0; |
| 6801 | } |
| 6802 | |
| 6803 | // Handle the rest of the compare/jumps. |
| 6804 | for (; index + 1 < num_entries; index += 2) { |
| 6805 | int32_t compare_to_value = lower_bound + index + 1; |
| 6806 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6807 | // Jump to successors[index] if value < case_value[index]. |
| 6808 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6809 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6810 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6811 | } |
| 6812 | |
| 6813 | if (index != num_entries) { |
| 6814 | // There are an odd number of entries. Handle the last one. |
| 6815 | DCHECK_EQ(index + 1, num_entries); |
| 6816 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6817 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6821 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6822 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6823 | } |
| 6824 | } |
| 6825 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6826 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6827 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6828 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6829 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6830 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6831 | |
| 6832 | GenPackedSwitchWithCompares(value_reg, |
| 6833 | lower_bound, |
| 6834 | num_entries, |
| 6835 | switch_instr->GetBlock(), |
| 6836 | switch_instr->GetDefaultBlock()); |
| 6837 | } |
| 6838 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6839 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6840 | LocationSummary* locations = |
| 6841 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6842 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6843 | |
| 6844 | // Constant area pointer. |
| 6845 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6846 | |
| 6847 | // And the temporary we need. |
| 6848 | locations->AddTemp(Location::RequiresRegister()); |
| 6849 | } |
| 6850 | |
| 6851 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6852 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6853 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6854 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6855 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6856 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6857 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6858 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6859 | GenPackedSwitchWithCompares(value_reg, |
| 6860 | lower_bound, |
| 6861 | num_entries, |
| 6862 | switch_instr->GetBlock(), |
| 6863 | default_block); |
| 6864 | return; |
| 6865 | } |
| 6866 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6867 | // Optimizing has a jump area. |
| 6868 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6869 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6870 | |
| 6871 | // Remove the bias, if needed. |
| 6872 | if (lower_bound != 0) { |
| 6873 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6874 | value_reg = temp_reg; |
| 6875 | } |
| 6876 | |
| 6877 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6878 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6879 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6880 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6881 | |
| 6882 | // We are in the range of the table. |
| 6883 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6884 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6885 | |
| 6886 | // Compute the actual target address by adding in constant_area. |
| 6887 | __ addl(temp_reg, constant_area); |
| 6888 | |
| 6889 | // And jump. |
| 6890 | __ jmp(temp_reg); |
| 6891 | } |
| 6892 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6893 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6894 | HX86ComputeBaseMethodAddress* insn) { |
| 6895 | LocationSummary* locations = |
| 6896 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6897 | locations->SetOut(Location::RequiresRegister()); |
| 6898 | } |
| 6899 | |
| 6900 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6901 | HX86ComputeBaseMethodAddress* insn) { |
| 6902 | LocationSummary* locations = insn->GetLocations(); |
| 6903 | Register reg = locations->Out().AsRegister<Register>(); |
| 6904 | |
| 6905 | // Generate call to next instruction. |
| 6906 | Label next_instruction; |
| 6907 | __ call(&next_instruction); |
| 6908 | __ Bind(&next_instruction); |
| 6909 | |
| 6910 | // Remember this offset for later use with constant area. |
| 6911 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6912 | |
| 6913 | // Grab the return address off the stack. |
| 6914 | __ popl(reg); |
| 6915 | } |
| 6916 | |
| 6917 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6918 | HX86LoadFromConstantTable* insn) { |
| 6919 | LocationSummary* locations = |
| 6920 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6921 | |
| 6922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6923 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6924 | |
| 6925 | // If we don't need to be materialized, we only need the inputs to be set. |
| 6926 | if (!insn->NeedsMaterialization()) { |
| 6927 | return; |
| 6928 | } |
| 6929 | |
| 6930 | switch (insn->GetType()) { |
| 6931 | case Primitive::kPrimFloat: |
| 6932 | case Primitive::kPrimDouble: |
| 6933 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6934 | break; |
| 6935 | |
| 6936 | case Primitive::kPrimInt: |
| 6937 | locations->SetOut(Location::RequiresRegister()); |
| 6938 | break; |
| 6939 | |
| 6940 | default: |
| 6941 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6942 | } |
| 6943 | } |
| 6944 | |
| 6945 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 6946 | if (!insn->NeedsMaterialization()) { |
| 6947 | return; |
| 6948 | } |
| 6949 | |
| 6950 | LocationSummary* locations = insn->GetLocations(); |
| 6951 | Location out = locations->Out(); |
| 6952 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 6953 | HConstant *value = insn->GetConstant(); |
| 6954 | |
| 6955 | switch (insn->GetType()) { |
| 6956 | case Primitive::kPrimFloat: |
| 6957 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 6958 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 6959 | break; |
| 6960 | |
| 6961 | case Primitive::kPrimDouble: |
| 6962 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 6963 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 6964 | break; |
| 6965 | |
| 6966 | case Primitive::kPrimInt: |
| 6967 | __ movl(out.AsRegister<Register>(), |
| 6968 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 6969 | break; |
| 6970 | |
| 6971 | default: |
| 6972 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6973 | } |
| 6974 | } |
| 6975 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6976 | /** |
| 6977 | * Class to handle late fixup of offsets into constant area. |
| 6978 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 6979 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6980 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6981 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 6982 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6983 | |
| 6984 | protected: |
| 6985 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6986 | |
| 6987 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6988 | |
| 6989 | private: |
| 6990 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6991 | // Patch the correct offset for the instruction. The place to patch is the |
| 6992 | // last 4 bytes of the instruction. |
| 6993 | // The value to patch is the distance from the offset in the constant area |
| 6994 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6995 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6996 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6997 | |
| 6998 | // Patch in the right value. |
| 6999 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7000 | } |
| 7001 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7002 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7003 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7004 | }; |
| 7005 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7006 | /** |
| 7007 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7008 | * constant area. |
| 7009 | */ |
| 7010 | class JumpTableRIPFixup : public RIPFixup { |
| 7011 | public: |
| 7012 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7013 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7014 | |
| 7015 | void CreateJumpTable() { |
| 7016 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7017 | |
| 7018 | // Ensure that the reference to the jump table has the correct offset. |
| 7019 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7020 | SetOffset(offset_in_constant_table); |
| 7021 | |
| 7022 | // The label values in the jump table are computed relative to the |
| 7023 | // instruction addressing the constant area. |
| 7024 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7025 | |
| 7026 | // Populate the jump table with the correct values for the jump table. |
| 7027 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7028 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7029 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7030 | // The value that we want is the target offset - the position of the table. |
| 7031 | for (int32_t i = 0; i < num_entries; i++) { |
| 7032 | HBasicBlock* b = successors[i]; |
| 7033 | Label* l = codegen_->GetLabelOf(b); |
| 7034 | DCHECK(l->IsBound()); |
| 7035 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7036 | assembler->AppendInt32(offset_to_block); |
| 7037 | } |
| 7038 | } |
| 7039 | |
| 7040 | private: |
| 7041 | const HX86PackedSwitch* switch_instr_; |
| 7042 | }; |
| 7043 | |
| 7044 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7045 | // Generate the constant area if needed. |
| 7046 | X86Assembler* assembler = GetAssembler(); |
| 7047 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7048 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7049 | // byte values. |
| 7050 | assembler->Align(4, 0); |
| 7051 | constant_area_start_ = assembler->CodeSize(); |
| 7052 | |
| 7053 | // Populate any jump tables. |
| 7054 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7055 | jump_table->CreateJumpTable(); |
| 7056 | } |
| 7057 | |
| 7058 | // And now add the constant area to the generated code. |
| 7059 | assembler->AddConstantArea(); |
| 7060 | } |
| 7061 | |
| 7062 | // And finish up. |
| 7063 | CodeGenerator::Finalize(allocator); |
| 7064 | } |
| 7065 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7066 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7067 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7068 | return Address(reg, kDummy32BitOffset, fixup); |
| 7069 | } |
| 7070 | |
| 7071 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7072 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7073 | return Address(reg, kDummy32BitOffset, fixup); |
| 7074 | } |
| 7075 | |
| 7076 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7077 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7078 | return Address(reg, kDummy32BitOffset, fixup); |
| 7079 | } |
| 7080 | |
| 7081 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7082 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7083 | return Address(reg, kDummy32BitOffset, fixup); |
| 7084 | } |
| 7085 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7086 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7087 | Register reg, |
| 7088 | Register value) { |
| 7089 | // Create a fixup to be used to create and address the jump table. |
| 7090 | JumpTableRIPFixup* table_fixup = |
| 7091 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7092 | |
| 7093 | // We have to populate the jump tables. |
| 7094 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7095 | |
| 7096 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7097 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7098 | } |
| 7099 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7100 | // TODO: target as memory. |
| 7101 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7102 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7103 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7104 | return; |
| 7105 | } |
| 7106 | |
| 7107 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7108 | |
| 7109 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7110 | if (target.Equals(return_loc)) { |
| 7111 | return; |
| 7112 | } |
| 7113 | |
| 7114 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7115 | // with the else branch. |
| 7116 | if (type == Primitive::kPrimLong) { |
| 7117 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7118 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7119 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7120 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7121 | } else { |
| 7122 | // Let the parallel move resolver take care of all of this. |
| 7123 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7124 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7125 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7126 | } |
| 7127 | } |
| 7128 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7129 | #undef __ |
| 7130 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7131 | } // namespace x86 |
| 7132 | } // namespace art |