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 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 820 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 821 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 822 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 823 | |
| 824 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 825 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 826 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 827 | UpdateBlockedPairRegisters(); |
| 828 | } |
| 829 | |
| 830 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 831 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 832 | X86ManagedRegister current = |
| 833 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 834 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 835 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 836 | blocked_register_pairs_[i] = true; |
| 837 | } |
| 838 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 839 | } |
| 840 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 841 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 842 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 843 | assembler_(codegen->GetAssembler()), |
| 844 | codegen_(codegen) {} |
| 845 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 846 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 847 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 848 | } |
| 849 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 850 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 851 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 852 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 853 | bool skip_overflow_check = |
| 854 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 855 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 856 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 857 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 858 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 859 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 860 | } |
| 861 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 862 | if (HasEmptyFrame()) { |
| 863 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 864 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 865 | |
| 866 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 867 | Register reg = kCoreCalleeSaves[i]; |
| 868 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 869 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 870 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 871 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 875 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 876 | __ subl(ESP, Immediate(adjust)); |
| 877 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 878 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 882 | __ cfi().RememberState(); |
| 883 | if (!HasEmptyFrame()) { |
| 884 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 885 | __ addl(ESP, Immediate(adjust)); |
| 886 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 887 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 888 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 889 | Register reg = kCoreCalleeSaves[i]; |
| 890 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 891 | __ popl(reg); |
| 892 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 893 | __ cfi().Restore(DWARFReg(reg)); |
| 894 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 895 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 896 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 897 | __ ret(); |
| 898 | __ cfi().RestoreState(); |
| 899 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 902 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 903 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 906 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 907 | switch (load->GetType()) { |
| 908 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 909 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 910 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 911 | |
| 912 | case Primitive::kPrimInt: |
| 913 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 914 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 915 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 916 | |
| 917 | case Primitive::kPrimBoolean: |
| 918 | case Primitive::kPrimByte: |
| 919 | case Primitive::kPrimChar: |
| 920 | case Primitive::kPrimShort: |
| 921 | case Primitive::kPrimVoid: |
| 922 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 923 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 927 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 930 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 931 | switch (type) { |
| 932 | case Primitive::kPrimBoolean: |
| 933 | case Primitive::kPrimByte: |
| 934 | case Primitive::kPrimChar: |
| 935 | case Primitive::kPrimShort: |
| 936 | case Primitive::kPrimInt: |
| 937 | case Primitive::kPrimNot: |
| 938 | return Location::RegisterLocation(EAX); |
| 939 | |
| 940 | case Primitive::kPrimLong: |
| 941 | return Location::RegisterPairLocation(EAX, EDX); |
| 942 | |
| 943 | case Primitive::kPrimVoid: |
| 944 | return Location::NoLocation(); |
| 945 | |
| 946 | case Primitive::kPrimDouble: |
| 947 | case Primitive::kPrimFloat: |
| 948 | return Location::FpuRegisterLocation(XMM0); |
| 949 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 950 | |
| 951 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 955 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 956 | } |
| 957 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 958 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 959 | switch (type) { |
| 960 | case Primitive::kPrimBoolean: |
| 961 | case Primitive::kPrimByte: |
| 962 | case Primitive::kPrimChar: |
| 963 | case Primitive::kPrimShort: |
| 964 | case Primitive::kPrimInt: |
| 965 | case Primitive::kPrimNot: { |
| 966 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 967 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 968 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 969 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 970 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 971 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 972 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 973 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 974 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 975 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 976 | uint32_t index = gp_index_; |
| 977 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 978 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 979 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 980 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 981 | calling_convention.GetRegisterPairAt(index)); |
| 982 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 983 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 984 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 989 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 990 | stack_index_++; |
| 991 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 992 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 993 | } else { |
| 994 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 999 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1000 | stack_index_ += 2; |
| 1001 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1002 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1003 | } else { |
| 1004 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1008 | case Primitive::kPrimVoid: |
| 1009 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1010 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1011 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1012 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1013 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1014 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1015 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1016 | if (source.Equals(destination)) { |
| 1017 | return; |
| 1018 | } |
| 1019 | if (destination.IsRegister()) { |
| 1020 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1021 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1022 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1023 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1024 | } else { |
| 1025 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1026 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1027 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1028 | } else if (destination.IsFpuRegister()) { |
| 1029 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1030 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1031 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1032 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1033 | } else { |
| 1034 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1035 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1036 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1037 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1038 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1039 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1040 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1041 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1042 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1043 | } else if (source.IsConstant()) { |
| 1044 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1045 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1046 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1047 | } else { |
| 1048 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1049 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1050 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1056 | if (source.Equals(destination)) { |
| 1057 | return; |
| 1058 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1059 | if (destination.IsRegisterPair()) { |
| 1060 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1061 | EmitParallelMoves( |
| 1062 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1063 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1064 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1065 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1066 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1067 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1068 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1069 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1070 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1071 | __ psrlq(src_reg, Immediate(32)); |
| 1072 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1073 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1074 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1075 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1076 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1077 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1078 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1079 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1080 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1081 | if (source.IsFpuRegister()) { |
| 1082 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1083 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1084 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1085 | } else if (source.IsRegisterPair()) { |
| 1086 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1087 | // Create stack space for 2 elements. |
| 1088 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1089 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1090 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1091 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1092 | // And remove the temporary stack space we allocated. |
| 1093 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1094 | } else { |
| 1095 | LOG(FATAL) << "Unimplemented"; |
| 1096 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1097 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1098 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1099 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1100 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1101 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1102 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1103 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1104 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1105 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1106 | } else if (source.IsConstant()) { |
| 1107 | HConstant* constant = source.GetConstant(); |
| 1108 | int64_t value; |
| 1109 | if (constant->IsLongConstant()) { |
| 1110 | value = constant->AsLongConstant()->GetValue(); |
| 1111 | } else { |
| 1112 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1113 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1114 | } |
| 1115 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1116 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1117 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1118 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1119 | EmitParallelMoves( |
| 1120 | Location::StackSlot(source.GetStackIndex()), |
| 1121 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1122 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1123 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1124 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1125 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1130 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1131 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1132 | if (instruction->IsCurrentMethod()) { |
| 1133 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1134 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1135 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1136 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1137 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1138 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1139 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1140 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1141 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1142 | } else if (location.IsStackSlot()) { |
| 1143 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 1144 | } else { |
| 1145 | DCHECK(location.IsConstant()); |
| 1146 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1147 | } |
| 1148 | } else if (const_to_move->IsLongConstant()) { |
| 1149 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1150 | if (location.IsRegisterPair()) { |
| 1151 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 1152 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 1153 | } else if (location.IsDoubleStackSlot()) { |
| 1154 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1155 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 1156 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1157 | } else { |
| 1158 | DCHECK(location.IsConstant()); |
| 1159 | DCHECK_EQ(location.GetConstant(), instruction); |
| 1160 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1161 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1162 | } else if (instruction->IsTemporary()) { |
| 1163 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1164 | if (temp_location.IsStackSlot()) { |
| 1165 | Move32(location, temp_location); |
| 1166 | } else { |
| 1167 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1168 | Move64(location, temp_location); |
| 1169 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1170 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1171 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1172 | switch (instruction->GetType()) { |
| 1173 | case Primitive::kPrimBoolean: |
| 1174 | case Primitive::kPrimByte: |
| 1175 | case Primitive::kPrimChar: |
| 1176 | case Primitive::kPrimShort: |
| 1177 | case Primitive::kPrimInt: |
| 1178 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1179 | case Primitive::kPrimFloat: |
| 1180 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1181 | break; |
| 1182 | |
| 1183 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | case Primitive::kPrimDouble: |
| 1185 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1186 | break; |
| 1187 | |
| 1188 | default: |
| 1189 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 1190 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1191 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1192 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1193 | switch (instruction->GetType()) { |
| 1194 | case Primitive::kPrimBoolean: |
| 1195 | case Primitive::kPrimByte: |
| 1196 | case Primitive::kPrimChar: |
| 1197 | case Primitive::kPrimShort: |
| 1198 | case Primitive::kPrimInt: |
| 1199 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1200 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1201 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1205 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1206 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1210 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1215 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1216 | DCHECK(location.IsRegister()); |
| 1217 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1218 | } |
| 1219 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1220 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1221 | if (Primitive::Is64BitType(dst_type)) { |
| 1222 | Move64(dst, src); |
| 1223 | } else { |
| 1224 | Move32(dst, src); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1229 | if (location.IsRegister()) { |
| 1230 | locations->AddTemp(location); |
| 1231 | } else if (location.IsRegisterPair()) { |
| 1232 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1233 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1234 | } else { |
| 1235 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1236 | } |
| 1237 | } |
| 1238 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1239 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1240 | DCHECK(!successor->IsExitBlock()); |
| 1241 | |
| 1242 | HBasicBlock* block = got->GetBlock(); |
| 1243 | HInstruction* previous = got->GetPrevious(); |
| 1244 | |
| 1245 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1246 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1247 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1248 | return; |
| 1249 | } |
| 1250 | |
| 1251 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1252 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1253 | } |
| 1254 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1255 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1259 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1260 | got->SetLocations(nullptr); |
| 1261 | } |
| 1262 | |
| 1263 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1264 | HandleGoto(got, got->GetSuccessor()); |
| 1265 | } |
| 1266 | |
| 1267 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1268 | try_boundary->SetLocations(nullptr); |
| 1269 | } |
| 1270 | |
| 1271 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1272 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1273 | if (!successor->IsExitBlock()) { |
| 1274 | HandleGoto(try_boundary, successor); |
| 1275 | } |
| 1276 | } |
| 1277 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1278 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1279 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1282 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1285 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1286 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1287 | LabelType* true_label, |
| 1288 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1289 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1290 | __ j(kUnordered, true_label); |
| 1291 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1292 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1294 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1297 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1298 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1299 | LabelType* true_label, |
| 1300 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1301 | LocationSummary* locations = cond->GetLocations(); |
| 1302 | Location left = locations->InAt(0); |
| 1303 | Location right = locations->InAt(1); |
| 1304 | IfCondition if_cond = cond->GetCondition(); |
| 1305 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1306 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1307 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1308 | IfCondition true_high_cond = if_cond; |
| 1309 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1310 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | |
| 1312 | // Set the conditions for the test, remembering that == needs to be |
| 1313 | // decided using the low words. |
| 1314 | switch (if_cond) { |
| 1315 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1316 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1317 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1318 | break; |
| 1319 | case kCondLT: |
| 1320 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1321 | break; |
| 1322 | case kCondLE: |
| 1323 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | break; |
| 1325 | case kCondGT: |
| 1326 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | break; |
| 1328 | case kCondGE: |
| 1329 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1330 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1331 | case kCondB: |
| 1332 | false_high_cond = kCondA; |
| 1333 | break; |
| 1334 | case kCondBE: |
| 1335 | true_high_cond = kCondB; |
| 1336 | break; |
| 1337 | case kCondA: |
| 1338 | false_high_cond = kCondB; |
| 1339 | break; |
| 1340 | case kCondAE: |
| 1341 | true_high_cond = kCondA; |
| 1342 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | if (right.IsConstant()) { |
| 1346 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1347 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1348 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1349 | |
| 1350 | if (val_high == 0) { |
| 1351 | __ testl(left_high, left_high); |
| 1352 | } else { |
| 1353 | __ cmpl(left_high, Immediate(val_high)); |
| 1354 | } |
| 1355 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1356 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1357 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1358 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1360 | __ j(X86Condition(true_high_cond), true_label); |
| 1361 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | } |
| 1363 | // Must be equal high, so compare the lows. |
| 1364 | if (val_low == 0) { |
| 1365 | __ testl(left_low, left_low); |
| 1366 | } else { |
| 1367 | __ cmpl(left_low, Immediate(val_low)); |
| 1368 | } |
| 1369 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1370 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1371 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | |
| 1373 | __ cmpl(left_high, right_high); |
| 1374 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1375 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1377 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1378 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1379 | __ j(X86Condition(true_high_cond), true_label); |
| 1380 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | } |
| 1382 | // Must be equal high, so compare the lows. |
| 1383 | __ cmpl(left_low, right_low); |
| 1384 | } |
| 1385 | // The last comparison might be unsigned. |
| 1386 | __ j(final_condition, true_label); |
| 1387 | } |
| 1388 | |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 1389 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1390 | Location rhs, |
| 1391 | HInstruction* insn, |
| 1392 | bool is_double) { |
| 1393 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1394 | if (is_double) { |
| 1395 | if (rhs.IsFpuRegister()) { |
| 1396 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1397 | } else if (const_area != nullptr) { |
| 1398 | DCHECK(!const_area->NeedsMaterialization()); |
| 1399 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1400 | codegen_->LiteralDoubleAddress( |
| 1401 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1402 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1403 | } else { |
| 1404 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1405 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1406 | } |
| 1407 | return; |
| 1408 | } |
| 1409 | |
| 1410 | if (rhs.IsFpuRegister()) { |
| 1411 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1412 | } else if (const_area != nullptr) { |
| 1413 | DCHECK(!const_area->NeedsMaterialization()); |
| 1414 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1415 | codegen_->LiteralFloatAddress( |
| 1416 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1417 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1418 | } else { |
| 1419 | DCHECK(rhs.IsStackSlot()); |
| 1420 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1421 | } |
| 1422 | } |
| 1423 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1424 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1425 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1426 | LabelType* true_target_in, |
| 1427 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1428 | // Generated branching requires both targets to be explicit. If either of the |
| 1429 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1430 | LabelType fallthrough_target; |
| 1431 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1432 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1433 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1434 | LocationSummary* locations = condition->GetLocations(); |
| 1435 | Location left = locations->InAt(0); |
| 1436 | Location right = locations->InAt(1); |
| 1437 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1438 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1439 | switch (type) { |
| 1440 | case Primitive::kPrimLong: |
| 1441 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1442 | break; |
| 1443 | case Primitive::kPrimFloat: |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 1444 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | GenerateFPJumps(condition, true_target, false_target); |
| 1446 | break; |
| 1447 | case Primitive::kPrimDouble: |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 1448 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1449 | GenerateFPJumps(condition, true_target, false_target); |
| 1450 | break; |
| 1451 | default: |
| 1452 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1453 | } |
| 1454 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1455 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1456 | __ jmp(false_target); |
| 1457 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1458 | |
| 1459 | if (fallthrough_target.IsLinked()) { |
| 1460 | __ Bind(&fallthrough_target); |
| 1461 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1462 | } |
| 1463 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1464 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1465 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1466 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1467 | // conditions if they are materialized due to the complex branching. |
| 1468 | return cond->IsCondition() && |
| 1469 | cond->GetNext() == branch && |
| 1470 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1471 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1472 | } |
| 1473 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1474 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1475 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1476 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1477 | LabelType* true_target, |
| 1478 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1479 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1480 | |
| 1481 | if (true_target == nullptr && false_target == nullptr) { |
| 1482 | // Nothing to do. The code always falls through. |
| 1483 | return; |
| 1484 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1485 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1486 | if (cond->AsIntConstant()->IsOne()) { |
| 1487 | if (true_target != nullptr) { |
| 1488 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1489 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1490 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1491 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1492 | if (false_target != nullptr) { |
| 1493 | __ jmp(false_target); |
| 1494 | } |
| 1495 | } |
| 1496 | return; |
| 1497 | } |
| 1498 | |
| 1499 | // The following code generates these patterns: |
| 1500 | // (1) true_target == nullptr && false_target != nullptr |
| 1501 | // - opposite condition true => branch to false_target |
| 1502 | // (2) true_target != nullptr && false_target == nullptr |
| 1503 | // - condition true => branch to true_target |
| 1504 | // (3) true_target != nullptr && false_target != nullptr |
| 1505 | // - condition true => branch to true_target |
| 1506 | // - branch to false_target |
| 1507 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1508 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1509 | if (true_target == nullptr) { |
| 1510 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1511 | } else { |
| 1512 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1513 | } |
| 1514 | } else { |
| 1515 | // Materialized condition, compare against 0. |
| 1516 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1517 | if (lhs.IsRegister()) { |
| 1518 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1519 | } else { |
| 1520 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1521 | } |
| 1522 | if (true_target == nullptr) { |
| 1523 | __ j(kEqual, false_target); |
| 1524 | } else { |
| 1525 | __ j(kNotEqual, true_target); |
| 1526 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1527 | } |
| 1528 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1529 | // Condition has not been materialized, use its inputs as the comparison and |
| 1530 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1531 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1532 | |
| 1533 | // If this is a long or FP comparison that has been folded into |
| 1534 | // the HCondition, generate the comparison directly. |
| 1535 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1536 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1537 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
| 1541 | Location lhs = condition->GetLocations()->InAt(0); |
| 1542 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1543 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1544 | if (rhs.IsRegister()) { |
| 1545 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1546 | } else if (rhs.IsConstant()) { |
| 1547 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1548 | if (constant == 0) { |
| 1549 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1550 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1551 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1552 | } |
| 1553 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1554 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1555 | } |
| 1556 | if (true_target == nullptr) { |
| 1557 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1558 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1559 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1560 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1561 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1562 | |
| 1563 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1564 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1565 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1566 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1570 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1571 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1572 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1573 | locations->SetInAt(0, Location::Any()); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1578 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1579 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1580 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1581 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1582 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1583 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1584 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1588 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1589 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1590 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1591 | locations->SetInAt(0, Location::Any()); |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1596 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1597 | GenerateTestAndBranch(deoptimize, |
| 1598 | /* condition_input_index */ 0, |
| 1599 | slow_path->GetEntryLabel(), |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1600 | /* false_target */ static_cast<Label*>(nullptr)); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1603 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1604 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1605 | } |
| 1606 | |
| 1607 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1608 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1609 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1610 | __ nop(); |
| 1611 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1612 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1613 | } |
| 1614 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1615 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1616 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1619 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1620 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1623 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1624 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1627 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1628 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1631 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1632 | LocationSummary* locations = |
| 1633 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1634 | switch (store->InputAt(1)->GetType()) { |
| 1635 | case Primitive::kPrimBoolean: |
| 1636 | case Primitive::kPrimByte: |
| 1637 | case Primitive::kPrimChar: |
| 1638 | case Primitive::kPrimShort: |
| 1639 | case Primitive::kPrimInt: |
| 1640 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1641 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1642 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1643 | break; |
| 1644 | |
| 1645 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1646 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1647 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1648 | break; |
| 1649 | |
| 1650 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1651 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1652 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1655 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1658 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1659 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1660 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1661 | // Handle the long/FP comparisons made in instruction simplification. |
| 1662 | switch (cond->InputAt(0)->GetType()) { |
| 1663 | case Primitive::kPrimLong: { |
| 1664 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1665 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1666 | if (cond->NeedsMaterialization()) { |
| 1667 | locations->SetOut(Location::RequiresRegister()); |
| 1668 | } |
| 1669 | break; |
| 1670 | } |
| 1671 | case Primitive::kPrimFloat: |
| 1672 | case Primitive::kPrimDouble: { |
| 1673 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 1674 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1675 | if (cond->NeedsMaterialization()) { |
| 1676 | locations->SetOut(Location::RequiresRegister()); |
| 1677 | } |
| 1678 | break; |
| 1679 | } |
| 1680 | default: |
| 1681 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1682 | locations->SetInAt(1, Location::Any()); |
| 1683 | if (cond->NeedsMaterialization()) { |
| 1684 | // We need a byte register. |
| 1685 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1686 | } |
| 1687 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1688 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1691 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1692 | if (!cond->NeedsMaterialization()) { |
| 1693 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1694 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 | |
| 1696 | LocationSummary* locations = cond->GetLocations(); |
| 1697 | Location lhs = locations->InAt(0); |
| 1698 | Location rhs = locations->InAt(1); |
| 1699 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1700 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1701 | |
| 1702 | switch (cond->InputAt(0)->GetType()) { |
| 1703 | default: { |
| 1704 | // Integer case. |
| 1705 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1706 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1707 | __ xorl(reg, reg); |
| 1708 | |
| 1709 | if (rhs.IsRegister()) { |
| 1710 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1711 | } else if (rhs.IsConstant()) { |
| 1712 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1713 | if (constant == 0) { |
| 1714 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1715 | } else { |
| 1716 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1717 | } |
| 1718 | } else { |
| 1719 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1720 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1721 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1722 | return; |
| 1723 | } |
| 1724 | case Primitive::kPrimLong: |
| 1725 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1726 | break; |
| 1727 | case Primitive::kPrimFloat: |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 1728 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1729 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1730 | break; |
| 1731 | case Primitive::kPrimDouble: |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 1732 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1733 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1734 | break; |
| 1735 | } |
| 1736 | |
| 1737 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1738 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1739 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1740 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1741 | __ Bind(&false_label); |
| 1742 | __ xorl(reg, reg); |
| 1743 | __ jmp(&done_label); |
| 1744 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1745 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1746 | __ Bind(&true_label); |
| 1747 | __ movl(reg, Immediate(1)); |
| 1748 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1752 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1756 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1760 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1764 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1831 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1832 | LocationSummary* locations = |
| 1833 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1834 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1837 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1838 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1841 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1842 | LocationSummary* locations = |
| 1843 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1844 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1845 | } |
| 1846 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1847 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1848 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1851 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1852 | LocationSummary* locations = |
| 1853 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1854 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1855 | } |
| 1856 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1857 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1858 | // Will be generated at use site. |
| 1859 | } |
| 1860 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1861 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1862 | LocationSummary* locations = |
| 1863 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1864 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1865 | } |
| 1866 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1867 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1868 | // Will be generated at use site. |
| 1869 | } |
| 1870 | |
| 1871 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1872 | LocationSummary* locations = |
| 1873 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1874 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1875 | } |
| 1876 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1877 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1878 | // Will be generated at use site. |
| 1879 | } |
| 1880 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1881 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1882 | memory_barrier->SetLocations(nullptr); |
| 1883 | } |
| 1884 | |
| 1885 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1886 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1887 | } |
| 1888 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1889 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1890 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1893 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1894 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1897 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1898 | LocationSummary* locations = |
| 1899 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1900 | switch (ret->InputAt(0)->GetType()) { |
| 1901 | case Primitive::kPrimBoolean: |
| 1902 | case Primitive::kPrimByte: |
| 1903 | case Primitive::kPrimChar: |
| 1904 | case Primitive::kPrimShort: |
| 1905 | case Primitive::kPrimInt: |
| 1906 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1907 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1908 | break; |
| 1909 | |
| 1910 | case Primitive::kPrimLong: |
| 1911 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1912 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1913 | break; |
| 1914 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1915 | case Primitive::kPrimFloat: |
| 1916 | case Primitive::kPrimDouble: |
| 1917 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1918 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1919 | break; |
| 1920 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1921 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1922 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1923 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1926 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1927 | if (kIsDebugBuild) { |
| 1928 | switch (ret->InputAt(0)->GetType()) { |
| 1929 | case Primitive::kPrimBoolean: |
| 1930 | case Primitive::kPrimByte: |
| 1931 | case Primitive::kPrimChar: |
| 1932 | case Primitive::kPrimShort: |
| 1933 | case Primitive::kPrimInt: |
| 1934 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1935 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1936 | break; |
| 1937 | |
| 1938 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1939 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1940 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1941 | break; |
| 1942 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1943 | case Primitive::kPrimFloat: |
| 1944 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1945 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1946 | break; |
| 1947 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1948 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1949 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1950 | } |
| 1951 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1952 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1955 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1956 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1957 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1958 | // the method_idx. |
| 1959 | HandleInvoke(invoke); |
| 1960 | } |
| 1961 | |
| 1962 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1963 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1964 | } |
| 1965 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1966 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1967 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1968 | // art::PrepareForRegisterAllocation. |
| 1969 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1970 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1971 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1972 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1973 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1974 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1975 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1976 | return; |
| 1977 | } |
| 1978 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1979 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1980 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1981 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1982 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1983 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1984 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1987 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1988 | if (invoke->GetLocations()->Intrinsified()) { |
| 1989 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1990 | intrinsic.Dispatch(invoke); |
| 1991 | return true; |
| 1992 | } |
| 1993 | return false; |
| 1994 | } |
| 1995 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1996 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1997 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1998 | // art::PrepareForRegisterAllocation. |
| 1999 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2000 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2001 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2002 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2003 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2004 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2005 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2006 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2007 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2008 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2012 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2013 | if (intrinsic.TryDispatch(invoke)) { |
| 2014 | return; |
| 2015 | } |
| 2016 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2017 | HandleInvoke(invoke); |
| 2018 | } |
| 2019 | |
| 2020 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2021 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2022 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2025 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2026 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2027 | return; |
| 2028 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2029 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2030 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2031 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2032 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2035 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2036 | // This call to HandleInvoke allocates a temporary (core) register |
| 2037 | // which is also used to transfer the hidden argument from FP to |
| 2038 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2039 | HandleInvoke(invoke); |
| 2040 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2041 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2045 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2046 | LocationSummary* locations = invoke->GetLocations(); |
| 2047 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2048 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2049 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2050 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2051 | Location receiver = locations->InAt(0); |
| 2052 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2053 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2054 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2055 | // won't be modified thereafter, before the `call` instruction. |
| 2056 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2057 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2058 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2059 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2060 | if (receiver.IsStackSlot()) { |
| 2061 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2062 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2063 | __ movl(temp, Address(temp, class_offset)); |
| 2064 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2065 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2066 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2067 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2068 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2069 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2070 | // emit a read barrier for the previous class reference load. |
| 2071 | // However this is not required in practice, as this is an |
| 2072 | // intermediate/temporary reference and because the current |
| 2073 | // concurrent copying collector keeps the from-space memory |
| 2074 | // intact/accessible until the end of the marking phase (the |
| 2075 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2076 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2077 | // temp = temp->GetImtEntryAt(method_offset); |
| 2078 | __ movl(temp, Address(temp, method_offset)); |
| 2079 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2080 | __ call(Address(temp, |
| 2081 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2082 | |
| 2083 | DCHECK(!codegen_->IsLeafMethod()); |
| 2084 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2085 | } |
| 2086 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2087 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2088 | LocationSummary* locations = |
| 2089 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2090 | switch (neg->GetResultType()) { |
| 2091 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2092 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2093 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2094 | locations->SetOut(Location::SameAsFirstInput()); |
| 2095 | break; |
| 2096 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2097 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2098 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2099 | locations->SetOut(Location::SameAsFirstInput()); |
| 2100 | locations->AddTemp(Location::RequiresRegister()); |
| 2101 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2102 | break; |
| 2103 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2104 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2105 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2106 | locations->SetOut(Location::SameAsFirstInput()); |
| 2107 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2108 | break; |
| 2109 | |
| 2110 | default: |
| 2111 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2116 | LocationSummary* locations = neg->GetLocations(); |
| 2117 | Location out = locations->Out(); |
| 2118 | Location in = locations->InAt(0); |
| 2119 | switch (neg->GetResultType()) { |
| 2120 | case Primitive::kPrimInt: |
| 2121 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2122 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2123 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2124 | break; |
| 2125 | |
| 2126 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2127 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2128 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2129 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2130 | // Negation is similar to subtraction from zero. The least |
| 2131 | // significant byte triggers a borrow when it is different from |
| 2132 | // zero; to take it into account, add 1 to the most significant |
| 2133 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2134 | // operation. |
| 2135 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2136 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2137 | break; |
| 2138 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2139 | case Primitive::kPrimFloat: { |
| 2140 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2141 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2142 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2143 | // Implement float negation with an exclusive or with value |
| 2144 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2145 | // single-precision floating-point number). |
| 2146 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2147 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2148 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2149 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2150 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2151 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimDouble: { |
| 2153 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2154 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2155 | // Implement double negation with an exclusive or with value |
| 2156 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2157 | // a double-precision floating-point number). |
| 2158 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2159 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2160 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2161 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2162 | |
| 2163 | default: |
| 2164 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2165 | } |
| 2166 | } |
| 2167 | |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 2168 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2169 | LocationSummary* locations = |
| 2170 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2171 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2172 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2173 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2174 | locations->SetOut(Location::SameAsFirstInput()); |
| 2175 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2176 | } |
| 2177 | |
| 2178 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2179 | LocationSummary* locations = neg->GetLocations(); |
| 2180 | Location out = locations->Out(); |
| 2181 | DCHECK(locations->InAt(0).Equals(out)); |
| 2182 | |
| 2183 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2184 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2185 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2186 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2187 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2188 | } else { |
| 2189 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2190 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2191 | } |
| 2192 | } |
| 2193 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2194 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2195 | Primitive::Type result_type = conversion->GetResultType(); |
| 2196 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2197 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2198 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2199 | // The float-to-long and double-to-long type conversions rely on a |
| 2200 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2201 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2202 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2203 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2204 | ? LocationSummary::kCall |
| 2205 | : LocationSummary::kNoCall; |
| 2206 | LocationSummary* locations = |
| 2207 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2208 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2209 | // The Java language does not allow treating boolean as an integral type but |
| 2210 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2211 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2212 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimByte: |
| 2214 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2215 | case Primitive::kPrimBoolean: |
| 2216 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2217 | case Primitive::kPrimShort: |
| 2218 | case Primitive::kPrimInt: |
| 2219 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2220 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2221 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2222 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2223 | // the validation of the linear scan implementation |
| 2224 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2225 | break; |
| 2226 | |
| 2227 | default: |
| 2228 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2229 | << " to " << result_type; |
| 2230 | } |
| 2231 | break; |
| 2232 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimShort: |
| 2234 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2235 | case Primitive::kPrimBoolean: |
| 2236 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2237 | case Primitive::kPrimByte: |
| 2238 | case Primitive::kPrimInt: |
| 2239 | case Primitive::kPrimChar: |
| 2240 | // Processing a Dex `int-to-short' instruction. |
| 2241 | locations->SetInAt(0, Location::Any()); |
| 2242 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2243 | break; |
| 2244 | |
| 2245 | default: |
| 2246 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2247 | << " to " << result_type; |
| 2248 | } |
| 2249 | break; |
| 2250 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimInt: |
| 2252 | switch (input_type) { |
| 2253 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2254 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2255 | locations->SetInAt(0, Location::Any()); |
| 2256 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2257 | break; |
| 2258 | |
| 2259 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2260 | // Processing a Dex `float-to-int' instruction. |
| 2261 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2262 | locations->SetOut(Location::RequiresRegister()); |
| 2263 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2264 | break; |
| 2265 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2267 | // Processing a Dex `double-to-int' instruction. |
| 2268 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2269 | locations->SetOut(Location::RequiresRegister()); |
| 2270 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2271 | break; |
| 2272 | |
| 2273 | default: |
| 2274 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2275 | << " to " << result_type; |
| 2276 | } |
| 2277 | break; |
| 2278 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2279 | case Primitive::kPrimLong: |
| 2280 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimBoolean: |
| 2282 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimByte: |
| 2284 | case Primitive::kPrimShort: |
| 2285 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2287 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2288 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2289 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2290 | break; |
| 2291 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2292 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2293 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2294 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2295 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2296 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2297 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2298 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2299 | // The runtime helper puts the result in EAX, EDX. |
| 2300 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2301 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2302 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2303 | |
| 2304 | default: |
| 2305 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2306 | << " to " << result_type; |
| 2307 | } |
| 2308 | break; |
| 2309 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimChar: |
| 2311 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimBoolean: |
| 2313 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimByte: |
| 2315 | case Primitive::kPrimShort: |
| 2316 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2317 | // Processing a Dex `int-to-char' instruction. |
| 2318 | locations->SetInAt(0, Location::Any()); |
| 2319 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2320 | break; |
| 2321 | |
| 2322 | default: |
| 2323 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2324 | << " to " << result_type; |
| 2325 | } |
| 2326 | break; |
| 2327 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2329 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2330 | case Primitive::kPrimBoolean: |
| 2331 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimByte: |
| 2333 | case Primitive::kPrimShort: |
| 2334 | case Primitive::kPrimInt: |
| 2335 | case Primitive::kPrimChar: |
| 2336 | // Processing a Dex `int-to-float' instruction. |
| 2337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2338 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2339 | break; |
| 2340 | |
| 2341 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2342 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2343 | locations->SetInAt(0, Location::Any()); |
| 2344 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2345 | break; |
| 2346 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2348 | // Processing a Dex `double-to-float' instruction. |
| 2349 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2350 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2351 | break; |
| 2352 | |
| 2353 | default: |
| 2354 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2355 | << " to " << result_type; |
| 2356 | }; |
| 2357 | break; |
| 2358 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2359 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2361 | case Primitive::kPrimBoolean: |
| 2362 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2363 | case Primitive::kPrimByte: |
| 2364 | case Primitive::kPrimShort: |
| 2365 | case Primitive::kPrimInt: |
| 2366 | case Primitive::kPrimChar: |
| 2367 | // Processing a Dex `int-to-double' instruction. |
| 2368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2369 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2370 | break; |
| 2371 | |
| 2372 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2373 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2374 | locations->SetInAt(0, Location::Any()); |
| 2375 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2376 | break; |
| 2377 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2378 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2379 | // Processing a Dex `float-to-double' instruction. |
| 2380 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2381 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2382 | break; |
| 2383 | |
| 2384 | default: |
| 2385 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2386 | << " to " << result_type; |
| 2387 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | |
| 2390 | default: |
| 2391 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2392 | << " to " << result_type; |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2397 | LocationSummary* locations = conversion->GetLocations(); |
| 2398 | Location out = locations->Out(); |
| 2399 | Location in = locations->InAt(0); |
| 2400 | Primitive::Type result_type = conversion->GetResultType(); |
| 2401 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2402 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2403 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2404 | case Primitive::kPrimByte: |
| 2405 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2406 | case Primitive::kPrimBoolean: |
| 2407 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2408 | case Primitive::kPrimShort: |
| 2409 | case Primitive::kPrimInt: |
| 2410 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2411 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2412 | if (in.IsRegister()) { |
| 2413 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2414 | } else { |
| 2415 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2416 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2417 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2418 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2419 | break; |
| 2420 | |
| 2421 | default: |
| 2422 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2423 | << " to " << result_type; |
| 2424 | } |
| 2425 | break; |
| 2426 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2427 | case Primitive::kPrimShort: |
| 2428 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2429 | case Primitive::kPrimBoolean: |
| 2430 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimByte: |
| 2432 | case Primitive::kPrimInt: |
| 2433 | case Primitive::kPrimChar: |
| 2434 | // Processing a Dex `int-to-short' instruction. |
| 2435 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2436 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2437 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2438 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2439 | } else { |
| 2440 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2441 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2442 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2443 | } |
| 2444 | break; |
| 2445 | |
| 2446 | default: |
| 2447 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2448 | << " to " << result_type; |
| 2449 | } |
| 2450 | break; |
| 2451 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2452 | case Primitive::kPrimInt: |
| 2453 | switch (input_type) { |
| 2454 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2455 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2456 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2457 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2458 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2459 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2460 | } else { |
| 2461 | DCHECK(in.IsConstant()); |
| 2462 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2463 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2464 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2465 | } |
| 2466 | break; |
| 2467 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2468 | case Primitive::kPrimFloat: { |
| 2469 | // Processing a Dex `float-to-int' instruction. |
| 2470 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2471 | Register output = out.AsRegister<Register>(); |
| 2472 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2473 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2474 | |
| 2475 | __ movl(output, Immediate(kPrimIntMax)); |
| 2476 | // temp = int-to-float(output) |
| 2477 | __ cvtsi2ss(temp, output); |
| 2478 | // if input >= temp goto done |
| 2479 | __ comiss(input, temp); |
| 2480 | __ j(kAboveEqual, &done); |
| 2481 | // if input == NaN goto nan |
| 2482 | __ j(kUnordered, &nan); |
| 2483 | // output = float-to-int-truncate(input) |
| 2484 | __ cvttss2si(output, input); |
| 2485 | __ jmp(&done); |
| 2486 | __ Bind(&nan); |
| 2487 | // output = 0 |
| 2488 | __ xorl(output, output); |
| 2489 | __ Bind(&done); |
| 2490 | break; |
| 2491 | } |
| 2492 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimDouble: { |
| 2494 | // Processing a Dex `double-to-int' instruction. |
| 2495 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2496 | Register output = out.AsRegister<Register>(); |
| 2497 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2498 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2499 | |
| 2500 | __ movl(output, Immediate(kPrimIntMax)); |
| 2501 | // temp = int-to-double(output) |
| 2502 | __ cvtsi2sd(temp, output); |
| 2503 | // if input >= temp goto done |
| 2504 | __ comisd(input, temp); |
| 2505 | __ j(kAboveEqual, &done); |
| 2506 | // if input == NaN goto nan |
| 2507 | __ j(kUnordered, &nan); |
| 2508 | // output = double-to-int-truncate(input) |
| 2509 | __ cvttsd2si(output, input); |
| 2510 | __ jmp(&done); |
| 2511 | __ Bind(&nan); |
| 2512 | // output = 0 |
| 2513 | __ xorl(output, output); |
| 2514 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2515 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2516 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2517 | |
| 2518 | default: |
| 2519 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2520 | << " to " << result_type; |
| 2521 | } |
| 2522 | break; |
| 2523 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2524 | case Primitive::kPrimLong: |
| 2525 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimBoolean: |
| 2527 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimByte: |
| 2529 | case Primitive::kPrimShort: |
| 2530 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2532 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2533 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2534 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2535 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2536 | __ cdq(); |
| 2537 | break; |
| 2538 | |
| 2539 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2540 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2541 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2542 | conversion, |
| 2543 | conversion->GetDexPc(), |
| 2544 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2545 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2546 | break; |
| 2547 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2548 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2549 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2550 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2551 | conversion, |
| 2552 | conversion->GetDexPc(), |
| 2553 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2554 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | |
| 2557 | default: |
| 2558 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2559 | << " to " << result_type; |
| 2560 | } |
| 2561 | break; |
| 2562 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2563 | case Primitive::kPrimChar: |
| 2564 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimBoolean: |
| 2566 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimByte: |
| 2568 | case Primitive::kPrimShort: |
| 2569 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2570 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2571 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2572 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2573 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2574 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2575 | } else { |
| 2576 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2577 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2578 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2579 | } |
| 2580 | break; |
| 2581 | |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2584 | << " to " << result_type; |
| 2585 | } |
| 2586 | break; |
| 2587 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2589 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimBoolean: |
| 2591 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimByte: |
| 2593 | case Primitive::kPrimShort: |
| 2594 | case Primitive::kPrimInt: |
| 2595 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2596 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2597 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2598 | break; |
| 2599 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2600 | case Primitive::kPrimLong: { |
| 2601 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2602 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2603 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2604 | // Create stack space for the call to |
| 2605 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2606 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2607 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2608 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2609 | __ subl(ESP, Immediate(adjustment)); |
| 2610 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2611 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2612 | // Load the value to the FP stack, using temporaries if needed. |
| 2613 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2614 | |
| 2615 | if (out.IsStackSlot()) { |
| 2616 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2617 | } else { |
| 2618 | __ fstps(Address(ESP, 0)); |
| 2619 | Location stack_temp = Location::StackSlot(0); |
| 2620 | codegen_->Move32(out, stack_temp); |
| 2621 | } |
| 2622 | |
| 2623 | // Remove the temporary stack space we allocated. |
| 2624 | if (adjustment != 0) { |
| 2625 | __ addl(ESP, Immediate(adjustment)); |
| 2626 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2627 | break; |
| 2628 | } |
| 2629 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2630 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2631 | // Processing a Dex `double-to-float' instruction. |
| 2632 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2633 | break; |
| 2634 | |
| 2635 | default: |
| 2636 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2637 | << " to " << result_type; |
| 2638 | }; |
| 2639 | break; |
| 2640 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2641 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2642 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimBoolean: |
| 2644 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2645 | case Primitive::kPrimByte: |
| 2646 | case Primitive::kPrimShort: |
| 2647 | case Primitive::kPrimInt: |
| 2648 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2649 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2650 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2651 | break; |
| 2652 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2653 | case Primitive::kPrimLong: { |
| 2654 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2655 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2656 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2657 | // Create stack space for the call to |
| 2658 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2659 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2660 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2661 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2662 | __ subl(ESP, Immediate(adjustment)); |
| 2663 | } |
| 2664 | |
| 2665 | // Load the value to the FP stack, using temporaries if needed. |
| 2666 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2667 | |
| 2668 | if (out.IsDoubleStackSlot()) { |
| 2669 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2670 | } else { |
| 2671 | __ fstpl(Address(ESP, 0)); |
| 2672 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2673 | codegen_->Move64(out, stack_temp); |
| 2674 | } |
| 2675 | |
| 2676 | // Remove the temporary stack space we allocated. |
| 2677 | if (adjustment != 0) { |
| 2678 | __ addl(ESP, Immediate(adjustment)); |
| 2679 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2683 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2684 | // Processing a Dex `float-to-double' instruction. |
| 2685 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2686 | break; |
| 2687 | |
| 2688 | default: |
| 2689 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2690 | << " to " << result_type; |
| 2691 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2692 | break; |
| 2693 | |
| 2694 | default: |
| 2695 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2696 | << " to " << result_type; |
| 2697 | } |
| 2698 | } |
| 2699 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2700 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2701 | LocationSummary* locations = |
| 2702 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2703 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2704 | case Primitive::kPrimInt: { |
| 2705 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2706 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2707 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2708 | break; |
| 2709 | } |
| 2710 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2711 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2712 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2713 | locations->SetInAt(1, Location::Any()); |
| 2714 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2715 | break; |
| 2716 | } |
| 2717 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2718 | case Primitive::kPrimFloat: |
| 2719 | case Primitive::kPrimDouble: { |
| 2720 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2721 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2722 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2723 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2724 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2725 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2726 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2727 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2728 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2729 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2733 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2734 | Location first = locations->InAt(0); |
| 2735 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2736 | Location out = locations->Out(); |
| 2737 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2738 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2739 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2740 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2741 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2742 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2743 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2744 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2745 | } else { |
| 2746 | __ leal(out.AsRegister<Register>(), Address( |
| 2747 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2748 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2749 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2750 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2751 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2752 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2753 | } else { |
| 2754 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2755 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2756 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2757 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2758 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2759 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2760 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2764 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2765 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2766 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2767 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2768 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2769 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2770 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2771 | } else { |
| 2772 | DCHECK(second.IsConstant()) << second; |
| 2773 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2774 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2775 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2776 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2777 | break; |
| 2778 | } |
| 2779 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2780 | case Primitive::kPrimFloat: { |
| 2781 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2782 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2783 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2784 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2785 | DCHECK(!const_area->NeedsMaterialization()); |
| 2786 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2787 | codegen_->LiteralFloatAddress( |
| 2788 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2789 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2790 | } else { |
| 2791 | DCHECK(second.IsStackSlot()); |
| 2792 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2793 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2794 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | case Primitive::kPrimDouble: { |
| 2798 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2799 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2800 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2801 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2802 | DCHECK(!const_area->NeedsMaterialization()); |
| 2803 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2804 | codegen_->LiteralDoubleAddress( |
| 2805 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2806 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2807 | } else { |
| 2808 | DCHECK(second.IsDoubleStackSlot()); |
| 2809 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2810 | } |
| 2811 | break; |
| 2812 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2813 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2814 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2815 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2819 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2820 | LocationSummary* locations = |
| 2821 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2822 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2823 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2824 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2825 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2826 | locations->SetInAt(1, Location::Any()); |
| 2827 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2828 | break; |
| 2829 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2830 | case Primitive::kPrimFloat: |
| 2831 | case Primitive::kPrimDouble: { |
| 2832 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2833 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2834 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2835 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2836 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2837 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2838 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2839 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2840 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2844 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2845 | Location first = locations->InAt(0); |
| 2846 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2847 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2848 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2849 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2850 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2851 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2852 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2853 | __ subl(first.AsRegister<Register>(), |
| 2854 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2855 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2856 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2857 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2858 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2862 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2863 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2864 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2865 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2866 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2867 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2868 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2869 | } else { |
| 2870 | DCHECK(second.IsConstant()) << second; |
| 2871 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2872 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2873 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2874 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2875 | break; |
| 2876 | } |
| 2877 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2878 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2879 | if (second.IsFpuRegister()) { |
| 2880 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2881 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2882 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2883 | DCHECK(!const_area->NeedsMaterialization()); |
| 2884 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2885 | codegen_->LiteralFloatAddress( |
| 2886 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2887 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2888 | } else { |
| 2889 | DCHECK(second.IsStackSlot()); |
| 2890 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2891 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2892 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2896 | if (second.IsFpuRegister()) { |
| 2897 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2898 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2899 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2900 | DCHECK(!const_area->NeedsMaterialization()); |
| 2901 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2902 | codegen_->LiteralDoubleAddress( |
| 2903 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2904 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2905 | } else { |
| 2906 | DCHECK(second.IsDoubleStackSlot()); |
| 2907 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2908 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2909 | break; |
| 2910 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2911 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2912 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2913 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2917 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2918 | LocationSummary* locations = |
| 2919 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2920 | switch (mul->GetResultType()) { |
| 2921 | case Primitive::kPrimInt: |
| 2922 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2923 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2924 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2925 | // Can use 3 operand multiply. |
| 2926 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2927 | } else { |
| 2928 | locations->SetOut(Location::SameAsFirstInput()); |
| 2929 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2930 | break; |
| 2931 | case Primitive::kPrimLong: { |
| 2932 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2933 | locations->SetInAt(1, Location::Any()); |
| 2934 | locations->SetOut(Location::SameAsFirstInput()); |
| 2935 | // Needed for imul on 32bits with 64bits output. |
| 2936 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2937 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2938 | break; |
| 2939 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2940 | case Primitive::kPrimFloat: |
| 2941 | case Primitive::kPrimDouble: { |
| 2942 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2943 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2944 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2945 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2946 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2947 | |
| 2948 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2949 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2954 | LocationSummary* locations = mul->GetLocations(); |
| 2955 | Location first = locations->InAt(0); |
| 2956 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2957 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2958 | |
| 2959 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2960 | case Primitive::kPrimInt: |
| 2961 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2962 | // problems where the output may not be the same as the first operand. |
| 2963 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2964 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2965 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2966 | } else if (second.IsRegister()) { |
| 2967 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2968 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2969 | } else { |
| 2970 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2971 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2972 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2973 | } |
| 2974 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2975 | |
| 2976 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2977 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2978 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2979 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2980 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2981 | |
| 2982 | DCHECK_EQ(EAX, eax); |
| 2983 | DCHECK_EQ(EDX, edx); |
| 2984 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2985 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2986 | // output: in1 |
| 2987 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2988 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2989 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2990 | if (second.IsConstant()) { |
| 2991 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2992 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2993 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2994 | int32_t low_value = Low32Bits(value); |
| 2995 | int32_t high_value = High32Bits(value); |
| 2996 | Immediate low(low_value); |
| 2997 | Immediate high(high_value); |
| 2998 | |
| 2999 | __ movl(eax, high); |
| 3000 | // eax <- in1.lo * in2.hi |
| 3001 | __ imull(eax, in1_lo); |
| 3002 | // in1.hi <- in1.hi * in2.lo |
| 3003 | __ imull(in1_hi, low); |
| 3004 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3005 | __ addl(in1_hi, eax); |
| 3006 | // move in2_lo to eax to prepare for double precision |
| 3007 | __ movl(eax, low); |
| 3008 | // edx:eax <- in1.lo * in2.lo |
| 3009 | __ mull(in1_lo); |
| 3010 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3011 | __ addl(in1_hi, edx); |
| 3012 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3013 | __ movl(in1_lo, eax); |
| 3014 | } else if (second.IsRegisterPair()) { |
| 3015 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3016 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3017 | |
| 3018 | __ movl(eax, in2_hi); |
| 3019 | // eax <- in1.lo * in2.hi |
| 3020 | __ imull(eax, in1_lo); |
| 3021 | // in1.hi <- in1.hi * in2.lo |
| 3022 | __ imull(in1_hi, in2_lo); |
| 3023 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3024 | __ addl(in1_hi, eax); |
| 3025 | // move in1_lo to eax to prepare for double precision |
| 3026 | __ movl(eax, in1_lo); |
| 3027 | // edx:eax <- in1.lo * in2.lo |
| 3028 | __ mull(in2_lo); |
| 3029 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3030 | __ addl(in1_hi, edx); |
| 3031 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3032 | __ movl(in1_lo, eax); |
| 3033 | } else { |
| 3034 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3035 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3036 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3037 | |
| 3038 | __ movl(eax, in2_hi); |
| 3039 | // eax <- in1.lo * in2.hi |
| 3040 | __ imull(eax, in1_lo); |
| 3041 | // in1.hi <- in1.hi * in2.lo |
| 3042 | __ imull(in1_hi, in2_lo); |
| 3043 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3044 | __ addl(in1_hi, eax); |
| 3045 | // move in1_lo to eax to prepare for double precision |
| 3046 | __ movl(eax, in1_lo); |
| 3047 | // edx:eax <- in1.lo * in2.lo |
| 3048 | __ mull(in2_lo); |
| 3049 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3050 | __ addl(in1_hi, edx); |
| 3051 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3052 | __ movl(in1_lo, eax); |
| 3053 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3054 | |
| 3055 | break; |
| 3056 | } |
| 3057 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3058 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3059 | DCHECK(first.Equals(locations->Out())); |
| 3060 | if (second.IsFpuRegister()) { |
| 3061 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3062 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3063 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3064 | DCHECK(!const_area->NeedsMaterialization()); |
| 3065 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3066 | codegen_->LiteralFloatAddress( |
| 3067 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3068 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3069 | } else { |
| 3070 | DCHECK(second.IsStackSlot()); |
| 3071 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3072 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3073 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3077 | DCHECK(first.Equals(locations->Out())); |
| 3078 | if (second.IsFpuRegister()) { |
| 3079 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3080 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3081 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3082 | DCHECK(!const_area->NeedsMaterialization()); |
| 3083 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3084 | codegen_->LiteralDoubleAddress( |
| 3085 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3086 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3087 | } else { |
| 3088 | DCHECK(second.IsDoubleStackSlot()); |
| 3089 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3090 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3091 | break; |
| 3092 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3093 | |
| 3094 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3095 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3096 | } |
| 3097 | } |
| 3098 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3099 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3100 | uint32_t temp_offset, |
| 3101 | uint32_t stack_adjustment, |
| 3102 | bool is_fp, |
| 3103 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3104 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3105 | DCHECK(!is_wide); |
| 3106 | if (is_fp) { |
| 3107 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3108 | } else { |
| 3109 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3110 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3111 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3112 | DCHECK(is_wide); |
| 3113 | if (is_fp) { |
| 3114 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3115 | } else { |
| 3116 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3117 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3118 | } else { |
| 3119 | // 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] | 3120 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3121 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3122 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3123 | if (is_fp) { |
| 3124 | __ flds(Address(ESP, temp_offset)); |
| 3125 | } else { |
| 3126 | __ filds(Address(ESP, temp_offset)); |
| 3127 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3128 | } else { |
| 3129 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3130 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3131 | if (is_fp) { |
| 3132 | __ fldl(Address(ESP, temp_offset)); |
| 3133 | } else { |
| 3134 | __ fildl(Address(ESP, temp_offset)); |
| 3135 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3141 | Primitive::Type type = rem->GetResultType(); |
| 3142 | bool is_float = type == Primitive::kPrimFloat; |
| 3143 | size_t elem_size = Primitive::ComponentSize(type); |
| 3144 | LocationSummary* locations = rem->GetLocations(); |
| 3145 | Location first = locations->InAt(0); |
| 3146 | Location second = locations->InAt(1); |
| 3147 | Location out = locations->Out(); |
| 3148 | |
| 3149 | // Create stack space for 2 elements. |
| 3150 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3151 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3152 | |
| 3153 | // 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] | 3154 | const bool is_wide = !is_float; |
| 3155 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3156 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3157 | |
| 3158 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3159 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3160 | __ Bind(&retry); |
| 3161 | __ fprem(); |
| 3162 | |
| 3163 | // Move FP status to AX. |
| 3164 | __ fstsw(); |
| 3165 | |
| 3166 | // And see if the argument reduction is complete. This is signaled by the |
| 3167 | // C2 FPU flag bit set to 0. |
| 3168 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3169 | __ j(kNotEqual, &retry); |
| 3170 | |
| 3171 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3172 | // Store FP top of stack to real stack. |
| 3173 | if (is_float) { |
| 3174 | __ fsts(Address(ESP, 0)); |
| 3175 | } else { |
| 3176 | __ fstl(Address(ESP, 0)); |
| 3177 | } |
| 3178 | |
| 3179 | // Pop the 2 items from the FP stack. |
| 3180 | __ fucompp(); |
| 3181 | |
| 3182 | // Load the value from the stack into an XMM register. |
| 3183 | DCHECK(out.IsFpuRegister()) << out; |
| 3184 | if (is_float) { |
| 3185 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3186 | } else { |
| 3187 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3188 | } |
| 3189 | |
| 3190 | // And remove the temporary stack space we allocated. |
| 3191 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3192 | } |
| 3193 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3194 | |
| 3195 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3196 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3197 | |
| 3198 | LocationSummary* locations = instruction->GetLocations(); |
| 3199 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3200 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3201 | |
| 3202 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3203 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3204 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3205 | |
| 3206 | DCHECK(imm == 1 || imm == -1); |
| 3207 | |
| 3208 | if (instruction->IsRem()) { |
| 3209 | __ xorl(out_register, out_register); |
| 3210 | } else { |
| 3211 | __ movl(out_register, input_register); |
| 3212 | if (imm == -1) { |
| 3213 | __ negl(out_register); |
| 3214 | } |
| 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3219 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3220 | LocationSummary* locations = instruction->GetLocations(); |
| 3221 | |
| 3222 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3223 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3224 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3225 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3226 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3227 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3228 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3229 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3230 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3231 | __ testl(input_register, input_register); |
| 3232 | __ cmovl(kGreaterEqual, num, input_register); |
| 3233 | int shift = CTZ(imm); |
| 3234 | __ sarl(num, Immediate(shift)); |
| 3235 | |
| 3236 | if (imm < 0) { |
| 3237 | __ negl(num); |
| 3238 | } |
| 3239 | |
| 3240 | __ movl(out_register, num); |
| 3241 | } |
| 3242 | |
| 3243 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3244 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3245 | |
| 3246 | LocationSummary* locations = instruction->GetLocations(); |
| 3247 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3248 | |
| 3249 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3250 | Register out = locations->Out().AsRegister<Register>(); |
| 3251 | Register num; |
| 3252 | Register edx; |
| 3253 | |
| 3254 | if (instruction->IsDiv()) { |
| 3255 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3256 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3257 | } else { |
| 3258 | edx = locations->Out().AsRegister<Register>(); |
| 3259 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3260 | } |
| 3261 | |
| 3262 | DCHECK_EQ(EAX, eax); |
| 3263 | DCHECK_EQ(EDX, edx); |
| 3264 | if (instruction->IsDiv()) { |
| 3265 | DCHECK_EQ(EAX, out); |
| 3266 | } else { |
| 3267 | DCHECK_EQ(EDX, out); |
| 3268 | } |
| 3269 | |
| 3270 | int64_t magic; |
| 3271 | int shift; |
| 3272 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3273 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3274 | NearLabel ndiv; |
| 3275 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3276 | // If numerator is 0, the result is 0, no computation needed. |
| 3277 | __ testl(eax, eax); |
| 3278 | __ j(kNotEqual, &ndiv); |
| 3279 | |
| 3280 | __ xorl(out, out); |
| 3281 | __ jmp(&end); |
| 3282 | |
| 3283 | __ Bind(&ndiv); |
| 3284 | |
| 3285 | // Save the numerator. |
| 3286 | __ movl(num, eax); |
| 3287 | |
| 3288 | // EAX = magic |
| 3289 | __ movl(eax, Immediate(magic)); |
| 3290 | |
| 3291 | // EDX:EAX = magic * numerator |
| 3292 | __ imull(num); |
| 3293 | |
| 3294 | if (imm > 0 && magic < 0) { |
| 3295 | // EDX += num |
| 3296 | __ addl(edx, num); |
| 3297 | } else if (imm < 0 && magic > 0) { |
| 3298 | __ subl(edx, num); |
| 3299 | } |
| 3300 | |
| 3301 | // Shift if needed. |
| 3302 | if (shift != 0) { |
| 3303 | __ sarl(edx, Immediate(shift)); |
| 3304 | } |
| 3305 | |
| 3306 | // EDX += 1 if EDX < 0 |
| 3307 | __ movl(eax, edx); |
| 3308 | __ shrl(edx, Immediate(31)); |
| 3309 | __ addl(edx, eax); |
| 3310 | |
| 3311 | if (instruction->IsRem()) { |
| 3312 | __ movl(eax, num); |
| 3313 | __ imull(edx, Immediate(imm)); |
| 3314 | __ subl(eax, edx); |
| 3315 | __ movl(edx, eax); |
| 3316 | } else { |
| 3317 | __ movl(eax, edx); |
| 3318 | } |
| 3319 | __ Bind(&end); |
| 3320 | } |
| 3321 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3322 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3323 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3324 | |
| 3325 | LocationSummary* locations = instruction->GetLocations(); |
| 3326 | Location out = locations->Out(); |
| 3327 | Location first = locations->InAt(0); |
| 3328 | Location second = locations->InAt(1); |
| 3329 | bool is_div = instruction->IsDiv(); |
| 3330 | |
| 3331 | switch (instruction->GetResultType()) { |
| 3332 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3333 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3334 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3335 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3336 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3337 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3338 | |
| 3339 | if (imm == 0) { |
| 3340 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3341 | } else if (imm == 1 || imm == -1) { |
| 3342 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3343 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3344 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3345 | } else { |
| 3346 | DCHECK(imm <= -2 || imm >= 2); |
| 3347 | GenerateDivRemWithAnyConstant(instruction); |
| 3348 | } |
| 3349 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3350 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3351 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3352 | is_div); |
| 3353 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3354 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3355 | Register second_reg = second.AsRegister<Register>(); |
| 3356 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3357 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3358 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3359 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3360 | __ cmpl(second_reg, Immediate(-1)); |
| 3361 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3362 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3363 | // edx:eax <- sign-extended of eax |
| 3364 | __ cdq(); |
| 3365 | // eax = quotient, edx = remainder |
| 3366 | __ idivl(second_reg); |
| 3367 | __ Bind(slow_path->GetExitLabel()); |
| 3368 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3369 | break; |
| 3370 | } |
| 3371 | |
| 3372 | case Primitive::kPrimLong: { |
| 3373 | InvokeRuntimeCallingConvention calling_convention; |
| 3374 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3375 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3376 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3377 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3378 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3379 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3380 | |
| 3381 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3382 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3383 | instruction, |
| 3384 | instruction->GetDexPc(), |
| 3385 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3386 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3387 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3388 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3389 | instruction, |
| 3390 | instruction->GetDexPc(), |
| 3391 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3392 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3393 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3394 | break; |
| 3395 | } |
| 3396 | |
| 3397 | default: |
| 3398 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3399 | } |
| 3400 | } |
| 3401 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3402 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3403 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3404 | ? LocationSummary::kCall |
| 3405 | : LocationSummary::kNoCall; |
| 3406 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3407 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3408 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3409 | case Primitive::kPrimInt: { |
| 3410 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3411 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3412 | locations->SetOut(Location::SameAsFirstInput()); |
| 3413 | // Intel uses edx:eax as the dividend. |
| 3414 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3415 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3416 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3417 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3418 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3419 | locations->AddTemp(Location::RequiresRegister()); |
| 3420 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3423 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3424 | InvokeRuntimeCallingConvention calling_convention; |
| 3425 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3426 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3427 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3428 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3429 | // Runtime helper puts the result in EAX, EDX. |
| 3430 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3431 | break; |
| 3432 | } |
| 3433 | case Primitive::kPrimFloat: |
| 3434 | case Primitive::kPrimDouble: { |
| 3435 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3436 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3437 | locations->SetOut(Location::SameAsFirstInput()); |
| 3438 | break; |
| 3439 | } |
| 3440 | |
| 3441 | default: |
| 3442 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3443 | } |
| 3444 | } |
| 3445 | |
| 3446 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3447 | LocationSummary* locations = div->GetLocations(); |
| 3448 | Location first = locations->InAt(0); |
| 3449 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3450 | |
| 3451 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3452 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3453 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3454 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3455 | break; |
| 3456 | } |
| 3457 | |
| 3458 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3459 | if (second.IsFpuRegister()) { |
| 3460 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3461 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3462 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3463 | DCHECK(!const_area->NeedsMaterialization()); |
| 3464 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3465 | codegen_->LiteralFloatAddress( |
| 3466 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3467 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3468 | } else { |
| 3469 | DCHECK(second.IsStackSlot()); |
| 3470 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3471 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3472 | break; |
| 3473 | } |
| 3474 | |
| 3475 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3476 | if (second.IsFpuRegister()) { |
| 3477 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3478 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3479 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3480 | DCHECK(!const_area->NeedsMaterialization()); |
| 3481 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3482 | codegen_->LiteralDoubleAddress( |
| 3483 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3484 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3485 | } else { |
| 3486 | DCHECK(second.IsDoubleStackSlot()); |
| 3487 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3488 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3489 | break; |
| 3490 | } |
| 3491 | |
| 3492 | default: |
| 3493 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3494 | } |
| 3495 | } |
| 3496 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3497 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3498 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3499 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3500 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3501 | ? LocationSummary::kCall |
| 3502 | : LocationSummary::kNoCall; |
| 3503 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3504 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3505 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3506 | case Primitive::kPrimInt: { |
| 3507 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3508 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3509 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3510 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3511 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3512 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3513 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3514 | locations->AddTemp(Location::RequiresRegister()); |
| 3515 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3516 | break; |
| 3517 | } |
| 3518 | case Primitive::kPrimLong: { |
| 3519 | InvokeRuntimeCallingConvention calling_convention; |
| 3520 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3521 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3522 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3523 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3524 | // Runtime helper puts the result in EAX, EDX. |
| 3525 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3526 | break; |
| 3527 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3528 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3529 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3530 | locations->SetInAt(0, Location::Any()); |
| 3531 | locations->SetInAt(1, Location::Any()); |
| 3532 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3533 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3534 | break; |
| 3535 | } |
| 3536 | |
| 3537 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3538 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3543 | Primitive::Type type = rem->GetResultType(); |
| 3544 | switch (type) { |
| 3545 | case Primitive::kPrimInt: |
| 3546 | case Primitive::kPrimLong: { |
| 3547 | GenerateDivRemIntegral(rem); |
| 3548 | break; |
| 3549 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3550 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3551 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3552 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 | break; |
| 3554 | } |
| 3555 | default: |
| 3556 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3557 | } |
| 3558 | } |
| 3559 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3560 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3561 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3562 | ? LocationSummary::kCallOnSlowPath |
| 3563 | : LocationSummary::kNoCall; |
| 3564 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3565 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3566 | case Primitive::kPrimByte: |
| 3567 | case Primitive::kPrimChar: |
| 3568 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3569 | case Primitive::kPrimInt: { |
| 3570 | locations->SetInAt(0, Location::Any()); |
| 3571 | break; |
| 3572 | } |
| 3573 | case Primitive::kPrimLong: { |
| 3574 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3575 | if (!instruction->IsConstant()) { |
| 3576 | locations->AddTemp(Location::RequiresRegister()); |
| 3577 | } |
| 3578 | break; |
| 3579 | } |
| 3580 | default: |
| 3581 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3582 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3583 | if (instruction->HasUses()) { |
| 3584 | locations->SetOut(Location::SameAsFirstInput()); |
| 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3589 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3590 | codegen_->AddSlowPath(slow_path); |
| 3591 | |
| 3592 | LocationSummary* locations = instruction->GetLocations(); |
| 3593 | Location value = locations->InAt(0); |
| 3594 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3595 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3596 | case Primitive::kPrimByte: |
| 3597 | case Primitive::kPrimChar: |
| 3598 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3599 | case Primitive::kPrimInt: { |
| 3600 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3601 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3602 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3603 | } else if (value.IsStackSlot()) { |
| 3604 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3605 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3606 | } else { |
| 3607 | DCHECK(value.IsConstant()) << value; |
| 3608 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3609 | __ jmp(slow_path->GetEntryLabel()); |
| 3610 | } |
| 3611 | } |
| 3612 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3613 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3614 | case Primitive::kPrimLong: { |
| 3615 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3616 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3617 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3618 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3619 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3620 | } else { |
| 3621 | DCHECK(value.IsConstant()) << value; |
| 3622 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3623 | __ jmp(slow_path->GetEntryLabel()); |
| 3624 | } |
| 3625 | } |
| 3626 | break; |
| 3627 | } |
| 3628 | default: |
| 3629 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3630 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3631 | } |
| 3632 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3633 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3634 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3635 | |
| 3636 | LocationSummary* locations = |
| 3637 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3638 | |
| 3639 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3640 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3641 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3642 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3643 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3644 | // The shift count needs to be in CL or a constant. |
| 3645 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3646 | locations->SetOut(Location::SameAsFirstInput()); |
| 3647 | break; |
| 3648 | } |
| 3649 | default: |
| 3650 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3651 | } |
| 3652 | } |
| 3653 | |
| 3654 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3655 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3656 | |
| 3657 | LocationSummary* locations = op->GetLocations(); |
| 3658 | Location first = locations->InAt(0); |
| 3659 | Location second = locations->InAt(1); |
| 3660 | DCHECK(first.Equals(locations->Out())); |
| 3661 | |
| 3662 | switch (op->GetResultType()) { |
| 3663 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3664 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3665 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3666 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3667 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3668 | DCHECK_EQ(ECX, second_reg); |
| 3669 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3670 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3671 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3672 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3673 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3674 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3675 | } |
| 3676 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3677 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3678 | if (shift == 0) { |
| 3679 | return; |
| 3680 | } |
| 3681 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3682 | if (op->IsShl()) { |
| 3683 | __ shll(first_reg, imm); |
| 3684 | } else if (op->IsShr()) { |
| 3685 | __ sarl(first_reg, imm); |
| 3686 | } else { |
| 3687 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3688 | } |
| 3689 | } |
| 3690 | break; |
| 3691 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3692 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3693 | if (second.IsRegister()) { |
| 3694 | Register second_reg = second.AsRegister<Register>(); |
| 3695 | DCHECK_EQ(ECX, second_reg); |
| 3696 | if (op->IsShl()) { |
| 3697 | GenerateShlLong(first, second_reg); |
| 3698 | } else if (op->IsShr()) { |
| 3699 | GenerateShrLong(first, second_reg); |
| 3700 | } else { |
| 3701 | GenerateUShrLong(first, second_reg); |
| 3702 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3703 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3704 | // Shift by a constant. |
| 3705 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3706 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3707 | if (shift != 0) { |
| 3708 | if (op->IsShl()) { |
| 3709 | GenerateShlLong(first, shift); |
| 3710 | } else if (op->IsShr()) { |
| 3711 | GenerateShrLong(first, shift); |
| 3712 | } else { |
| 3713 | GenerateUShrLong(first, shift); |
| 3714 | } |
| 3715 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3716 | } |
| 3717 | break; |
| 3718 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3719 | default: |
| 3720 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3721 | } |
| 3722 | } |
| 3723 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3724 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3725 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3726 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3727 | if (shift == 1) { |
| 3728 | // This is just an addition. |
| 3729 | __ addl(low, low); |
| 3730 | __ adcl(high, high); |
| 3731 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3732 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3733 | codegen_->EmitParallelMoves( |
| 3734 | loc.ToLow(), |
| 3735 | loc.ToHigh(), |
| 3736 | Primitive::kPrimInt, |
| 3737 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3738 | loc.ToLow(), |
| 3739 | Primitive::kPrimInt); |
| 3740 | } else if (shift > 32) { |
| 3741 | // Low part becomes 0. High part is low part << (shift-32). |
| 3742 | __ movl(high, low); |
| 3743 | __ shll(high, Immediate(shift - 32)); |
| 3744 | __ xorl(low, low); |
| 3745 | } else { |
| 3746 | // Between 1 and 31. |
| 3747 | __ shld(high, low, Immediate(shift)); |
| 3748 | __ shll(low, Immediate(shift)); |
| 3749 | } |
| 3750 | } |
| 3751 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3752 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3753 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3754 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3755 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3756 | __ testl(shifter, Immediate(32)); |
| 3757 | __ j(kEqual, &done); |
| 3758 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3759 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3760 | __ Bind(&done); |
| 3761 | } |
| 3762 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3763 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3764 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3765 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3766 | if (shift == 32) { |
| 3767 | // Need to copy the sign. |
| 3768 | DCHECK_NE(low, high); |
| 3769 | __ movl(low, high); |
| 3770 | __ sarl(high, Immediate(31)); |
| 3771 | } else if (shift > 32) { |
| 3772 | DCHECK_NE(low, high); |
| 3773 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3774 | __ movl(low, high); |
| 3775 | __ sarl(high, Immediate(31)); |
| 3776 | __ sarl(low, Immediate(shift - 32)); |
| 3777 | } else { |
| 3778 | // Between 1 and 31. |
| 3779 | __ shrd(low, high, Immediate(shift)); |
| 3780 | __ sarl(high, Immediate(shift)); |
| 3781 | } |
| 3782 | } |
| 3783 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3784 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3785 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3786 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3787 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3788 | __ testl(shifter, Immediate(32)); |
| 3789 | __ j(kEqual, &done); |
| 3790 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3791 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3792 | __ Bind(&done); |
| 3793 | } |
| 3794 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3795 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3796 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3797 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3798 | if (shift == 32) { |
| 3799 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3800 | codegen_->EmitParallelMoves( |
| 3801 | loc.ToHigh(), |
| 3802 | loc.ToLow(), |
| 3803 | Primitive::kPrimInt, |
| 3804 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3805 | loc.ToHigh(), |
| 3806 | Primitive::kPrimInt); |
| 3807 | } else if (shift > 32) { |
| 3808 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3809 | __ movl(low, high); |
| 3810 | __ shrl(low, Immediate(shift - 32)); |
| 3811 | __ xorl(high, high); |
| 3812 | } else { |
| 3813 | // Between 1 and 31. |
| 3814 | __ shrd(low, high, Immediate(shift)); |
| 3815 | __ shrl(high, Immediate(shift)); |
| 3816 | } |
| 3817 | } |
| 3818 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3819 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3820 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3821 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3822 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3823 | __ testl(shifter, Immediate(32)); |
| 3824 | __ j(kEqual, &done); |
| 3825 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3826 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3827 | __ Bind(&done); |
| 3828 | } |
| 3829 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3830 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3831 | LocationSummary* locations = |
| 3832 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3833 | |
| 3834 | switch (ror->GetResultType()) { |
| 3835 | case Primitive::kPrimLong: |
| 3836 | // Add the temporary needed. |
| 3837 | locations->AddTemp(Location::RequiresRegister()); |
| 3838 | FALLTHROUGH_INTENDED; |
| 3839 | case Primitive::kPrimInt: |
| 3840 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3841 | // The shift count needs to be in CL (unless it is a constant). |
| 3842 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3843 | locations->SetOut(Location::SameAsFirstInput()); |
| 3844 | break; |
| 3845 | default: |
| 3846 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3847 | UNREACHABLE(); |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3852 | LocationSummary* locations = ror->GetLocations(); |
| 3853 | Location first = locations->InAt(0); |
| 3854 | Location second = locations->InAt(1); |
| 3855 | |
| 3856 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3857 | Register first_reg = first.AsRegister<Register>(); |
| 3858 | if (second.IsRegister()) { |
| 3859 | Register second_reg = second.AsRegister<Register>(); |
| 3860 | __ rorl(first_reg, second_reg); |
| 3861 | } else { |
| 3862 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3863 | __ rorl(first_reg, imm); |
| 3864 | } |
| 3865 | return; |
| 3866 | } |
| 3867 | |
| 3868 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3869 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3870 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3871 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3872 | if (second.IsRegister()) { |
| 3873 | Register second_reg = second.AsRegister<Register>(); |
| 3874 | DCHECK_EQ(second_reg, ECX); |
| 3875 | __ movl(temp_reg, first_reg_hi); |
| 3876 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3877 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3878 | __ movl(temp_reg, first_reg_hi); |
| 3879 | __ testl(second_reg, Immediate(32)); |
| 3880 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3881 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3882 | } else { |
| 3883 | int32_t shift_amt = |
| 3884 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3885 | if (shift_amt == 0) { |
| 3886 | // Already fine. |
| 3887 | return; |
| 3888 | } |
| 3889 | if (shift_amt == 32) { |
| 3890 | // Just swap. |
| 3891 | __ movl(temp_reg, first_reg_lo); |
| 3892 | __ movl(first_reg_lo, first_reg_hi); |
| 3893 | __ movl(first_reg_hi, temp_reg); |
| 3894 | return; |
| 3895 | } |
| 3896 | |
| 3897 | Immediate imm(shift_amt); |
| 3898 | // Save the constents of the low value. |
| 3899 | __ movl(temp_reg, first_reg_lo); |
| 3900 | |
| 3901 | // Shift right into low, feeding bits from high. |
| 3902 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3903 | |
| 3904 | // Shift right into high, feeding bits from the original low. |
| 3905 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3906 | |
| 3907 | // Swap if needed. |
| 3908 | if (shift_amt > 32) { |
| 3909 | __ movl(temp_reg, first_reg_lo); |
| 3910 | __ movl(first_reg_lo, first_reg_hi); |
| 3911 | __ movl(first_reg_hi, temp_reg); |
| 3912 | } |
| 3913 | } |
| 3914 | } |
| 3915 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3916 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3917 | HandleShift(shl); |
| 3918 | } |
| 3919 | |
| 3920 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3921 | HandleShift(shl); |
| 3922 | } |
| 3923 | |
| 3924 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3925 | HandleShift(shr); |
| 3926 | } |
| 3927 | |
| 3928 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3929 | HandleShift(shr); |
| 3930 | } |
| 3931 | |
| 3932 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3933 | HandleShift(ushr); |
| 3934 | } |
| 3935 | |
| 3936 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3937 | HandleShift(ushr); |
| 3938 | } |
| 3939 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3940 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3941 | LocationSummary* locations = |
| 3942 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3943 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3944 | if (instruction->IsStringAlloc()) { |
| 3945 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3946 | } else { |
| 3947 | InvokeRuntimeCallingConvention calling_convention; |
| 3948 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3949 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3950 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3954 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3955 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3956 | if (instruction->IsStringAlloc()) { |
| 3957 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3958 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3959 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3960 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3961 | __ call(Address(temp, code_offset.Int32Value())); |
| 3962 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3963 | } else { |
| 3964 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3965 | instruction, |
| 3966 | instruction->GetDexPc(), |
| 3967 | nullptr); |
| 3968 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3969 | DCHECK(!codegen_->IsLeafMethod()); |
| 3970 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3971 | } |
| 3972 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3973 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3974 | LocationSummary* locations = |
| 3975 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3976 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3977 | InvokeRuntimeCallingConvention calling_convention; |
| 3978 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3979 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3980 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3984 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3985 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3986 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3987 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3988 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3989 | instruction, |
| 3990 | instruction->GetDexPc(), |
| 3991 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3992 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3993 | DCHECK(!codegen_->IsLeafMethod()); |
| 3994 | } |
| 3995 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3996 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3997 | LocationSummary* locations = |
| 3998 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3999 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4000 | if (location.IsStackSlot()) { |
| 4001 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4002 | } else if (location.IsDoubleStackSlot()) { |
| 4003 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4004 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4005 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4006 | } |
| 4007 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4008 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4009 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4010 | } |
| 4011 | |
| 4012 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4013 | LocationSummary* locations = |
| 4014 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4015 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4016 | } |
| 4017 | |
| 4018 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4019 | } |
| 4020 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4021 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4022 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4023 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4024 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4025 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4026 | } |
| 4027 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4028 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4029 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4030 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4031 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4032 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4033 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4034 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4035 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4036 | break; |
| 4037 | |
| 4038 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4039 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4040 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4041 | break; |
| 4042 | |
| 4043 | default: |
| 4044 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4045 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4046 | } |
| 4047 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4048 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4049 | LocationSummary* locations = |
| 4050 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4052 | locations->SetOut(Location::SameAsFirstInput()); |
| 4053 | } |
| 4054 | |
| 4055 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4056 | LocationSummary* locations = bool_not->GetLocations(); |
| 4057 | Location in = locations->InAt(0); |
| 4058 | Location out = locations->Out(); |
| 4059 | DCHECK(in.Equals(out)); |
| 4060 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4061 | } |
| 4062 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4063 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4064 | LocationSummary* locations = |
| 4065 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4066 | switch (compare->InputAt(0)->GetType()) { |
| 4067 | case Primitive::kPrimLong: { |
| 4068 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4069 | locations->SetInAt(1, Location::Any()); |
| 4070 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4071 | break; |
| 4072 | } |
| 4073 | case Primitive::kPrimFloat: |
| 4074 | case Primitive::kPrimDouble: { |
| 4075 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 4076 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4077 | locations->SetOut(Location::RequiresRegister()); |
| 4078 | break; |
| 4079 | } |
| 4080 | default: |
| 4081 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4082 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4086 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4087 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4088 | Location left = locations->InAt(0); |
| 4089 | Location right = locations->InAt(1); |
| 4090 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4091 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4092 | switch (compare->InputAt(0)->GetType()) { |
| 4093 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4094 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4095 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4096 | int32_t val_low = 0; |
| 4097 | int32_t val_high = 0; |
| 4098 | bool right_is_const = false; |
| 4099 | |
| 4100 | if (right.IsConstant()) { |
| 4101 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4102 | right_is_const = true; |
| 4103 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4104 | val_low = Low32Bits(val); |
| 4105 | val_high = High32Bits(val); |
| 4106 | } |
| 4107 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4108 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4109 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4110 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4111 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4112 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4113 | DCHECK(right_is_const) << right; |
| 4114 | if (val_high == 0) { |
| 4115 | __ testl(left_high, left_high); |
| 4116 | } else { |
| 4117 | __ cmpl(left_high, Immediate(val_high)); |
| 4118 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4119 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4120 | __ j(kLess, &less); // Signed compare. |
| 4121 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4122 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4123 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4124 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4125 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4126 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4127 | DCHECK(right_is_const) << right; |
| 4128 | if (val_low == 0) { |
| 4129 | __ testl(left_low, left_low); |
| 4130 | } else { |
| 4131 | __ cmpl(left_low, Immediate(val_low)); |
| 4132 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4133 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4134 | break; |
| 4135 | } |
| 4136 | case Primitive::kPrimFloat: { |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 4137 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4138 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4139 | break; |
| 4140 | } |
| 4141 | case Primitive::kPrimDouble: { |
Mark Mendell | dc00454 | 2015-10-30 09:45:03 -0400 | [diff] [blame^] | 4142 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4143 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4144 | break; |
| 4145 | } |
| 4146 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4147 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4148 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4149 | __ movl(out, Immediate(0)); |
| 4150 | __ j(kEqual, &done); |
| 4151 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4152 | |
| 4153 | __ Bind(&greater); |
| 4154 | __ movl(out, Immediate(1)); |
| 4155 | __ jmp(&done); |
| 4156 | |
| 4157 | __ Bind(&less); |
| 4158 | __ movl(out, Immediate(-1)); |
| 4159 | |
| 4160 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4163 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4164 | LocationSummary* locations = |
| 4165 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4166 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4167 | locations->SetInAt(i, Location::Any()); |
| 4168 | } |
| 4169 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4170 | } |
| 4171 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4172 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4173 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4174 | } |
| 4175 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4176 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | /* |
| 4178 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4179 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4180 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4181 | */ |
| 4182 | switch (kind) { |
| 4183 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4184 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4185 | break; |
| 4186 | } |
| 4187 | case MemBarrierKind::kAnyStore: |
| 4188 | case MemBarrierKind::kLoadAny: |
| 4189 | case MemBarrierKind::kStoreStore: { |
| 4190 | // nop |
| 4191 | break; |
| 4192 | } |
| 4193 | default: |
| 4194 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4195 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4198 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4199 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4200 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4201 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4202 | |
| 4203 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4204 | // is incompatible with it. |
| 4205 | if (GetGraph()->HasIrreducibleLoops() && |
| 4206 | (dispatch_info.method_load_kind == |
| 4207 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4208 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4209 | } |
| 4210 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4211 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4212 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4213 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4214 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4215 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4216 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4217 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4218 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4219 | 0u |
| 4220 | }; |
| 4221 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4222 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4223 | } |
| 4224 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4225 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4226 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4227 | Register temp) { |
| 4228 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4229 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4230 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4231 | return location.AsRegister<Register>(); |
| 4232 | } |
| 4233 | // For intrinsics we allow any location, so it may be on the stack. |
| 4234 | if (!location.IsRegister()) { |
| 4235 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4236 | return temp; |
| 4237 | } |
| 4238 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4239 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4240 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4241 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4242 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4243 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4244 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4245 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4246 | __ movl(temp, Address(ESP, stack_offset)); |
| 4247 | return temp; |
| 4248 | } |
| 4249 | return location.AsRegister<Register>(); |
| 4250 | } |
| 4251 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4252 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4253 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4254 | switch (invoke->GetMethodLoadKind()) { |
| 4255 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4256 | // temp = thread->string_init_entrypoint |
| 4257 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4258 | break; |
| 4259 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4260 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4261 | break; |
| 4262 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4263 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4264 | break; |
| 4265 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4266 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4267 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4268 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4269 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4270 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4271 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4272 | temp.AsRegister<Register>()); |
| 4273 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4274 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4275 | // Add the patch entry and bind its label at the end of the instruction. |
| 4276 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4277 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4278 | break; |
| 4279 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4280 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4281 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4282 | Register method_reg; |
| 4283 | Register reg = temp.AsRegister<Register>(); |
| 4284 | if (current_method.IsRegister()) { |
| 4285 | method_reg = current_method.AsRegister<Register>(); |
| 4286 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4287 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4288 | DCHECK(!current_method.IsValid()); |
| 4289 | method_reg = reg; |
| 4290 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4291 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4292 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4293 | __ movl(reg, Address(method_reg, |
| 4294 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4295 | // temp = temp[index_in_cache] |
| 4296 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4297 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4298 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4299 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | switch (invoke->GetCodePtrLocation()) { |
| 4303 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4304 | __ call(GetFrameEntryLabel()); |
| 4305 | break; |
| 4306 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4307 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4308 | Label* label = &relative_call_patches_.back().label; |
| 4309 | __ call(label); // Bind to the patch label, override at link time. |
| 4310 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4311 | break; |
| 4312 | } |
| 4313 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4314 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4315 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4316 | LOG(FATAL) << "Unsupported"; |
| 4317 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4318 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4319 | // (callee_method + offset_of_quick_compiled_code)() |
| 4320 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4321 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4322 | kX86WordSize).Int32Value())); |
| 4323 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4327 | } |
| 4328 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4329 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4330 | Register temp = temp_in.AsRegister<Register>(); |
| 4331 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4332 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4333 | |
| 4334 | // Use the calling convention instead of the location of the receiver, as |
| 4335 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4336 | // slow path, the arguments have been moved to the right place, so here we are |
| 4337 | // guaranteed that the receiver is the first register of the calling convention. |
| 4338 | InvokeDexCallingConvention calling_convention; |
| 4339 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4340 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4341 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4342 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4343 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4344 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4345 | // emit a read barrier for the previous class reference load. |
| 4346 | // However this is not required in practice, as this is an |
| 4347 | // intermediate/temporary reference and because the current |
| 4348 | // concurrent copying collector keeps the from-space memory |
| 4349 | // intact/accessible until the end of the marking phase (the |
| 4350 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4351 | __ MaybeUnpoisonHeapReference(temp); |
| 4352 | // temp = temp->GetMethodAt(method_offset); |
| 4353 | __ movl(temp, Address(temp, method_offset)); |
| 4354 | // call temp->GetEntryPoint(); |
| 4355 | __ call(Address( |
| 4356 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4357 | } |
| 4358 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4359 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4360 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4361 | size_t size = |
| 4362 | method_patches_.size() + |
| 4363 | relative_call_patches_.size() + |
| 4364 | pc_relative_dex_cache_patches_.size(); |
| 4365 | linker_patches->reserve(size); |
| 4366 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4367 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4368 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4369 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4370 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4371 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4372 | info.target_method.dex_file, |
| 4373 | info.target_method.dex_method_index)); |
| 4374 | } |
| 4375 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4376 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4377 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4378 | info.target_method.dex_file, |
| 4379 | info.target_method.dex_method_index)); |
| 4380 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4381 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4382 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4383 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4384 | &info.target_dex_file, |
| 4385 | GetMethodAddressOffset(), |
| 4386 | info.element_offset)); |
| 4387 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4390 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4391 | Register card, |
| 4392 | Register object, |
| 4393 | Register value, |
| 4394 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4395 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4396 | if (value_can_be_null) { |
| 4397 | __ testl(value, value); |
| 4398 | __ j(kEqual, &is_null); |
| 4399 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4400 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4401 | __ movl(temp, object); |
| 4402 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4403 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4404 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4405 | if (value_can_be_null) { |
| 4406 | __ Bind(&is_null); |
| 4407 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4408 | } |
| 4409 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4410 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4411 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4412 | |
| 4413 | bool object_field_get_with_read_barrier = |
| 4414 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4415 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4416 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4417 | kEmitCompilerReadBarrier ? |
| 4418 | LocationSummary::kCallOnSlowPath : |
| 4419 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4420 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4421 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4422 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4423 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4424 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4425 | // The output overlaps in case of long: we don't want the low move |
| 4426 | // to overwrite the object's location. Likewise, in the case of |
| 4427 | // an object field get with read barriers enabled, we do not want |
| 4428 | // the move to overwrite the object's location, as we need it to emit |
| 4429 | // the read barrier. |
| 4430 | locations->SetOut( |
| 4431 | Location::RequiresRegister(), |
| 4432 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4433 | Location::kOutputOverlap : |
| 4434 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4435 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4436 | |
| 4437 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4438 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4439 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4440 | // load the temp into the XMM and then copy the XMM into the |
| 4441 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4442 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4443 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4444 | // We need a temporary register for the read barrier marking slow |
| 4445 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4446 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4447 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | } |
| 4449 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4450 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4451 | const FieldInfo& field_info) { |
| 4452 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4453 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4454 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4455 | Location base_loc = locations->InAt(0); |
| 4456 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4457 | Location out = locations->Out(); |
| 4458 | bool is_volatile = field_info.IsVolatile(); |
| 4459 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4460 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4461 | |
| 4462 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4463 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4464 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4465 | break; |
| 4466 | } |
| 4467 | |
| 4468 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4469 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4470 | break; |
| 4471 | } |
| 4472 | |
| 4473 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4474 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4475 | break; |
| 4476 | } |
| 4477 | |
| 4478 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4479 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4480 | break; |
| 4481 | } |
| 4482 | |
| 4483 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4484 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4486 | |
| 4487 | case Primitive::kPrimNot: { |
| 4488 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4489 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4490 | Location temp_loc = locations->GetTemp(0); |
| 4491 | // Note that a potential implicit null check is handled in this |
| 4492 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4493 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4494 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4495 | if (is_volatile) { |
| 4496 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4497 | } |
| 4498 | } else { |
| 4499 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4500 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4501 | if (is_volatile) { |
| 4502 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4503 | } |
| 4504 | // If read barriers are enabled, emit read barriers other than |
| 4505 | // Baker's using a slow path (and also unpoison the loaded |
| 4506 | // reference, if heap poisoning is enabled). |
| 4507 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4508 | } |
| 4509 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4513 | if (is_volatile) { |
| 4514 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4515 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4516 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4517 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4518 | __ psrlq(temp, Immediate(32)); |
| 4519 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4520 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4521 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4522 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4523 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4524 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4525 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4526 | break; |
| 4527 | } |
| 4528 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4529 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4530 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4531 | break; |
| 4532 | } |
| 4533 | |
| 4534 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4536 | break; |
| 4537 | } |
| 4538 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4539 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4541 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4542 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4543 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4544 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4545 | // Potential implicit null checks, in the case of reference or |
| 4546 | // long fields, are handled in the previous switch statement. |
| 4547 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4548 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4549 | } |
| 4550 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4551 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4552 | if (field_type == Primitive::kPrimNot) { |
| 4553 | // Memory barriers, in the case of references, are also handled |
| 4554 | // in the previous switch statement. |
| 4555 | } else { |
| 4556 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4557 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4558 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | } |
| 4560 | |
| 4561 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4562 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4563 | |
| 4564 | LocationSummary* locations = |
| 4565 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4566 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4567 | bool is_volatile = field_info.IsVolatile(); |
| 4568 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4569 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4570 | || (field_type == Primitive::kPrimByte); |
| 4571 | |
| 4572 | // The register allocator does not support multiple |
| 4573 | // inputs that die at entry with one in a specific register. |
| 4574 | if (is_byte_type) { |
| 4575 | // Ensure the value is in a byte register. |
| 4576 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4577 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4578 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4579 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4580 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4581 | } else { |
| 4582 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4583 | } |
| 4584 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4585 | // 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] | 4586 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4587 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4589 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4590 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4591 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4592 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4593 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4594 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4595 | } else { |
| 4596 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4597 | |
| 4598 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4599 | // Temporary registers for the write barrier. |
| 4600 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4601 | // Ensure the card is in a byte register. |
| 4602 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4603 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4608 | const FieldInfo& field_info, |
| 4609 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4610 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4611 | |
| 4612 | LocationSummary* locations = instruction->GetLocations(); |
| 4613 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4614 | Location value = locations->InAt(1); |
| 4615 | bool is_volatile = field_info.IsVolatile(); |
| 4616 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4617 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4618 | bool needs_write_barrier = |
| 4619 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4620 | |
| 4621 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4622 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4623 | } |
| 4624 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4625 | bool maybe_record_implicit_null_check_done = false; |
| 4626 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4627 | switch (field_type) { |
| 4628 | case Primitive::kPrimBoolean: |
| 4629 | case Primitive::kPrimByte: { |
| 4630 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4631 | break; |
| 4632 | } |
| 4633 | |
| 4634 | case Primitive::kPrimShort: |
| 4635 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4636 | if (value.IsConstant()) { |
| 4637 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4638 | __ movw(Address(base, offset), Immediate(v)); |
| 4639 | } else { |
| 4640 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4641 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | break; |
| 4643 | } |
| 4644 | |
| 4645 | case Primitive::kPrimInt: |
| 4646 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4647 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4648 | // Note that in the case where `value` is a null reference, |
| 4649 | // we do not enter this block, as the reference does not |
| 4650 | // need poisoning. |
| 4651 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4652 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4653 | __ movl(temp, value.AsRegister<Register>()); |
| 4654 | __ PoisonHeapReference(temp); |
| 4655 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4656 | } else if (value.IsConstant()) { |
| 4657 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4658 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4659 | } else { |
| 4660 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4661 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4662 | break; |
| 4663 | } |
| 4664 | |
| 4665 | case Primitive::kPrimLong: { |
| 4666 | if (is_volatile) { |
| 4667 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4668 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4669 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4670 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4671 | __ punpckldq(temp1, temp2); |
| 4672 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4673 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4674 | } else if (value.IsConstant()) { |
| 4675 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4676 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4677 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4678 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4679 | } else { |
| 4680 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4681 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4682 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4683 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4684 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4685 | break; |
| 4686 | } |
| 4687 | |
| 4688 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4689 | if (value.IsConstant()) { |
| 4690 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4691 | __ movl(Address(base, offset), Immediate(v)); |
| 4692 | } else { |
| 4693 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4694 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4695 | break; |
| 4696 | } |
| 4697 | |
| 4698 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4699 | if (value.IsConstant()) { |
| 4700 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4701 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4702 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4703 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4704 | maybe_record_implicit_null_check_done = true; |
| 4705 | } else { |
| 4706 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4707 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4708 | break; |
| 4709 | } |
| 4710 | |
| 4711 | case Primitive::kPrimVoid: |
| 4712 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4713 | UNREACHABLE(); |
| 4714 | } |
| 4715 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4716 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4717 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4718 | } |
| 4719 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4720 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4721 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4722 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4723 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4724 | } |
| 4725 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4726 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4727 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4732 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4733 | } |
| 4734 | |
| 4735 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4736 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4737 | } |
| 4738 | |
| 4739 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4740 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4741 | } |
| 4742 | |
| 4743 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4744 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4748 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4749 | } |
| 4750 | |
| 4751 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4752 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4756 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4757 | } |
| 4758 | |
| 4759 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4760 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4761 | } |
| 4762 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4763 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4764 | HUnresolvedInstanceFieldGet* instruction) { |
| 4765 | FieldAccessCallingConventionX86 calling_convention; |
| 4766 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4767 | instruction, instruction->GetFieldType(), calling_convention); |
| 4768 | } |
| 4769 | |
| 4770 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4771 | HUnresolvedInstanceFieldGet* instruction) { |
| 4772 | FieldAccessCallingConventionX86 calling_convention; |
| 4773 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4774 | instruction->GetFieldType(), |
| 4775 | instruction->GetFieldIndex(), |
| 4776 | instruction->GetDexPc(), |
| 4777 | calling_convention); |
| 4778 | } |
| 4779 | |
| 4780 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4781 | HUnresolvedInstanceFieldSet* instruction) { |
| 4782 | FieldAccessCallingConventionX86 calling_convention; |
| 4783 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4784 | instruction, instruction->GetFieldType(), calling_convention); |
| 4785 | } |
| 4786 | |
| 4787 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4788 | HUnresolvedInstanceFieldSet* instruction) { |
| 4789 | FieldAccessCallingConventionX86 calling_convention; |
| 4790 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4791 | instruction->GetFieldType(), |
| 4792 | instruction->GetFieldIndex(), |
| 4793 | instruction->GetDexPc(), |
| 4794 | calling_convention); |
| 4795 | } |
| 4796 | |
| 4797 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4798 | HUnresolvedStaticFieldGet* instruction) { |
| 4799 | FieldAccessCallingConventionX86 calling_convention; |
| 4800 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4801 | instruction, instruction->GetFieldType(), calling_convention); |
| 4802 | } |
| 4803 | |
| 4804 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4805 | HUnresolvedStaticFieldGet* instruction) { |
| 4806 | FieldAccessCallingConventionX86 calling_convention; |
| 4807 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4808 | instruction->GetFieldType(), |
| 4809 | instruction->GetFieldIndex(), |
| 4810 | instruction->GetDexPc(), |
| 4811 | calling_convention); |
| 4812 | } |
| 4813 | |
| 4814 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4815 | HUnresolvedStaticFieldSet* instruction) { |
| 4816 | FieldAccessCallingConventionX86 calling_convention; |
| 4817 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4818 | instruction, instruction->GetFieldType(), calling_convention); |
| 4819 | } |
| 4820 | |
| 4821 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4822 | HUnresolvedStaticFieldSet* instruction) { |
| 4823 | FieldAccessCallingConventionX86 calling_convention; |
| 4824 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4825 | instruction->GetFieldType(), |
| 4826 | instruction->GetFieldIndex(), |
| 4827 | instruction->GetDexPc(), |
| 4828 | calling_convention); |
| 4829 | } |
| 4830 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4831 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4832 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4833 | ? LocationSummary::kCallOnSlowPath |
| 4834 | : LocationSummary::kNoCall; |
| 4835 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4836 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4837 | ? Location::RequiresRegister() |
| 4838 | : Location::Any(); |
| 4839 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4840 | if (instruction->HasUses()) { |
| 4841 | locations->SetOut(Location::SameAsFirstInput()); |
| 4842 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4845 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4846 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4847 | return; |
| 4848 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4849 | LocationSummary* locations = instruction->GetLocations(); |
| 4850 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4851 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4852 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4853 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4854 | } |
| 4855 | |
| 4856 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4857 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4858 | codegen_->AddSlowPath(slow_path); |
| 4859 | |
| 4860 | LocationSummary* locations = instruction->GetLocations(); |
| 4861 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4862 | |
| 4863 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4864 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4865 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4866 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4867 | } else { |
| 4868 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4869 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4870 | __ jmp(slow_path->GetEntryLabel()); |
| 4871 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4872 | } |
| 4873 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4874 | } |
| 4875 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4876 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4877 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4878 | GenerateImplicitNullCheck(instruction); |
| 4879 | } else { |
| 4880 | GenerateExplicitNullCheck(instruction); |
| 4881 | } |
| 4882 | } |
| 4883 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4884 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4885 | bool object_array_get_with_read_barrier = |
| 4886 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4887 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4888 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4889 | object_array_get_with_read_barrier ? |
| 4890 | LocationSummary::kCallOnSlowPath : |
| 4891 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4892 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4893 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4894 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4895 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4896 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4897 | // The output overlaps in case of long: we don't want the low move |
| 4898 | // to overwrite the array's location. Likewise, in the case of an |
| 4899 | // object array get with read barriers enabled, we do not want the |
| 4900 | // move to overwrite the array's location, as we need it to emit |
| 4901 | // the read barrier. |
| 4902 | locations->SetOut( |
| 4903 | Location::RequiresRegister(), |
| 4904 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4905 | Location::kOutputOverlap : |
| 4906 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4907 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4908 | // We need a temporary register for the read barrier marking slow |
| 4909 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4910 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4911 | locations->AddTemp(Location::RequiresRegister()); |
| 4912 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4916 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4917 | Location obj_loc = locations->InAt(0); |
| 4918 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4919 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4920 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4921 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4922 | Primitive::Type type = instruction->GetType(); |
| 4923 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4924 | case Primitive::kPrimBoolean: { |
| 4925 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4926 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4927 | if (index.IsConstant()) { |
| 4928 | __ movzxb(out, Address(obj, |
| 4929 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4930 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4931 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4932 | } |
| 4933 | break; |
| 4934 | } |
| 4935 | |
| 4936 | case Primitive::kPrimByte: { |
| 4937 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4938 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4939 | if (index.IsConstant()) { |
| 4940 | __ movsxb(out, Address(obj, |
| 4941 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4942 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4943 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4944 | } |
| 4945 | break; |
| 4946 | } |
| 4947 | |
| 4948 | case Primitive::kPrimShort: { |
| 4949 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4950 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4951 | if (index.IsConstant()) { |
| 4952 | __ movsxw(out, Address(obj, |
| 4953 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4954 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4955 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4956 | } |
| 4957 | break; |
| 4958 | } |
| 4959 | |
| 4960 | case Primitive::kPrimChar: { |
| 4961 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4962 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4963 | if (index.IsConstant()) { |
| 4964 | __ movzxw(out, Address(obj, |
| 4965 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4966 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4967 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4968 | } |
| 4969 | break; |
| 4970 | } |
| 4971 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4972 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4973 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4974 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4975 | if (index.IsConstant()) { |
| 4976 | __ movl(out, Address(obj, |
| 4977 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4978 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4979 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4980 | } |
| 4981 | break; |
| 4982 | } |
| 4983 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4984 | case Primitive::kPrimNot: { |
| 4985 | static_assert( |
| 4986 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4987 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4988 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4989 | // /* HeapReference<Object> */ out = |
| 4990 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4991 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4992 | Location temp = locations->GetTemp(0); |
| 4993 | // Note that a potential implicit null check is handled in this |
| 4994 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4995 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4996 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4997 | } else { |
| 4998 | Register out = out_loc.AsRegister<Register>(); |
| 4999 | if (index.IsConstant()) { |
| 5000 | uint32_t offset = |
| 5001 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5002 | __ movl(out, Address(obj, offset)); |
| 5003 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5004 | // If read barriers are enabled, emit read barriers other than |
| 5005 | // Baker's using a slow path (and also unpoison the loaded |
| 5006 | // reference, if heap poisoning is enabled). |
| 5007 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5008 | } else { |
| 5009 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5010 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5011 | // If read barriers are enabled, emit read barriers other than |
| 5012 | // Baker's using a slow path (and also unpoison the loaded |
| 5013 | // reference, if heap poisoning is enabled). |
| 5014 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5015 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5016 | } |
| 5017 | } |
| 5018 | break; |
| 5019 | } |
| 5020 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5021 | case Primitive::kPrimLong: { |
| 5022 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5023 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5024 | if (index.IsConstant()) { |
| 5025 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5026 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5028 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5030 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5031 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5032 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5033 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5034 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5035 | } |
| 5036 | break; |
| 5037 | } |
| 5038 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5039 | case Primitive::kPrimFloat: { |
| 5040 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5041 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5042 | if (index.IsConstant()) { |
| 5043 | __ movss(out, Address(obj, |
| 5044 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5045 | } else { |
| 5046 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5047 | } |
| 5048 | break; |
| 5049 | } |
| 5050 | |
| 5051 | case Primitive::kPrimDouble: { |
| 5052 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5053 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5054 | if (index.IsConstant()) { |
| 5055 | __ movsd(out, Address(obj, |
| 5056 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5057 | } else { |
| 5058 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5059 | } |
| 5060 | break; |
| 5061 | } |
| 5062 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5063 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5064 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5065 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5067 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5068 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5069 | // Potential implicit null checks, in the case of reference or |
| 5070 | // long arrays, are handled in the previous switch statement. |
| 5071 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5072 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5073 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | } |
| 5075 | |
| 5076 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5077 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5078 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5079 | bool needs_write_barrier = |
| 5080 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5081 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5082 | bool object_array_set_with_read_barrier = |
| 5083 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5084 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5085 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5086 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5087 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5088 | LocationSummary::kCallOnSlowPath : |
| 5089 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5090 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5091 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5092 | || (value_type == Primitive::kPrimByte); |
| 5093 | // We need the inputs to be different than the output in case of long operation. |
| 5094 | // In case of a byte operation, the register allocator does not support multiple |
| 5095 | // inputs that die at entry with one in a specific register. |
| 5096 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5097 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5098 | if (is_byte_type) { |
| 5099 | // Ensure the value is in a byte register. |
| 5100 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5101 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5102 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5103 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5104 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5105 | } |
| 5106 | if (needs_write_barrier) { |
| 5107 | // Temporary registers for the write barrier. |
| 5108 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5109 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5110 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5115 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5116 | Location array_loc = locations->InAt(0); |
| 5117 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5118 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5119 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5120 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5121 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5122 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5123 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5124 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5125 | bool needs_write_barrier = |
| 5126 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | |
| 5128 | switch (value_type) { |
| 5129 | case Primitive::kPrimBoolean: |
| 5130 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5131 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5132 | Address address = index.IsConstant() |
| 5133 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5134 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5135 | if (value.IsRegister()) { |
| 5136 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5137 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5138 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5139 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5140 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5141 | break; |
| 5142 | } |
| 5143 | |
| 5144 | case Primitive::kPrimShort: |
| 5145 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5146 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5147 | Address address = index.IsConstant() |
| 5148 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5149 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5150 | if (value.IsRegister()) { |
| 5151 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5152 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5153 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5154 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5155 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5156 | break; |
| 5157 | } |
| 5158 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5159 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5160 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5161 | Address address = index.IsConstant() |
| 5162 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5163 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5164 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5165 | if (!value.IsRegister()) { |
| 5166 | // Just setting null. |
| 5167 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5168 | DCHECK(value.IsConstant()) << value; |
| 5169 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5170 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5171 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5172 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5173 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5174 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5175 | |
| 5176 | DCHECK(needs_write_barrier); |
| 5177 | Register register_value = value.AsRegister<Register>(); |
| 5178 | NearLabel done, not_null, do_put; |
| 5179 | SlowPathCode* slow_path = nullptr; |
| 5180 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5181 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5182 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5183 | codegen_->AddSlowPath(slow_path); |
| 5184 | if (instruction->GetValueCanBeNull()) { |
| 5185 | __ testl(register_value, register_value); |
| 5186 | __ j(kNotEqual, ¬_null); |
| 5187 | __ movl(address, Immediate(0)); |
| 5188 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5189 | __ jmp(&done); |
| 5190 | __ Bind(¬_null); |
| 5191 | } |
| 5192 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5193 | if (kEmitCompilerReadBarrier) { |
| 5194 | // When read barriers are enabled, the type checking |
| 5195 | // instrumentation requires two read barriers: |
| 5196 | // |
| 5197 | // __ movl(temp2, temp); |
| 5198 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5199 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5200 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5201 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5202 | // |
| 5203 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5204 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5205 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5206 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5207 | // |
| 5208 | // __ cmpl(temp, temp2); |
| 5209 | // |
| 5210 | // However, the second read barrier may trash `temp`, as it |
| 5211 | // is a temporary register, and as such would not be saved |
| 5212 | // along with live registers before calling the runtime (nor |
| 5213 | // restored afterwards). So in this case, we bail out and |
| 5214 | // delegate the work to the array set slow path. |
| 5215 | // |
| 5216 | // TODO: Extend the register allocator to support a new |
| 5217 | // "(locally) live temp" location so as to avoid always |
| 5218 | // going into the slow path when read barriers are enabled. |
| 5219 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5220 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5221 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5222 | __ movl(temp, Address(array, class_offset)); |
| 5223 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5224 | __ MaybeUnpoisonHeapReference(temp); |
| 5225 | |
| 5226 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5227 | __ movl(temp, Address(temp, component_offset)); |
| 5228 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5229 | // nor the object reference in `register_value->klass`, as |
| 5230 | // we are comparing two poisoned references. |
| 5231 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5232 | |
| 5233 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5234 | __ j(kEqual, &do_put); |
| 5235 | // If heap poisoning is enabled, the `temp` reference has |
| 5236 | // not been unpoisoned yet; unpoison it now. |
| 5237 | __ MaybeUnpoisonHeapReference(temp); |
| 5238 | |
| 5239 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5240 | __ movl(temp, Address(temp, super_offset)); |
| 5241 | // If heap poisoning is enabled, no need to unpoison |
| 5242 | // `temp`, as we are comparing against null below. |
| 5243 | __ testl(temp, temp); |
| 5244 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5245 | __ Bind(&do_put); |
| 5246 | } else { |
| 5247 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5248 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | if (kPoisonHeapReferences) { |
| 5253 | __ movl(temp, register_value); |
| 5254 | __ PoisonHeapReference(temp); |
| 5255 | __ movl(address, temp); |
| 5256 | } else { |
| 5257 | __ movl(address, register_value); |
| 5258 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5259 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5260 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5261 | } |
| 5262 | |
| 5263 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5264 | codegen_->MarkGCCard( |
| 5265 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5266 | __ Bind(&done); |
| 5267 | |
| 5268 | if (slow_path != nullptr) { |
| 5269 | __ Bind(slow_path->GetExitLabel()); |
| 5270 | } |
| 5271 | |
| 5272 | break; |
| 5273 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5274 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5275 | case Primitive::kPrimInt: { |
| 5276 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5277 | Address address = index.IsConstant() |
| 5278 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5279 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5280 | if (value.IsRegister()) { |
| 5281 | __ movl(address, value.AsRegister<Register>()); |
| 5282 | } else { |
| 5283 | DCHECK(value.IsConstant()) << value; |
| 5284 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5285 | __ movl(address, Immediate(v)); |
| 5286 | } |
| 5287 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5288 | break; |
| 5289 | } |
| 5290 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5291 | case Primitive::kPrimLong: { |
| 5292 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5293 | if (index.IsConstant()) { |
| 5294 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5295 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5296 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5297 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5298 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5299 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5300 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5301 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5302 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5304 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5305 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5307 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5308 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5309 | value.AsRegisterPairLow<Register>()); |
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, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5312 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5313 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5314 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5315 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5316 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5317 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5318 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5319 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5320 | Immediate(High32Bits(val))); |
| 5321 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5322 | } |
| 5323 | break; |
| 5324 | } |
| 5325 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5326 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5327 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5328 | Address address = index.IsConstant() |
| 5329 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5330 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5331 | if (value.IsFpuRegister()) { |
| 5332 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5333 | } else { |
| 5334 | DCHECK(value.IsConstant()); |
| 5335 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5336 | __ movl(address, Immediate(v)); |
| 5337 | } |
| 5338 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5339 | break; |
| 5340 | } |
| 5341 | |
| 5342 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5343 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5344 | Address address = index.IsConstant() |
| 5345 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5346 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5347 | if (value.IsFpuRegister()) { |
| 5348 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5349 | } else { |
| 5350 | DCHECK(value.IsConstant()); |
| 5351 | Address address_hi = index.IsConstant() ? |
| 5352 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5353 | offset + kX86WordSize) : |
| 5354 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5355 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5356 | __ movl(address, Immediate(Low32Bits(v))); |
| 5357 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5358 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5359 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5360 | break; |
| 5361 | } |
| 5362 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5363 | case Primitive::kPrimVoid: |
| 5364 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5365 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5366 | } |
| 5367 | } |
| 5368 | |
| 5369 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5370 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5372 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | } |
| 5374 | |
| 5375 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5376 | LocationSummary* locations = instruction->GetLocations(); |
| 5377 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5378 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5379 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5380 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5381 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5385 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5386 | ? LocationSummary::kCallOnSlowPath |
| 5387 | : LocationSummary::kNoCall; |
| 5388 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5389 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5390 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5391 | if (instruction->HasUses()) { |
| 5392 | locations->SetOut(Location::SameAsFirstInput()); |
| 5393 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5397 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5398 | Location index_loc = locations->InAt(0); |
| 5399 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5400 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5401 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5402 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5403 | if (length_loc.IsConstant()) { |
| 5404 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5405 | if (index_loc.IsConstant()) { |
| 5406 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5407 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5408 | if (index < 0 || index >= length) { |
| 5409 | codegen_->AddSlowPath(slow_path); |
| 5410 | __ jmp(slow_path->GetEntryLabel()); |
| 5411 | } else { |
| 5412 | // Some optimization after BCE may have generated this, and we should not |
| 5413 | // generate a bounds check if it is a valid range. |
| 5414 | } |
| 5415 | return; |
| 5416 | } |
| 5417 | |
| 5418 | // We have to reverse the jump condition because the length is the constant. |
| 5419 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5420 | __ cmpl(index_reg, Immediate(length)); |
| 5421 | codegen_->AddSlowPath(slow_path); |
| 5422 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5423 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5424 | Register length = length_loc.AsRegister<Register>(); |
| 5425 | if (index_loc.IsConstant()) { |
| 5426 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5427 | __ cmpl(length, Immediate(value)); |
| 5428 | } else { |
| 5429 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5430 | } |
| 5431 | codegen_->AddSlowPath(slow_path); |
| 5432 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5433 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5434 | } |
| 5435 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5436 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5437 | temp->SetLocations(nullptr); |
| 5438 | } |
| 5439 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5440 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5441 | // Nothing to do, this is driven by the code generator. |
| 5442 | } |
| 5443 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5444 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5445 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5446 | } |
| 5447 | |
| 5448 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5449 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5450 | } |
| 5451 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5452 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5453 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5454 | } |
| 5455 | |
| 5456 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5457 | HBasicBlock* block = instruction->GetBlock(); |
| 5458 | if (block->GetLoopInformation() != nullptr) { |
| 5459 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5460 | // The back edge will generate the suspend check. |
| 5461 | return; |
| 5462 | } |
| 5463 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5464 | // The goto will generate the suspend check. |
| 5465 | return; |
| 5466 | } |
| 5467 | GenerateSuspendCheck(instruction, nullptr); |
| 5468 | } |
| 5469 | |
| 5470 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5471 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5472 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5473 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5474 | if (slow_path == nullptr) { |
| 5475 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5476 | instruction->SetSlowPath(slow_path); |
| 5477 | codegen_->AddSlowPath(slow_path); |
| 5478 | if (successor != nullptr) { |
| 5479 | DCHECK(successor->IsLoopHeader()); |
| 5480 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5481 | } |
| 5482 | } else { |
| 5483 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5484 | } |
| 5485 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5486 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5487 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5488 | if (successor == nullptr) { |
| 5489 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5490 | __ Bind(slow_path->GetReturnLabel()); |
| 5491 | } else { |
| 5492 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5493 | __ jmp(slow_path->GetEntryLabel()); |
| 5494 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5495 | } |
| 5496 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5497 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5498 | return codegen_->GetAssembler(); |
| 5499 | } |
| 5500 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5501 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5502 | ScratchRegisterScope ensure_scratch( |
| 5503 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5504 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5505 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5506 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5507 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5508 | } |
| 5509 | |
| 5510 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5511 | ScratchRegisterScope ensure_scratch( |
| 5512 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5513 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5514 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5515 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5516 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5517 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5518 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5522 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5523 | Location source = move->GetSource(); |
| 5524 | Location destination = move->GetDestination(); |
| 5525 | |
| 5526 | if (source.IsRegister()) { |
| 5527 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5528 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5529 | } else { |
| 5530 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5531 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5532 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5533 | } else if (source.IsFpuRegister()) { |
| 5534 | if (destination.IsFpuRegister()) { |
| 5535 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5536 | } else if (destination.IsStackSlot()) { |
| 5537 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5538 | } else { |
| 5539 | DCHECK(destination.IsDoubleStackSlot()); |
| 5540 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5541 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5542 | } else if (source.IsStackSlot()) { |
| 5543 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5544 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5545 | } else if (destination.IsFpuRegister()) { |
| 5546 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5547 | } else { |
| 5548 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5549 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5550 | } |
| 5551 | } else if (source.IsDoubleStackSlot()) { |
| 5552 | if (destination.IsFpuRegister()) { |
| 5553 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5554 | } else { |
| 5555 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5556 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5557 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5558 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5559 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5560 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5561 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5562 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5563 | if (value == 0) { |
| 5564 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5565 | } else { |
| 5566 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5567 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5568 | } else { |
| 5569 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5570 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5571 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5572 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5573 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5574 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5575 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5576 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5577 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5578 | if (value == 0) { |
| 5579 | // Easy handling of 0.0. |
| 5580 | __ xorps(dest, dest); |
| 5581 | } else { |
| 5582 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5583 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5584 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5585 | __ movl(temp, Immediate(value)); |
| 5586 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5587 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5588 | } else { |
| 5589 | DCHECK(destination.IsStackSlot()) << destination; |
| 5590 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5591 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5592 | } else if (constant->IsLongConstant()) { |
| 5593 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5594 | int32_t low_value = Low32Bits(value); |
| 5595 | int32_t high_value = High32Bits(value); |
| 5596 | Immediate low(low_value); |
| 5597 | Immediate high(high_value); |
| 5598 | if (destination.IsDoubleStackSlot()) { |
| 5599 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5600 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5601 | } else { |
| 5602 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5603 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5604 | } |
| 5605 | } else { |
| 5606 | DCHECK(constant->IsDoubleConstant()); |
| 5607 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5608 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5609 | int32_t low_value = Low32Bits(value); |
| 5610 | int32_t high_value = High32Bits(value); |
| 5611 | Immediate low(low_value); |
| 5612 | Immediate high(high_value); |
| 5613 | if (destination.IsFpuRegister()) { |
| 5614 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5615 | if (value == 0) { |
| 5616 | // Easy handling of 0.0. |
| 5617 | __ xorpd(dest, dest); |
| 5618 | } else { |
| 5619 | __ pushl(high); |
| 5620 | __ pushl(low); |
| 5621 | __ movsd(dest, Address(ESP, 0)); |
| 5622 | __ addl(ESP, Immediate(8)); |
| 5623 | } |
| 5624 | } else { |
| 5625 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5626 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5627 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5628 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5629 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5630 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5631 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5632 | } |
| 5633 | } |
| 5634 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5635 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5636 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5637 | ScratchRegisterScope ensure_scratch( |
| 5638 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5639 | |
| 5640 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5641 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5642 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5643 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5644 | } |
| 5645 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5646 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5647 | ScratchRegisterScope ensure_scratch( |
| 5648 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5649 | |
| 5650 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5651 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5652 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5653 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5654 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5655 | } |
| 5656 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5657 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5658 | ScratchRegisterScope ensure_scratch1( |
| 5659 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5660 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5661 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5662 | ScratchRegisterScope ensure_scratch2( |
| 5663 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5664 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5665 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5666 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5667 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5668 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5669 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5670 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5674 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5675 | Location source = move->GetSource(); |
| 5676 | Location destination = move->GetDestination(); |
| 5677 | |
| 5678 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5679 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5680 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5681 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5682 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5683 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5684 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5685 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5686 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5687 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5688 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5689 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5690 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5691 | // Use XOR Swap algorithm to avoid a temporary. |
| 5692 | DCHECK_NE(source.reg(), destination.reg()); |
| 5693 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5694 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5695 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5696 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5697 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5698 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5699 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5700 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5701 | // Take advantage of the 16 bytes in the XMM register. |
| 5702 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5703 | Address stack(ESP, destination.GetStackIndex()); |
| 5704 | // Load the double into the high doubleword. |
| 5705 | __ movhpd(reg, stack); |
| 5706 | |
| 5707 | // Store the low double into the destination. |
| 5708 | __ movsd(stack, reg); |
| 5709 | |
| 5710 | // Move the high double to the low double. |
| 5711 | __ psrldq(reg, Immediate(8)); |
| 5712 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5713 | // Take advantage of the 16 bytes in the XMM register. |
| 5714 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5715 | Address stack(ESP, source.GetStackIndex()); |
| 5716 | // Load the double into the high doubleword. |
| 5717 | __ movhpd(reg, stack); |
| 5718 | |
| 5719 | // Store the low double into the destination. |
| 5720 | __ movsd(stack, reg); |
| 5721 | |
| 5722 | // Move the high double to the low double. |
| 5723 | __ psrldq(reg, Immediate(8)); |
| 5724 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5725 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5726 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5727 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5728 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5729 | } |
| 5730 | } |
| 5731 | |
| 5732 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5733 | __ pushl(static_cast<Register>(reg)); |
| 5734 | } |
| 5735 | |
| 5736 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5737 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5738 | } |
| 5739 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5740 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5741 | InvokeRuntimeCallingConvention calling_convention; |
| 5742 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5743 | cls, |
| 5744 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5745 | Location::RegisterLocation(EAX), |
| 5746 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5750 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5751 | if (cls->NeedsAccessCheck()) { |
| 5752 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5753 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5754 | cls, |
| 5755 | cls->GetDexPc(), |
| 5756 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5757 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5758 | return; |
| 5759 | } |
| 5760 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5761 | Location out_loc = locations->Out(); |
| 5762 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5763 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5764 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5765 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5766 | DCHECK(!cls->CanCallRuntime()); |
| 5767 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5768 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5769 | GenerateGcRootFieldLoad( |
| 5770 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5771 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5772 | // /* GcRoot<mirror::Class>[] */ out = |
| 5773 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5774 | __ movl(out, Address(current_method, |
| 5775 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5776 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5777 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5778 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5779 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5780 | DCHECK(cls->CanCallRuntime()); |
| 5781 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5782 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5783 | codegen_->AddSlowPath(slow_path); |
| 5784 | |
| 5785 | if (!cls->IsInDexCache()) { |
| 5786 | __ testl(out, out); |
| 5787 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5788 | } |
| 5789 | |
| 5790 | if (cls->MustGenerateClinitCheck()) { |
| 5791 | GenerateClassInitializationCheck(slow_path, out); |
| 5792 | } else { |
| 5793 | __ Bind(slow_path->GetExitLabel()); |
| 5794 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5795 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5800 | LocationSummary* locations = |
| 5801 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5802 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5803 | if (check->HasUses()) { |
| 5804 | locations->SetOut(Location::SameAsFirstInput()); |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5809 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5810 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5811 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5812 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5813 | GenerateClassInitializationCheck(slow_path, |
| 5814 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5815 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5816 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5817 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5818 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5819 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5820 | Immediate(mirror::Class::kStatusInitialized)); |
| 5821 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5822 | __ Bind(slow_path->GetExitLabel()); |
| 5823 | // No need for memory fence, thanks to the X86 memory model. |
| 5824 | } |
| 5825 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5826 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5827 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5828 | ? LocationSummary::kCallOnSlowPath |
| 5829 | : LocationSummary::kNoCall; |
| 5830 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5831 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5832 | locations->SetOut(Location::RequiresRegister()); |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5836 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5837 | Location out_loc = locations->Out(); |
| 5838 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5839 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5840 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5841 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5842 | GenerateGcRootFieldLoad( |
| 5843 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5844 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5845 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5846 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5847 | GenerateGcRootFieldLoad( |
| 5848 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5849 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5850 | if (!load->IsInDexCache()) { |
| 5851 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5852 | codegen_->AddSlowPath(slow_path); |
| 5853 | __ testl(out, out); |
| 5854 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5855 | __ Bind(slow_path->GetExitLabel()); |
| 5856 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5857 | } |
| 5858 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5859 | static Address GetExceptionTlsAddress() { |
| 5860 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5861 | } |
| 5862 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5863 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5864 | LocationSummary* locations = |
| 5865 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5866 | locations->SetOut(Location::RequiresRegister()); |
| 5867 | } |
| 5868 | |
| 5869 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5870 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5871 | } |
| 5872 | |
| 5873 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5874 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5875 | } |
| 5876 | |
| 5877 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5878 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
| 5881 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5882 | LocationSummary* locations = |
| 5883 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5884 | InvokeRuntimeCallingConvention calling_convention; |
| 5885 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5886 | } |
| 5887 | |
| 5888 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5889 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5890 | instruction, |
| 5891 | instruction->GetDexPc(), |
| 5892 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5893 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5894 | } |
| 5895 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5896 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5897 | return kEmitCompilerReadBarrier && |
| 5898 | (kUseBakerReadBarrier || |
| 5899 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5900 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5901 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5902 | } |
| 5903 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5904 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5905 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5906 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5907 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5908 | case TypeCheckKind::kExactCheck: |
| 5909 | case TypeCheckKind::kAbstractClassCheck: |
| 5910 | case TypeCheckKind::kClassHierarchyCheck: |
| 5911 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5912 | call_kind = |
| 5913 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5914 | break; |
| 5915 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5916 | case TypeCheckKind::kUnresolvedCheck: |
| 5917 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5918 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5919 | break; |
| 5920 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5921 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5922 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5924 | locations->SetInAt(1, Location::Any()); |
| 5925 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5926 | locations->SetOut(Location::RequiresRegister()); |
| 5927 | // When read barriers are enabled, we need a temporary register for |
| 5928 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5929 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5930 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5931 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5934 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5935 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5936 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5937 | Location obj_loc = locations->InAt(0); |
| 5938 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5939 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5940 | Location out_loc = locations->Out(); |
| 5941 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5942 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5943 | locations->GetTemp(0) : |
| 5944 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5945 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5946 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5947 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5948 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5949 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5950 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5951 | |
| 5952 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5953 | // Avoid null check if we know obj is not null. |
| 5954 | if (instruction->MustDoNullCheck()) { |
| 5955 | __ testl(obj, obj); |
| 5956 | __ j(kEqual, &zero); |
| 5957 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5958 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5959 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5960 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5961 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5962 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5963 | case TypeCheckKind::kExactCheck: { |
| 5964 | if (cls.IsRegister()) { |
| 5965 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5966 | } else { |
| 5967 | DCHECK(cls.IsStackSlot()) << cls; |
| 5968 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5969 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5970 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5971 | // Classes must be equal for the instanceof to succeed. |
| 5972 | __ j(kNotEqual, &zero); |
| 5973 | __ movl(out, Immediate(1)); |
| 5974 | __ jmp(&done); |
| 5975 | break; |
| 5976 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5977 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5978 | case TypeCheckKind::kAbstractClassCheck: { |
| 5979 | // If the class is abstract, we eagerly fetch the super class of the |
| 5980 | // object to avoid doing a comparison we know will fail. |
| 5981 | NearLabel loop; |
| 5982 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5983 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5984 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5985 | __ testl(out, out); |
| 5986 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5987 | __ j(kEqual, &done); |
| 5988 | if (cls.IsRegister()) { |
| 5989 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5990 | } else { |
| 5991 | DCHECK(cls.IsStackSlot()) << cls; |
| 5992 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5993 | } |
| 5994 | __ j(kNotEqual, &loop); |
| 5995 | __ movl(out, Immediate(1)); |
| 5996 | if (zero.IsLinked()) { |
| 5997 | __ jmp(&done); |
| 5998 | } |
| 5999 | break; |
| 6000 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6001 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6002 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6003 | // Walk over the class hierarchy to find a match. |
| 6004 | NearLabel loop, success; |
| 6005 | __ Bind(&loop); |
| 6006 | if (cls.IsRegister()) { |
| 6007 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6008 | } else { |
| 6009 | DCHECK(cls.IsStackSlot()) << cls; |
| 6010 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6011 | } |
| 6012 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6013 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6014 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6015 | __ testl(out, out); |
| 6016 | __ j(kNotEqual, &loop); |
| 6017 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6018 | __ jmp(&done); |
| 6019 | __ Bind(&success); |
| 6020 | __ movl(out, Immediate(1)); |
| 6021 | if (zero.IsLinked()) { |
| 6022 | __ jmp(&done); |
| 6023 | } |
| 6024 | break; |
| 6025 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6026 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6027 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6028 | // Do an exact check. |
| 6029 | NearLabel exact_check; |
| 6030 | if (cls.IsRegister()) { |
| 6031 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6032 | } else { |
| 6033 | DCHECK(cls.IsStackSlot()) << cls; |
| 6034 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6035 | } |
| 6036 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6037 | // 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] | 6038 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6039 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6040 | __ testl(out, out); |
| 6041 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6042 | __ j(kEqual, &done); |
| 6043 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6044 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6045 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6046 | __ movl(out, Immediate(1)); |
| 6047 | __ jmp(&done); |
| 6048 | break; |
| 6049 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6050 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6051 | case TypeCheckKind::kArrayCheck: { |
| 6052 | if (cls.IsRegister()) { |
| 6053 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6054 | } else { |
| 6055 | DCHECK(cls.IsStackSlot()) << cls; |
| 6056 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6057 | } |
| 6058 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6059 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6060 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6061 | codegen_->AddSlowPath(slow_path); |
| 6062 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6063 | __ movl(out, Immediate(1)); |
| 6064 | if (zero.IsLinked()) { |
| 6065 | __ jmp(&done); |
| 6066 | } |
| 6067 | break; |
| 6068 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6069 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6070 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6071 | case TypeCheckKind::kInterfaceCheck: { |
| 6072 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6073 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6074 | // cases. |
| 6075 | // |
| 6076 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6077 | // entry point without resorting to a type checking slow path |
| 6078 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6079 | // require to assign fixed registers for the inputs of this |
| 6080 | // HInstanceOf instruction (following the runtime calling |
| 6081 | // convention), which might be cluttered by the potential first |
| 6082 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6083 | // |
| 6084 | // TODO: Introduce a new runtime entry point taking the object |
| 6085 | // to test (instead of its class) as argument, and let it deal |
| 6086 | // with the read barrier issues. This will let us refactor this |
| 6087 | // case of the `switch` code as it was previously (with a direct |
| 6088 | // call to the runtime not using a type checking slow path). |
| 6089 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6090 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6091 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6092 | /* is_fatal */ false); |
| 6093 | codegen_->AddSlowPath(slow_path); |
| 6094 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6095 | if (zero.IsLinked()) { |
| 6096 | __ jmp(&done); |
| 6097 | } |
| 6098 | break; |
| 6099 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6102 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6103 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6104 | __ xorl(out, out); |
| 6105 | } |
| 6106 | |
| 6107 | if (done.IsLinked()) { |
| 6108 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6109 | } |
| 6110 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6111 | if (slow_path != nullptr) { |
| 6112 | __ Bind(slow_path->GetExitLabel()); |
| 6113 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6114 | } |
| 6115 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6116 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6117 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6118 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6119 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6120 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6121 | case TypeCheckKind::kExactCheck: |
| 6122 | case TypeCheckKind::kAbstractClassCheck: |
| 6123 | case TypeCheckKind::kClassHierarchyCheck: |
| 6124 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6125 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6126 | LocationSummary::kCallOnSlowPath : |
| 6127 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6128 | break; |
| 6129 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6130 | case TypeCheckKind::kUnresolvedCheck: |
| 6131 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6132 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6133 | break; |
| 6134 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6135 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6136 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6137 | locations->SetInAt(1, Location::Any()); |
| 6138 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6139 | locations->AddTemp(Location::RequiresRegister()); |
| 6140 | // When read barriers are enabled, we need an additional temporary |
| 6141 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6142 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6144 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6148 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6149 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6150 | Location obj_loc = locations->InAt(0); |
| 6151 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6152 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6153 | Location temp_loc = locations->GetTemp(0); |
| 6154 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6155 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6156 | locations->GetTemp(1) : |
| 6157 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6159 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6160 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6161 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6162 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6163 | bool is_type_check_slow_path_fatal = |
| 6164 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6165 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6166 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6167 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6168 | !instruction->CanThrowIntoCatchBlock(); |
| 6169 | SlowPathCode* type_check_slow_path = |
| 6170 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6171 | is_type_check_slow_path_fatal); |
| 6172 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6173 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6174 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6175 | // Avoid null check if we know obj is not null. |
| 6176 | if (instruction->MustDoNullCheck()) { |
| 6177 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6178 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6179 | } |
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 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6182 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6184 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6185 | case TypeCheckKind::kExactCheck: |
| 6186 | case TypeCheckKind::kArrayCheck: { |
| 6187 | if (cls.IsRegister()) { |
| 6188 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6189 | } else { |
| 6190 | DCHECK(cls.IsStackSlot()) << cls; |
| 6191 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6192 | } |
| 6193 | // Jump to slow path for throwing the exception or doing a |
| 6194 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6195 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6196 | break; |
| 6197 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6198 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6199 | case TypeCheckKind::kAbstractClassCheck: { |
| 6200 | // If the class is abstract, we eagerly fetch the super class of the |
| 6201 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6202 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6204 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6205 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6206 | |
| 6207 | // If the class reference currently in `temp` is not null, jump |
| 6208 | // to the `compare_classes` label to compare it with the checked |
| 6209 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | __ j(kNotEqual, &compare_classes); |
| 6212 | // Otherwise, jump to the slow path to throw the exception. |
| 6213 | // |
| 6214 | // But before, move back the object's class into `temp` before |
| 6215 | // going into the slow path, as it has been overwritten in the |
| 6216 | // meantime. |
| 6217 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6218 | GenerateReferenceLoadTwoRegisters( |
| 6219 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6220 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6221 | |
| 6222 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6223 | if (cls.IsRegister()) { |
| 6224 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6225 | } else { |
| 6226 | DCHECK(cls.IsStackSlot()) << cls; |
| 6227 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6228 | } |
| 6229 | __ j(kNotEqual, &loop); |
| 6230 | break; |
| 6231 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6232 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6233 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6234 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6235 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6236 | __ Bind(&loop); |
| 6237 | if (cls.IsRegister()) { |
| 6238 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6239 | } else { |
| 6240 | DCHECK(cls.IsStackSlot()) << cls; |
| 6241 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6242 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6243 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6244 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6245 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6246 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6247 | |
| 6248 | // If the class reference currently in `temp` is not null, jump |
| 6249 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6250 | __ testl(temp, temp); |
| 6251 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6252 | // Otherwise, jump to the slow path to throw the exception. |
| 6253 | // |
| 6254 | // But before, move back the object's class into `temp` before |
| 6255 | // going into the slow path, as it has been overwritten in the |
| 6256 | // meantime. |
| 6257 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6258 | GenerateReferenceLoadTwoRegisters( |
| 6259 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6260 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6261 | break; |
| 6262 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6263 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6264 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6265 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6266 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6267 | if (cls.IsRegister()) { |
| 6268 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6269 | } else { |
| 6270 | DCHECK(cls.IsStackSlot()) << cls; |
| 6271 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6272 | } |
| 6273 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | |
| 6275 | // 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] | 6276 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6277 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6278 | |
| 6279 | // If the component type is not null (i.e. the object is indeed |
| 6280 | // an array), jump to label `check_non_primitive_component_type` |
| 6281 | // to further check that this component type is not a primitive |
| 6282 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6283 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6284 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6285 | // Otherwise, jump to the slow path to throw the exception. |
| 6286 | // |
| 6287 | // But before, move back the object's class into `temp` before |
| 6288 | // going into the slow path, as it has been overwritten in the |
| 6289 | // meantime. |
| 6290 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6291 | GenerateReferenceLoadTwoRegisters( |
| 6292 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6293 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6294 | |
| 6295 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6296 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6297 | __ j(kEqual, &done); |
| 6298 | // Same comment as above regarding `temp` and the slow path. |
| 6299 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6300 | GenerateReferenceLoadTwoRegisters( |
| 6301 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6303 | break; |
| 6304 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6305 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6306 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6307 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6308 | // We always go into the type check slow path for the unresolved |
| 6309 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6310 | // |
| 6311 | // We cannot directly call the CheckCast runtime entry point |
| 6312 | // without resorting to a type checking slow path here (i.e. by |
| 6313 | // calling InvokeRuntime directly), as it would require to |
| 6314 | // assign fixed registers for the inputs of this HInstanceOf |
| 6315 | // instruction (following the runtime calling convention), which |
| 6316 | // might be cluttered by the potential first read barrier |
| 6317 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6318 | // |
| 6319 | // TODO: Introduce a new runtime entry point taking the object |
| 6320 | // to test (instead of its class) as argument, and let it deal |
| 6321 | // with the read barrier issues. This will let us refactor this |
| 6322 | // case of the `switch` code as it was previously (with a direct |
| 6323 | // call to the runtime not using a type checking slow path). |
| 6324 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6325 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6326 | break; |
| 6327 | } |
| 6328 | __ Bind(&done); |
| 6329 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6330 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6331 | } |
| 6332 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6333 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6334 | LocationSummary* locations = |
| 6335 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6336 | InvokeRuntimeCallingConvention calling_convention; |
| 6337 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6338 | } |
| 6339 | |
| 6340 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6341 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6342 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6343 | instruction, |
| 6344 | instruction->GetDexPc(), |
| 6345 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6346 | if (instruction->IsEnter()) { |
| 6347 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6348 | } else { |
| 6349 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6350 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6351 | } |
| 6352 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6353 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6354 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6355 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6356 | |
| 6357 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6358 | LocationSummary* locations = |
| 6359 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6360 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6361 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6362 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6363 | locations->SetInAt(1, Location::Any()); |
| 6364 | locations->SetOut(Location::SameAsFirstInput()); |
| 6365 | } |
| 6366 | |
| 6367 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6368 | HandleBitwiseOperation(instruction); |
| 6369 | } |
| 6370 | |
| 6371 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6372 | HandleBitwiseOperation(instruction); |
| 6373 | } |
| 6374 | |
| 6375 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6376 | HandleBitwiseOperation(instruction); |
| 6377 | } |
| 6378 | |
| 6379 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6380 | LocationSummary* locations = instruction->GetLocations(); |
| 6381 | Location first = locations->InAt(0); |
| 6382 | Location second = locations->InAt(1); |
| 6383 | DCHECK(first.Equals(locations->Out())); |
| 6384 | |
| 6385 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6386 | if (second.IsRegister()) { |
| 6387 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6388 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6389 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6390 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6391 | } else { |
| 6392 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6393 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6394 | } |
| 6395 | } else if (second.IsConstant()) { |
| 6396 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6397 | __ andl(first.AsRegister<Register>(), |
| 6398 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6399 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6400 | __ orl(first.AsRegister<Register>(), |
| 6401 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6402 | } else { |
| 6403 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6404 | __ xorl(first.AsRegister<Register>(), |
| 6405 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6406 | } |
| 6407 | } else { |
| 6408 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6409 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6410 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6411 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6412 | } else { |
| 6413 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6414 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6415 | } |
| 6416 | } |
| 6417 | } else { |
| 6418 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6419 | if (second.IsRegisterPair()) { |
| 6420 | if (instruction->IsAnd()) { |
| 6421 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6422 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6423 | } else if (instruction->IsOr()) { |
| 6424 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6425 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6426 | } else { |
| 6427 | DCHECK(instruction->IsXor()); |
| 6428 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6429 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6430 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6431 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6432 | if (instruction->IsAnd()) { |
| 6433 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6434 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6435 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6436 | } else if (instruction->IsOr()) { |
| 6437 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6438 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6439 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6440 | } else { |
| 6441 | DCHECK(instruction->IsXor()); |
| 6442 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6443 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6444 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6445 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6446 | } else { |
| 6447 | DCHECK(second.IsConstant()) << second; |
| 6448 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6449 | int32_t low_value = Low32Bits(value); |
| 6450 | int32_t high_value = High32Bits(value); |
| 6451 | Immediate low(low_value); |
| 6452 | Immediate high(high_value); |
| 6453 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6454 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6455 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6456 | if (low_value == 0) { |
| 6457 | __ xorl(first_low, first_low); |
| 6458 | } else if (low_value != -1) { |
| 6459 | __ andl(first_low, low); |
| 6460 | } |
| 6461 | if (high_value == 0) { |
| 6462 | __ xorl(first_high, first_high); |
| 6463 | } else if (high_value != -1) { |
| 6464 | __ andl(first_high, high); |
| 6465 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6466 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6467 | if (low_value != 0) { |
| 6468 | __ orl(first_low, low); |
| 6469 | } |
| 6470 | if (high_value != 0) { |
| 6471 | __ orl(first_high, high); |
| 6472 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6473 | } else { |
| 6474 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6475 | if (low_value != 0) { |
| 6476 | __ xorl(first_low, low); |
| 6477 | } |
| 6478 | if (high_value != 0) { |
| 6479 | __ xorl(first_high, high); |
| 6480 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6481 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6482 | } |
| 6483 | } |
| 6484 | } |
| 6485 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6486 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6487 | Location out, |
| 6488 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6489 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6490 | Register out_reg = out.AsRegister<Register>(); |
| 6491 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6492 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6493 | if (kUseBakerReadBarrier) { |
| 6494 | // Load with fast path based Baker's read barrier. |
| 6495 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6496 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6497 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6498 | } else { |
| 6499 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6500 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6501 | // in the following move operation, as we will need it for the |
| 6502 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6503 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6504 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6505 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6506 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6507 | } |
| 6508 | } else { |
| 6509 | // Plain load with no read barrier. |
| 6510 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6511 | __ movl(out_reg, Address(out_reg, offset)); |
| 6512 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6517 | Location out, |
| 6518 | Location obj, |
| 6519 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6520 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6521 | Register out_reg = out.AsRegister<Register>(); |
| 6522 | Register obj_reg = obj.AsRegister<Register>(); |
| 6523 | if (kEmitCompilerReadBarrier) { |
| 6524 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6525 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6526 | // Load with fast path based Baker's read barrier. |
| 6527 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6528 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6529 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6530 | } else { |
| 6531 | // Load with slow path based read barrier. |
| 6532 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6533 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6534 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6535 | } |
| 6536 | } else { |
| 6537 | // Plain load with no read barrier. |
| 6538 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6539 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6540 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6541 | } |
| 6542 | } |
| 6543 | |
| 6544 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6545 | Location root, |
| 6546 | Register obj, |
| 6547 | uint32_t offset) { |
| 6548 | Register root_reg = root.AsRegister<Register>(); |
| 6549 | if (kEmitCompilerReadBarrier) { |
| 6550 | if (kUseBakerReadBarrier) { |
| 6551 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6552 | // Baker's read barrier are used: |
| 6553 | // |
| 6554 | // root = obj.field; |
| 6555 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6556 | // root = ReadBarrier::Mark(root) |
| 6557 | // } |
| 6558 | |
| 6559 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6560 | __ movl(root_reg, Address(obj, offset)); |
| 6561 | static_assert( |
| 6562 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6563 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6564 | "have different sizes."); |
| 6565 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6566 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6567 | "have different sizes."); |
| 6568 | |
| 6569 | // Slow path used to mark the GC root `root`. |
| 6570 | SlowPathCode* slow_path = |
| 6571 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6572 | codegen_->AddSlowPath(slow_path); |
| 6573 | |
| 6574 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6575 | Immediate(0)); |
| 6576 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6577 | __ Bind(slow_path->GetExitLabel()); |
| 6578 | } else { |
| 6579 | // GC root loaded through a slow path for read barriers other |
| 6580 | // than Baker's. |
| 6581 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6582 | __ leal(root_reg, Address(obj, offset)); |
| 6583 | // /* mirror::Object* */ root = root->Read() |
| 6584 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6585 | } |
| 6586 | } else { |
| 6587 | // Plain GC root load with no read barrier. |
| 6588 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6589 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6590 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6591 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6596 | Location ref, |
| 6597 | Register obj, |
| 6598 | uint32_t offset, |
| 6599 | Location temp, |
| 6600 | bool needs_null_check) { |
| 6601 | DCHECK(kEmitCompilerReadBarrier); |
| 6602 | DCHECK(kUseBakerReadBarrier); |
| 6603 | |
| 6604 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6605 | Address src(obj, offset); |
| 6606 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6607 | } |
| 6608 | |
| 6609 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6610 | Location ref, |
| 6611 | Register obj, |
| 6612 | uint32_t data_offset, |
| 6613 | Location index, |
| 6614 | Location temp, |
| 6615 | bool needs_null_check) { |
| 6616 | DCHECK(kEmitCompilerReadBarrier); |
| 6617 | DCHECK(kUseBakerReadBarrier); |
| 6618 | |
| 6619 | // /* HeapReference<Object> */ ref = |
| 6620 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6621 | Address src = index.IsConstant() ? |
| 6622 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6623 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6624 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6625 | } |
| 6626 | |
| 6627 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6628 | Location ref, |
| 6629 | Register obj, |
| 6630 | const Address& src, |
| 6631 | Location temp, |
| 6632 | bool needs_null_check) { |
| 6633 | DCHECK(kEmitCompilerReadBarrier); |
| 6634 | DCHECK(kUseBakerReadBarrier); |
| 6635 | |
| 6636 | // In slow path based read barriers, the read barrier call is |
| 6637 | // inserted after the original load. However, in fast path based |
| 6638 | // Baker's read barriers, we need to perform the load of |
| 6639 | // mirror::Object::monitor_ *before* the original reference load. |
| 6640 | // This load-load ordering is required by the read barrier. |
| 6641 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6642 | // |
| 6643 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6644 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6645 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6646 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6647 | // if (is_gray) { |
| 6648 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6649 | // } |
| 6650 | // |
| 6651 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6652 | // slightly more complex as: |
| 6653 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6654 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6655 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6656 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6657 | // - it performs additional checks that we do not do here for |
| 6658 | // performance reasons. |
| 6659 | |
| 6660 | Register ref_reg = ref.AsRegister<Register>(); |
| 6661 | Register temp_reg = temp.AsRegister<Register>(); |
| 6662 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6663 | |
| 6664 | // /* int32_t */ monitor = obj->monitor_ |
| 6665 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6666 | if (needs_null_check) { |
| 6667 | MaybeRecordImplicitNullCheck(instruction); |
| 6668 | } |
| 6669 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6670 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6671 | "art::LockWord and int32_t have different sizes."); |
| 6672 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6673 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6674 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6675 | static_assert( |
| 6676 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6677 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6678 | |
| 6679 | // Load fence to prevent load-load reordering. |
| 6680 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6681 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6682 | |
| 6683 | // The actual reference load. |
| 6684 | // /* HeapReference<Object> */ ref = *src |
| 6685 | __ movl(ref_reg, src); |
| 6686 | |
| 6687 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6688 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6689 | |
| 6690 | // Slow path used to mark the object `ref` when it is gray. |
| 6691 | SlowPathCode* slow_path = |
| 6692 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6693 | AddSlowPath(slow_path); |
| 6694 | |
| 6695 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6696 | // ref = ReadBarrier::Mark(ref); |
| 6697 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6698 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6699 | __ Bind(slow_path->GetExitLabel()); |
| 6700 | } |
| 6701 | |
| 6702 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6703 | Location out, |
| 6704 | Location ref, |
| 6705 | Location obj, |
| 6706 | uint32_t offset, |
| 6707 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6708 | DCHECK(kEmitCompilerReadBarrier); |
| 6709 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6710 | // Insert a slow path based read barrier *after* the reference load. |
| 6711 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6713 | // reference will be carried out by the runtime within the slow |
| 6714 | // path. |
| 6715 | // |
| 6716 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6717 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6718 | // not used by the artReadBarrierSlow entry point. |
| 6719 | // |
| 6720 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6721 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6722 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6723 | AddSlowPath(slow_path); |
| 6724 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6725 | __ jmp(slow_path->GetEntryLabel()); |
| 6726 | __ Bind(slow_path->GetExitLabel()); |
| 6727 | } |
| 6728 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6729 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6730 | Location out, |
| 6731 | Location ref, |
| 6732 | Location obj, |
| 6733 | uint32_t offset, |
| 6734 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6735 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6736 | // Baker's read barriers shall be handled by the fast path |
| 6737 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6738 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6740 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6741 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6742 | } else if (kPoisonHeapReferences) { |
| 6743 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6744 | } |
| 6745 | } |
| 6746 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6747 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6748 | Location out, |
| 6749 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6750 | DCHECK(kEmitCompilerReadBarrier); |
| 6751 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6752 | // Insert a slow path based read barrier *after* the GC root load. |
| 6753 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6754 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6755 | // not need to do anything special for this here. |
| 6756 | SlowPathCode* slow_path = |
| 6757 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6758 | AddSlowPath(slow_path); |
| 6759 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6760 | __ jmp(slow_path->GetEntryLabel()); |
| 6761 | __ Bind(slow_path->GetExitLabel()); |
| 6762 | } |
| 6763 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6764 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6765 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6766 | LOG(FATAL) << "Unreachable"; |
| 6767 | } |
| 6768 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6769 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6770 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6771 | LOG(FATAL) << "Unreachable"; |
| 6772 | } |
| 6773 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6774 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6775 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6776 | LocationSummary* locations = |
| 6777 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6778 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6779 | } |
| 6780 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6781 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6782 | int32_t lower_bound, |
| 6783 | uint32_t num_entries, |
| 6784 | HBasicBlock* switch_block, |
| 6785 | HBasicBlock* default_block) { |
| 6786 | // Figure out the correct compare values and jump conditions. |
| 6787 | // Handle the first compare/branch as a special case because it might |
| 6788 | // jump to the default case. |
| 6789 | DCHECK_GT(num_entries, 2u); |
| 6790 | Condition first_condition; |
| 6791 | uint32_t index; |
| 6792 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6793 | if (lower_bound != 0) { |
| 6794 | first_condition = kLess; |
| 6795 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6796 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6797 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6798 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6799 | index = 1; |
| 6800 | } else { |
| 6801 | // Handle all the compare/jumps below. |
| 6802 | first_condition = kBelow; |
| 6803 | index = 0; |
| 6804 | } |
| 6805 | |
| 6806 | // Handle the rest of the compare/jumps. |
| 6807 | for (; index + 1 < num_entries; index += 2) { |
| 6808 | int32_t compare_to_value = lower_bound + index + 1; |
| 6809 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6810 | // Jump to successors[index] if value < case_value[index]. |
| 6811 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6812 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6813 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6814 | } |
| 6815 | |
| 6816 | if (index != num_entries) { |
| 6817 | // There are an odd number of entries. Handle the last one. |
| 6818 | DCHECK_EQ(index + 1, num_entries); |
| 6819 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6820 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6824 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6825 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6826 | } |
| 6827 | } |
| 6828 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6829 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6830 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6831 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6832 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6833 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6834 | |
| 6835 | GenPackedSwitchWithCompares(value_reg, |
| 6836 | lower_bound, |
| 6837 | num_entries, |
| 6838 | switch_instr->GetBlock(), |
| 6839 | switch_instr->GetDefaultBlock()); |
| 6840 | } |
| 6841 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6842 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6843 | LocationSummary* locations = |
| 6844 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6846 | |
| 6847 | // Constant area pointer. |
| 6848 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6849 | |
| 6850 | // And the temporary we need. |
| 6851 | locations->AddTemp(Location::RequiresRegister()); |
| 6852 | } |
| 6853 | |
| 6854 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6855 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6856 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6857 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6858 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6859 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6860 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6861 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6862 | GenPackedSwitchWithCompares(value_reg, |
| 6863 | lower_bound, |
| 6864 | num_entries, |
| 6865 | switch_instr->GetBlock(), |
| 6866 | default_block); |
| 6867 | return; |
| 6868 | } |
| 6869 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6870 | // Optimizing has a jump area. |
| 6871 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6872 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6873 | |
| 6874 | // Remove the bias, if needed. |
| 6875 | if (lower_bound != 0) { |
| 6876 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6877 | value_reg = temp_reg; |
| 6878 | } |
| 6879 | |
| 6880 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6881 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6882 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6883 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6884 | |
| 6885 | // We are in the range of the table. |
| 6886 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6887 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6888 | |
| 6889 | // Compute the actual target address by adding in constant_area. |
| 6890 | __ addl(temp_reg, constant_area); |
| 6891 | |
| 6892 | // And jump. |
| 6893 | __ jmp(temp_reg); |
| 6894 | } |
| 6895 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6896 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6897 | HX86ComputeBaseMethodAddress* insn) { |
| 6898 | LocationSummary* locations = |
| 6899 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6900 | locations->SetOut(Location::RequiresRegister()); |
| 6901 | } |
| 6902 | |
| 6903 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6904 | HX86ComputeBaseMethodAddress* insn) { |
| 6905 | LocationSummary* locations = insn->GetLocations(); |
| 6906 | Register reg = locations->Out().AsRegister<Register>(); |
| 6907 | |
| 6908 | // Generate call to next instruction. |
| 6909 | Label next_instruction; |
| 6910 | __ call(&next_instruction); |
| 6911 | __ Bind(&next_instruction); |
| 6912 | |
| 6913 | // Remember this offset for later use with constant area. |
| 6914 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6915 | |
| 6916 | // Grab the return address off the stack. |
| 6917 | __ popl(reg); |
| 6918 | } |
| 6919 | |
| 6920 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6921 | HX86LoadFromConstantTable* insn) { |
| 6922 | LocationSummary* locations = |
| 6923 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6924 | |
| 6925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6926 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6927 | |
| 6928 | // If we don't need to be materialized, we only need the inputs to be set. |
| 6929 | if (!insn->NeedsMaterialization()) { |
| 6930 | return; |
| 6931 | } |
| 6932 | |
| 6933 | switch (insn->GetType()) { |
| 6934 | case Primitive::kPrimFloat: |
| 6935 | case Primitive::kPrimDouble: |
| 6936 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6937 | break; |
| 6938 | |
| 6939 | case Primitive::kPrimInt: |
| 6940 | locations->SetOut(Location::RequiresRegister()); |
| 6941 | break; |
| 6942 | |
| 6943 | default: |
| 6944 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 6949 | if (!insn->NeedsMaterialization()) { |
| 6950 | return; |
| 6951 | } |
| 6952 | |
| 6953 | LocationSummary* locations = insn->GetLocations(); |
| 6954 | Location out = locations->Out(); |
| 6955 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 6956 | HConstant *value = insn->GetConstant(); |
| 6957 | |
| 6958 | switch (insn->GetType()) { |
| 6959 | case Primitive::kPrimFloat: |
| 6960 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 6961 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 6962 | break; |
| 6963 | |
| 6964 | case Primitive::kPrimDouble: |
| 6965 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 6966 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 6967 | break; |
| 6968 | |
| 6969 | case Primitive::kPrimInt: |
| 6970 | __ movl(out.AsRegister<Register>(), |
| 6971 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 6972 | break; |
| 6973 | |
| 6974 | default: |
| 6975 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6976 | } |
| 6977 | } |
| 6978 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6979 | /** |
| 6980 | * Class to handle late fixup of offsets into constant area. |
| 6981 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 6982 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6983 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6984 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 6985 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6986 | |
| 6987 | protected: |
| 6988 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6989 | |
| 6990 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6991 | |
| 6992 | private: |
| 6993 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6994 | // Patch the correct offset for the instruction. The place to patch is the |
| 6995 | // last 4 bytes of the instruction. |
| 6996 | // The value to patch is the distance from the offset in the constant area |
| 6997 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6998 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6999 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7000 | |
| 7001 | // Patch in the right value. |
| 7002 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7003 | } |
| 7004 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7005 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7006 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7007 | }; |
| 7008 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7009 | /** |
| 7010 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7011 | * constant area. |
| 7012 | */ |
| 7013 | class JumpTableRIPFixup : public RIPFixup { |
| 7014 | public: |
| 7015 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7016 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7017 | |
| 7018 | void CreateJumpTable() { |
| 7019 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7020 | |
| 7021 | // Ensure that the reference to the jump table has the correct offset. |
| 7022 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7023 | SetOffset(offset_in_constant_table); |
| 7024 | |
| 7025 | // The label values in the jump table are computed relative to the |
| 7026 | // instruction addressing the constant area. |
| 7027 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7028 | |
| 7029 | // Populate the jump table with the correct values for the jump table. |
| 7030 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7031 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7032 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7033 | // The value that we want is the target offset - the position of the table. |
| 7034 | for (int32_t i = 0; i < num_entries; i++) { |
| 7035 | HBasicBlock* b = successors[i]; |
| 7036 | Label* l = codegen_->GetLabelOf(b); |
| 7037 | DCHECK(l->IsBound()); |
| 7038 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7039 | assembler->AppendInt32(offset_to_block); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | private: |
| 7044 | const HX86PackedSwitch* switch_instr_; |
| 7045 | }; |
| 7046 | |
| 7047 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7048 | // Generate the constant area if needed. |
| 7049 | X86Assembler* assembler = GetAssembler(); |
| 7050 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7051 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7052 | // byte values. |
| 7053 | assembler->Align(4, 0); |
| 7054 | constant_area_start_ = assembler->CodeSize(); |
| 7055 | |
| 7056 | // Populate any jump tables. |
| 7057 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7058 | jump_table->CreateJumpTable(); |
| 7059 | } |
| 7060 | |
| 7061 | // And now add the constant area to the generated code. |
| 7062 | assembler->AddConstantArea(); |
| 7063 | } |
| 7064 | |
| 7065 | // And finish up. |
| 7066 | CodeGenerator::Finalize(allocator); |
| 7067 | } |
| 7068 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7069 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7070 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7071 | return Address(reg, kDummy32BitOffset, fixup); |
| 7072 | } |
| 7073 | |
| 7074 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7075 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7076 | return Address(reg, kDummy32BitOffset, fixup); |
| 7077 | } |
| 7078 | |
| 7079 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7080 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7081 | return Address(reg, kDummy32BitOffset, fixup); |
| 7082 | } |
| 7083 | |
| 7084 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7085 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7086 | return Address(reg, kDummy32BitOffset, fixup); |
| 7087 | } |
| 7088 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7089 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7090 | Register reg, |
| 7091 | Register value) { |
| 7092 | // Create a fixup to be used to create and address the jump table. |
| 7093 | JumpTableRIPFixup* table_fixup = |
| 7094 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7095 | |
| 7096 | // We have to populate the jump tables. |
| 7097 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7098 | |
| 7099 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7100 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7101 | } |
| 7102 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7103 | // TODO: target as memory. |
| 7104 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7105 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7106 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7107 | return; |
| 7108 | } |
| 7109 | |
| 7110 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7111 | |
| 7112 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7113 | if (target.Equals(return_loc)) { |
| 7114 | return; |
| 7115 | } |
| 7116 | |
| 7117 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7118 | // with the else branch. |
| 7119 | if (type == Primitive::kPrimLong) { |
| 7120 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7121 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7122 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7123 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7124 | } else { |
| 7125 | // Let the parallel move resolver take care of all of this. |
| 7126 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7127 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7128 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7129 | } |
| 7130 | } |
| 7131 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7132 | #undef __ |
| 7133 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7134 | } // namespace x86 |
| 7135 | } // namespace art |