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) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1221 | HParallelMove move(GetGraph()->GetArena()); |
| 1222 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1223 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1224 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1225 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1226 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1227 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1228 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1232 | if (location.IsRegister()) { |
| 1233 | locations->AddTemp(location); |
| 1234 | } else if (location.IsRegisterPair()) { |
| 1235 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1236 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1237 | } else { |
| 1238 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1239 | } |
| 1240 | } |
| 1241 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1242 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1243 | DCHECK(!successor->IsExitBlock()); |
| 1244 | |
| 1245 | HBasicBlock* block = got->GetBlock(); |
| 1246 | HInstruction* previous = got->GetPrevious(); |
| 1247 | |
| 1248 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1249 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1250 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1251 | return; |
| 1252 | } |
| 1253 | |
| 1254 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1255 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1256 | } |
| 1257 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1258 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1262 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1263 | got->SetLocations(nullptr); |
| 1264 | } |
| 1265 | |
| 1266 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1267 | HandleGoto(got, got->GetSuccessor()); |
| 1268 | } |
| 1269 | |
| 1270 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1271 | try_boundary->SetLocations(nullptr); |
| 1272 | } |
| 1273 | |
| 1274 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1275 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1276 | if (!successor->IsExitBlock()) { |
| 1277 | HandleGoto(try_boundary, successor); |
| 1278 | } |
| 1279 | } |
| 1280 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1281 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1282 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1285 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1288 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1289 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1290 | LabelType* true_label, |
| 1291 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1292 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1293 | __ j(kUnordered, true_label); |
| 1294 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1295 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1296 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1297 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1298 | } |
| 1299 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1300 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1301 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1302 | LabelType* true_label, |
| 1303 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1304 | LocationSummary* locations = cond->GetLocations(); |
| 1305 | Location left = locations->InAt(0); |
| 1306 | Location right = locations->InAt(1); |
| 1307 | IfCondition if_cond = cond->GetCondition(); |
| 1308 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1309 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1310 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | IfCondition true_high_cond = if_cond; |
| 1312 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1313 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1314 | |
| 1315 | // Set the conditions for the test, remembering that == needs to be |
| 1316 | // decided using the low words. |
| 1317 | switch (if_cond) { |
| 1318 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1319 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1320 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1321 | break; |
| 1322 | case kCondLT: |
| 1323 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | break; |
| 1325 | case kCondLE: |
| 1326 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | break; |
| 1328 | case kCondGT: |
| 1329 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1330 | break; |
| 1331 | case kCondGE: |
| 1332 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1333 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1334 | case kCondB: |
| 1335 | false_high_cond = kCondA; |
| 1336 | break; |
| 1337 | case kCondBE: |
| 1338 | true_high_cond = kCondB; |
| 1339 | break; |
| 1340 | case kCondA: |
| 1341 | false_high_cond = kCondB; |
| 1342 | break; |
| 1343 | case kCondAE: |
| 1344 | true_high_cond = kCondA; |
| 1345 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | if (right.IsConstant()) { |
| 1349 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1350 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1351 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1352 | |
| 1353 | if (val_high == 0) { |
| 1354 | __ testl(left_high, left_high); |
| 1355 | } else { |
| 1356 | __ cmpl(left_high, Immediate(val_high)); |
| 1357 | } |
| 1358 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1359 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1360 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1361 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1363 | __ j(X86Condition(true_high_cond), true_label); |
| 1364 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1365 | } |
| 1366 | // Must be equal high, so compare the lows. |
| 1367 | if (val_low == 0) { |
| 1368 | __ testl(left_low, left_low); |
| 1369 | } else { |
| 1370 | __ cmpl(left_low, Immediate(val_low)); |
| 1371 | } |
| 1372 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1373 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1374 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1375 | |
| 1376 | __ cmpl(left_high, right_high); |
| 1377 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1378 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1379 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1380 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1382 | __ j(X86Condition(true_high_cond), true_label); |
| 1383 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1384 | } |
| 1385 | // Must be equal high, so compare the lows. |
| 1386 | __ cmpl(left_low, right_low); |
| 1387 | } |
| 1388 | // The last comparison might be unsigned. |
| 1389 | __ j(final_condition, true_label); |
| 1390 | } |
| 1391 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1392 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1393 | Location rhs, |
| 1394 | HInstruction* insn, |
| 1395 | bool is_double) { |
| 1396 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1397 | if (is_double) { |
| 1398 | if (rhs.IsFpuRegister()) { |
| 1399 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1400 | } else if (const_area != nullptr) { |
| 1401 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1402 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1403 | codegen_->LiteralDoubleAddress( |
| 1404 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1405 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1406 | } else { |
| 1407 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1408 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1409 | } |
| 1410 | } else { |
| 1411 | if (rhs.IsFpuRegister()) { |
| 1412 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1413 | } else if (const_area != nullptr) { |
| 1414 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1415 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1416 | codegen_->LiteralFloatAddress( |
| 1417 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1418 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1419 | } else { |
| 1420 | DCHECK(rhs.IsStackSlot()); |
| 1421 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1422 | } |
| 1423 | } |
| 1424 | } |
| 1425 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1426 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1427 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1428 | LabelType* true_target_in, |
| 1429 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1430 | // Generated branching requires both targets to be explicit. If either of the |
| 1431 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1432 | LabelType fallthrough_target; |
| 1433 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1434 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1435 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1436 | LocationSummary* locations = condition->GetLocations(); |
| 1437 | Location left = locations->InAt(0); |
| 1438 | Location right = locations->InAt(1); |
| 1439 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1440 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1441 | switch (type) { |
| 1442 | case Primitive::kPrimLong: |
| 1443 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1444 | break; |
| 1445 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1446 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1447 | GenerateFPJumps(condition, true_target, false_target); |
| 1448 | break; |
| 1449 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1450 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1451 | GenerateFPJumps(condition, true_target, false_target); |
| 1452 | break; |
| 1453 | default: |
| 1454 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1455 | } |
| 1456 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1457 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1458 | __ jmp(false_target); |
| 1459 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1460 | |
| 1461 | if (fallthrough_target.IsLinked()) { |
| 1462 | __ Bind(&fallthrough_target); |
| 1463 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1464 | } |
| 1465 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1466 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1467 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1468 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1469 | // conditions if they are materialized due to the complex branching. |
| 1470 | return cond->IsCondition() && |
| 1471 | cond->GetNext() == branch && |
| 1472 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1473 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1474 | } |
| 1475 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1476 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1477 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1478 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1479 | LabelType* true_target, |
| 1480 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1481 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1482 | |
| 1483 | if (true_target == nullptr && false_target == nullptr) { |
| 1484 | // Nothing to do. The code always falls through. |
| 1485 | return; |
| 1486 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1487 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1488 | if (cond->AsIntConstant()->IsOne()) { |
| 1489 | if (true_target != nullptr) { |
| 1490 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1491 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1492 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1493 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1494 | if (false_target != nullptr) { |
| 1495 | __ jmp(false_target); |
| 1496 | } |
| 1497 | } |
| 1498 | return; |
| 1499 | } |
| 1500 | |
| 1501 | // The following code generates these patterns: |
| 1502 | // (1) true_target == nullptr && false_target != nullptr |
| 1503 | // - opposite condition true => branch to false_target |
| 1504 | // (2) true_target != nullptr && false_target == nullptr |
| 1505 | // - condition true => branch to true_target |
| 1506 | // (3) true_target != nullptr && false_target != nullptr |
| 1507 | // - condition true => branch to true_target |
| 1508 | // - branch to false_target |
| 1509 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1510 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1511 | if (true_target == nullptr) { |
| 1512 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1513 | } else { |
| 1514 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1515 | } |
| 1516 | } else { |
| 1517 | // Materialized condition, compare against 0. |
| 1518 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1519 | if (lhs.IsRegister()) { |
| 1520 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1521 | } else { |
| 1522 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1523 | } |
| 1524 | if (true_target == nullptr) { |
| 1525 | __ j(kEqual, false_target); |
| 1526 | } else { |
| 1527 | __ j(kNotEqual, true_target); |
| 1528 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1529 | } |
| 1530 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1531 | // Condition has not been materialized, use its inputs as the comparison and |
| 1532 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1533 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1534 | |
| 1535 | // If this is a long or FP comparison that has been folded into |
| 1536 | // the HCondition, generate the comparison directly. |
| 1537 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1538 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1539 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1540 | return; |
| 1541 | } |
| 1542 | |
| 1543 | Location lhs = condition->GetLocations()->InAt(0); |
| 1544 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1545 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1546 | if (rhs.IsRegister()) { |
| 1547 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1548 | } else if (rhs.IsConstant()) { |
| 1549 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1550 | if (constant == 0) { |
| 1551 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1552 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1553 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1554 | } |
| 1555 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1556 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1557 | } |
| 1558 | if (true_target == nullptr) { |
| 1559 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1560 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1561 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1562 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1563 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1564 | |
| 1565 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1566 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1567 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1568 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1572 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1573 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1574 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1575 | locations->SetInAt(0, Location::Any()); |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1580 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1581 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1582 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1583 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1584 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1585 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1586 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1590 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1591 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1592 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1593 | locations->SetInAt(0, Location::Any()); |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1598 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1599 | GenerateTestAndBranch<Label>(deoptimize, |
| 1600 | /* condition_input_index */ 0, |
| 1601 | slow_path->GetEntryLabel(), |
| 1602 | /* false_target */ nullptr); |
| 1603 | } |
| 1604 | |
| 1605 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1606 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1607 | Primitive::Type select_type = select->GetType(); |
| 1608 | HInstruction* cond = select->GetCondition(); |
| 1609 | |
| 1610 | if (Primitive::IsFloatingPointType(select_type)) { |
| 1611 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1612 | } else { |
| 1613 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1614 | } |
| 1615 | locations->SetInAt(1, Location::Any()); |
| 1616 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1617 | locations->SetInAt(2, Location::Any()); |
| 1618 | } |
| 1619 | locations->SetOut(Location::SameAsFirstInput()); |
| 1620 | } |
| 1621 | |
| 1622 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1623 | LocationSummary* locations = select->GetLocations(); |
| 1624 | NearLabel false_target; |
| 1625 | GenerateTestAndBranch<NearLabel>( |
| 1626 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1627 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1628 | __ Bind(&false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1631 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1632 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1633 | } |
| 1634 | |
| 1635 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1636 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1637 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1638 | __ nop(); |
| 1639 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1640 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1641 | } |
| 1642 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1643 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1644 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1647 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1648 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1651 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1652 | local->SetLocations(nullptr); |
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::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1656 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1659 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1660 | LocationSummary* locations = |
| 1661 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1662 | switch (store->InputAt(1)->GetType()) { |
| 1663 | case Primitive::kPrimBoolean: |
| 1664 | case Primitive::kPrimByte: |
| 1665 | case Primitive::kPrimChar: |
| 1666 | case Primitive::kPrimShort: |
| 1667 | case Primitive::kPrimInt: |
| 1668 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1669 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1670 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1671 | break; |
| 1672 | |
| 1673 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1674 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1675 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1676 | break; |
| 1677 | |
| 1678 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1679 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1680 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1683 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1686 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1687 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1688 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1689 | // Handle the long/FP comparisons made in instruction simplification. |
| 1690 | switch (cond->InputAt(0)->GetType()) { |
| 1691 | case Primitive::kPrimLong: { |
| 1692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1693 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1694 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 | locations->SetOut(Location::RequiresRegister()); |
| 1696 | } |
| 1697 | break; |
| 1698 | } |
| 1699 | case Primitive::kPrimFloat: |
| 1700 | case Primitive::kPrimDouble: { |
| 1701 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1702 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1703 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1704 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1705 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1706 | } else { |
| 1707 | locations->SetInAt(1, Location::Any()); |
| 1708 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1709 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1710 | locations->SetOut(Location::RequiresRegister()); |
| 1711 | } |
| 1712 | break; |
| 1713 | } |
| 1714 | default: |
| 1715 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1716 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1717 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1718 | // We need a byte register. |
| 1719 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1720 | } |
| 1721 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1722 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1723 | } |
| 1724 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1725 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1726 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1727 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1728 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1729 | |
| 1730 | LocationSummary* locations = cond->GetLocations(); |
| 1731 | Location lhs = locations->InAt(0); |
| 1732 | Location rhs = locations->InAt(1); |
| 1733 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1734 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1735 | |
| 1736 | switch (cond->InputAt(0)->GetType()) { |
| 1737 | default: { |
| 1738 | // Integer case. |
| 1739 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1740 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1741 | __ xorl(reg, reg); |
| 1742 | |
| 1743 | if (rhs.IsRegister()) { |
| 1744 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1745 | } else if (rhs.IsConstant()) { |
| 1746 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1747 | if (constant == 0) { |
| 1748 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1749 | } else { |
| 1750 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1751 | } |
| 1752 | } else { |
| 1753 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1754 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1755 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1756 | return; |
| 1757 | } |
| 1758 | case Primitive::kPrimLong: |
| 1759 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1760 | break; |
| 1761 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1762 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1763 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1764 | break; |
| 1765 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1766 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1767 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1768 | break; |
| 1769 | } |
| 1770 | |
| 1771 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1772 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1773 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1774 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1775 | __ Bind(&false_label); |
| 1776 | __ xorl(reg, reg); |
| 1777 | __ jmp(&done_label); |
| 1778 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1779 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1780 | __ Bind(&true_label); |
| 1781 | __ movl(reg, Immediate(1)); |
| 1782 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1826 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1830 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1833 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1834 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1838 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1842 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1846 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1850 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1854 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1858 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1862 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1865 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1866 | LocationSummary* locations = |
| 1867 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1868 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1871 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1872 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1875 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1876 | LocationSummary* locations = |
| 1877 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1878 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1879 | } |
| 1880 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1881 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1882 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1885 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1886 | LocationSummary* locations = |
| 1887 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1888 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1891 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1892 | // Will be generated at use site. |
| 1893 | } |
| 1894 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1895 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1896 | LocationSummary* locations = |
| 1897 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1898 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1899 | } |
| 1900 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1901 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1902 | // Will be generated at use site. |
| 1903 | } |
| 1904 | |
| 1905 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1906 | LocationSummary* locations = |
| 1907 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1908 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1909 | } |
| 1910 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1911 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1912 | // Will be generated at use site. |
| 1913 | } |
| 1914 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1915 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1916 | memory_barrier->SetLocations(nullptr); |
| 1917 | } |
| 1918 | |
| 1919 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1920 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1921 | } |
| 1922 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1923 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1924 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1925 | } |
| 1926 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1927 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1928 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1931 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1932 | LocationSummary* locations = |
| 1933 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1934 | switch (ret->InputAt(0)->GetType()) { |
| 1935 | case Primitive::kPrimBoolean: |
| 1936 | case Primitive::kPrimByte: |
| 1937 | case Primitive::kPrimChar: |
| 1938 | case Primitive::kPrimShort: |
| 1939 | case Primitive::kPrimInt: |
| 1940 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1941 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1942 | break; |
| 1943 | |
| 1944 | case Primitive::kPrimLong: |
| 1945 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1946 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1947 | break; |
| 1948 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1949 | case Primitive::kPrimFloat: |
| 1950 | case Primitive::kPrimDouble: |
| 1951 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1952 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1953 | break; |
| 1954 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1955 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1956 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1957 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1960 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1961 | if (kIsDebugBuild) { |
| 1962 | switch (ret->InputAt(0)->GetType()) { |
| 1963 | case Primitive::kPrimBoolean: |
| 1964 | case Primitive::kPrimByte: |
| 1965 | case Primitive::kPrimChar: |
| 1966 | case Primitive::kPrimShort: |
| 1967 | case Primitive::kPrimInt: |
| 1968 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1969 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1970 | break; |
| 1971 | |
| 1972 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1973 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1974 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1975 | break; |
| 1976 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1977 | case Primitive::kPrimFloat: |
| 1978 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1979 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1980 | break; |
| 1981 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1982 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1983 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1984 | } |
| 1985 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1986 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1989 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1990 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1991 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1992 | // the method_idx. |
| 1993 | HandleInvoke(invoke); |
| 1994 | } |
| 1995 | |
| 1996 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1997 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1998 | } |
| 1999 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2000 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2001 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2002 | // art::PrepareForRegisterAllocation. |
| 2003 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2004 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2005 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2006 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2007 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2008 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2009 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2010 | return; |
| 2011 | } |
| 2012 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2013 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2014 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2015 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2016 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2017 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2018 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2019 | } |
| 2020 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2021 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2022 | if (invoke->GetLocations()->Intrinsified()) { |
| 2023 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2024 | intrinsic.Dispatch(invoke); |
| 2025 | return true; |
| 2026 | } |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2030 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2031 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2032 | // art::PrepareForRegisterAllocation. |
| 2033 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2034 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2035 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2036 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2037 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2038 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2039 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2040 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2041 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2042 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2046 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2047 | if (intrinsic.TryDispatch(invoke)) { |
| 2048 | return; |
| 2049 | } |
| 2050 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2051 | HandleInvoke(invoke); |
| 2052 | } |
| 2053 | |
| 2054 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2055 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2056 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2059 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2060 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2061 | return; |
| 2062 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2063 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2064 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2065 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2066 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2069 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2070 | // This call to HandleInvoke allocates a temporary (core) register |
| 2071 | // which is also used to transfer the hidden argument from FP to |
| 2072 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2073 | HandleInvoke(invoke); |
| 2074 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2075 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2079 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2080 | LocationSummary* locations = invoke->GetLocations(); |
| 2081 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2082 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2083 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2084 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2085 | Location receiver = locations->InAt(0); |
| 2086 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2087 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2088 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2089 | // won't be modified thereafter, before the `call` instruction. |
| 2090 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2091 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2092 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2093 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2094 | if (receiver.IsStackSlot()) { |
| 2095 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2096 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2097 | __ movl(temp, Address(temp, class_offset)); |
| 2098 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2099 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2100 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2101 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2102 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2103 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2104 | // emit a read barrier for the previous class reference load. |
| 2105 | // However this is not required in practice, as this is an |
| 2106 | // intermediate/temporary reference and because the current |
| 2107 | // concurrent copying collector keeps the from-space memory |
| 2108 | // intact/accessible until the end of the marking phase (the |
| 2109 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2110 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2111 | // temp = temp->GetImtEntryAt(method_offset); |
| 2112 | __ movl(temp, Address(temp, method_offset)); |
| 2113 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2114 | __ call(Address(temp, |
| 2115 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2116 | |
| 2117 | DCHECK(!codegen_->IsLeafMethod()); |
| 2118 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2119 | } |
| 2120 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2121 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2122 | LocationSummary* locations = |
| 2123 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2124 | switch (neg->GetResultType()) { |
| 2125 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2126 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2127 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2128 | locations->SetOut(Location::SameAsFirstInput()); |
| 2129 | break; |
| 2130 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2131 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2132 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2133 | locations->SetOut(Location::SameAsFirstInput()); |
| 2134 | locations->AddTemp(Location::RequiresRegister()); |
| 2135 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2136 | break; |
| 2137 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2138 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2139 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2140 | locations->SetOut(Location::SameAsFirstInput()); |
| 2141 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2142 | break; |
| 2143 | |
| 2144 | default: |
| 2145 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2150 | LocationSummary* locations = neg->GetLocations(); |
| 2151 | Location out = locations->Out(); |
| 2152 | Location in = locations->InAt(0); |
| 2153 | switch (neg->GetResultType()) { |
| 2154 | case Primitive::kPrimInt: |
| 2155 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2156 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2157 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2158 | break; |
| 2159 | |
| 2160 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2161 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2162 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2163 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2164 | // Negation is similar to subtraction from zero. The least |
| 2165 | // significant byte triggers a borrow when it is different from |
| 2166 | // zero; to take it into account, add 1 to the most significant |
| 2167 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2168 | // operation. |
| 2169 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2170 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2171 | break; |
| 2172 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2173 | case Primitive::kPrimFloat: { |
| 2174 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2175 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2176 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2177 | // Implement float negation with an exclusive or with value |
| 2178 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2179 | // single-precision floating-point number). |
| 2180 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2181 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2182 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2183 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2184 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2185 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2186 | case Primitive::kPrimDouble: { |
| 2187 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2188 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2189 | // Implement double negation with an exclusive or with value |
| 2190 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2191 | // a double-precision floating-point number). |
| 2192 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2193 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2194 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2195 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2196 | |
| 2197 | default: |
| 2198 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2199 | } |
| 2200 | } |
| 2201 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2202 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2203 | LocationSummary* locations = |
| 2204 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2205 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2206 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2207 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2208 | locations->SetOut(Location::SameAsFirstInput()); |
| 2209 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2210 | } |
| 2211 | |
| 2212 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2213 | LocationSummary* locations = neg->GetLocations(); |
| 2214 | Location out = locations->Out(); |
| 2215 | DCHECK(locations->InAt(0).Equals(out)); |
| 2216 | |
| 2217 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2218 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2219 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2220 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2221 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2222 | } else { |
| 2223 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2224 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2225 | } |
| 2226 | } |
| 2227 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2228 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2229 | Primitive::Type result_type = conversion->GetResultType(); |
| 2230 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2231 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2232 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2233 | // The float-to-long and double-to-long type conversions rely on a |
| 2234 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2235 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2236 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2237 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2238 | ? LocationSummary::kCall |
| 2239 | : LocationSummary::kNoCall; |
| 2240 | LocationSummary* locations = |
| 2241 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2242 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2243 | // The Java language does not allow treating boolean as an integral type but |
| 2244 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2245 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2246 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimByte: |
| 2248 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2249 | case Primitive::kPrimBoolean: |
| 2250 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimShort: |
| 2252 | case Primitive::kPrimInt: |
| 2253 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2254 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2255 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2256 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2257 | // the validation of the linear scan implementation |
| 2258 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2259 | break; |
| 2260 | |
| 2261 | default: |
| 2262 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2263 | << " to " << result_type; |
| 2264 | } |
| 2265 | break; |
| 2266 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2267 | case Primitive::kPrimShort: |
| 2268 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2269 | case Primitive::kPrimBoolean: |
| 2270 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2271 | case Primitive::kPrimByte: |
| 2272 | case Primitive::kPrimInt: |
| 2273 | case Primitive::kPrimChar: |
| 2274 | // Processing a Dex `int-to-short' instruction. |
| 2275 | locations->SetInAt(0, Location::Any()); |
| 2276 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2277 | break; |
| 2278 | |
| 2279 | default: |
| 2280 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2281 | << " to " << result_type; |
| 2282 | } |
| 2283 | break; |
| 2284 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2285 | case Primitive::kPrimInt: |
| 2286 | switch (input_type) { |
| 2287 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2288 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2289 | locations->SetInAt(0, Location::Any()); |
| 2290 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2291 | break; |
| 2292 | |
| 2293 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2294 | // Processing a Dex `float-to-int' instruction. |
| 2295 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2296 | locations->SetOut(Location::RequiresRegister()); |
| 2297 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2298 | break; |
| 2299 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2300 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2301 | // Processing a Dex `double-to-int' instruction. |
| 2302 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2303 | locations->SetOut(Location::RequiresRegister()); |
| 2304 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2305 | break; |
| 2306 | |
| 2307 | default: |
| 2308 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2309 | << " to " << result_type; |
| 2310 | } |
| 2311 | break; |
| 2312 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2313 | case Primitive::kPrimLong: |
| 2314 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2315 | case Primitive::kPrimBoolean: |
| 2316 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2317 | case Primitive::kPrimByte: |
| 2318 | case Primitive::kPrimShort: |
| 2319 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2320 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2321 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2322 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2323 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2324 | break; |
| 2325 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2328 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2329 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2330 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2331 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2332 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2333 | // The runtime helper puts the result in EAX, EDX. |
| 2334 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2335 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2336 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2337 | |
| 2338 | default: |
| 2339 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2340 | << " to " << result_type; |
| 2341 | } |
| 2342 | break; |
| 2343 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimChar: |
| 2345 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2346 | case Primitive::kPrimBoolean: |
| 2347 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2348 | case Primitive::kPrimByte: |
| 2349 | case Primitive::kPrimShort: |
| 2350 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2351 | // Processing a Dex `int-to-char' instruction. |
| 2352 | locations->SetInAt(0, Location::Any()); |
| 2353 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2354 | break; |
| 2355 | |
| 2356 | default: |
| 2357 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2358 | << " to " << result_type; |
| 2359 | } |
| 2360 | break; |
| 2361 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2362 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2363 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2364 | case Primitive::kPrimBoolean: |
| 2365 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2366 | case Primitive::kPrimByte: |
| 2367 | case Primitive::kPrimShort: |
| 2368 | case Primitive::kPrimInt: |
| 2369 | case Primitive::kPrimChar: |
| 2370 | // Processing a Dex `int-to-float' instruction. |
| 2371 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2372 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2373 | break; |
| 2374 | |
| 2375 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2376 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2377 | locations->SetInAt(0, Location::Any()); |
| 2378 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2381 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2382 | // Processing a Dex `double-to-float' instruction. |
| 2383 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2384 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2389 | << " to " << result_type; |
| 2390 | }; |
| 2391 | break; |
| 2392 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2393 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2394 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimBoolean: |
| 2396 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimByte: |
| 2398 | case Primitive::kPrimShort: |
| 2399 | case Primitive::kPrimInt: |
| 2400 | case Primitive::kPrimChar: |
| 2401 | // Processing a Dex `int-to-double' instruction. |
| 2402 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2403 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2404 | break; |
| 2405 | |
| 2406 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2407 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2408 | locations->SetInAt(0, Location::Any()); |
| 2409 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2410 | break; |
| 2411 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2412 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2413 | // Processing a Dex `float-to-double' instruction. |
| 2414 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2415 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | |
| 2418 | default: |
| 2419 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2420 | << " to " << result_type; |
| 2421 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2422 | break; |
| 2423 | |
| 2424 | default: |
| 2425 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2426 | << " to " << result_type; |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2431 | LocationSummary* locations = conversion->GetLocations(); |
| 2432 | Location out = locations->Out(); |
| 2433 | Location in = locations->InAt(0); |
| 2434 | Primitive::Type result_type = conversion->GetResultType(); |
| 2435 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2436 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2437 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2438 | case Primitive::kPrimByte: |
| 2439 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2440 | case Primitive::kPrimBoolean: |
| 2441 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2442 | case Primitive::kPrimShort: |
| 2443 | case Primitive::kPrimInt: |
| 2444 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2445 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2446 | if (in.IsRegister()) { |
| 2447 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2448 | } else { |
| 2449 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2450 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2451 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2452 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2453 | break; |
| 2454 | |
| 2455 | default: |
| 2456 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2457 | << " to " << result_type; |
| 2458 | } |
| 2459 | break; |
| 2460 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimShort: |
| 2462 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2463 | case Primitive::kPrimBoolean: |
| 2464 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimByte: |
| 2466 | case Primitive::kPrimInt: |
| 2467 | case Primitive::kPrimChar: |
| 2468 | // Processing a Dex `int-to-short' instruction. |
| 2469 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2470 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2471 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2472 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2473 | } else { |
| 2474 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2475 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2476 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2477 | } |
| 2478 | break; |
| 2479 | |
| 2480 | default: |
| 2481 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2482 | << " to " << result_type; |
| 2483 | } |
| 2484 | break; |
| 2485 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2486 | case Primitive::kPrimInt: |
| 2487 | switch (input_type) { |
| 2488 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2489 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2490 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2491 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2492 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2493 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2494 | } else { |
| 2495 | DCHECK(in.IsConstant()); |
| 2496 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2497 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2498 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2499 | } |
| 2500 | break; |
| 2501 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2502 | case Primitive::kPrimFloat: { |
| 2503 | // Processing a Dex `float-to-int' instruction. |
| 2504 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2505 | Register output = out.AsRegister<Register>(); |
| 2506 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2507 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2508 | |
| 2509 | __ movl(output, Immediate(kPrimIntMax)); |
| 2510 | // temp = int-to-float(output) |
| 2511 | __ cvtsi2ss(temp, output); |
| 2512 | // if input >= temp goto done |
| 2513 | __ comiss(input, temp); |
| 2514 | __ j(kAboveEqual, &done); |
| 2515 | // if input == NaN goto nan |
| 2516 | __ j(kUnordered, &nan); |
| 2517 | // output = float-to-int-truncate(input) |
| 2518 | __ cvttss2si(output, input); |
| 2519 | __ jmp(&done); |
| 2520 | __ Bind(&nan); |
| 2521 | // output = 0 |
| 2522 | __ xorl(output, output); |
| 2523 | __ Bind(&done); |
| 2524 | break; |
| 2525 | } |
| 2526 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2527 | case Primitive::kPrimDouble: { |
| 2528 | // Processing a Dex `double-to-int' instruction. |
| 2529 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2530 | Register output = out.AsRegister<Register>(); |
| 2531 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2532 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2533 | |
| 2534 | __ movl(output, Immediate(kPrimIntMax)); |
| 2535 | // temp = int-to-double(output) |
| 2536 | __ cvtsi2sd(temp, output); |
| 2537 | // if input >= temp goto done |
| 2538 | __ comisd(input, temp); |
| 2539 | __ j(kAboveEqual, &done); |
| 2540 | // if input == NaN goto nan |
| 2541 | __ j(kUnordered, &nan); |
| 2542 | // output = double-to-int-truncate(input) |
| 2543 | __ cvttsd2si(output, input); |
| 2544 | __ jmp(&done); |
| 2545 | __ Bind(&nan); |
| 2546 | // output = 0 |
| 2547 | __ xorl(output, output); |
| 2548 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2549 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2550 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2551 | |
| 2552 | default: |
| 2553 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2554 | << " to " << result_type; |
| 2555 | } |
| 2556 | break; |
| 2557 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimLong: |
| 2559 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimBoolean: |
| 2561 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimByte: |
| 2563 | case Primitive::kPrimShort: |
| 2564 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2566 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2567 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2568 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2569 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2570 | __ cdq(); |
| 2571 | break; |
| 2572 | |
| 2573 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2574 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2575 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2576 | conversion, |
| 2577 | conversion->GetDexPc(), |
| 2578 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2579 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2580 | break; |
| 2581 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2582 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2583 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2584 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2585 | conversion, |
| 2586 | conversion->GetDexPc(), |
| 2587 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2588 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2589 | break; |
| 2590 | |
| 2591 | default: |
| 2592 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2593 | << " to " << result_type; |
| 2594 | } |
| 2595 | break; |
| 2596 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimChar: |
| 2598 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2599 | case Primitive::kPrimBoolean: |
| 2600 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2601 | case Primitive::kPrimByte: |
| 2602 | case Primitive::kPrimShort: |
| 2603 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2604 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2605 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2606 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2607 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2608 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2609 | } else { |
| 2610 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2611 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2612 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2613 | } |
| 2614 | break; |
| 2615 | |
| 2616 | default: |
| 2617 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2618 | << " to " << result_type; |
| 2619 | } |
| 2620 | break; |
| 2621 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2623 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimBoolean: |
| 2625 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimByte: |
| 2627 | case Primitive::kPrimShort: |
| 2628 | case Primitive::kPrimInt: |
| 2629 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2630 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2631 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2632 | break; |
| 2633 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2634 | case Primitive::kPrimLong: { |
| 2635 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2636 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2637 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2638 | // Create stack space for the call to |
| 2639 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2640 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2641 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2642 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2643 | __ subl(ESP, Immediate(adjustment)); |
| 2644 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2645 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2646 | // Load the value to the FP stack, using temporaries if needed. |
| 2647 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2648 | |
| 2649 | if (out.IsStackSlot()) { |
| 2650 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2651 | } else { |
| 2652 | __ fstps(Address(ESP, 0)); |
| 2653 | Location stack_temp = Location::StackSlot(0); |
| 2654 | codegen_->Move32(out, stack_temp); |
| 2655 | } |
| 2656 | |
| 2657 | // Remove the temporary stack space we allocated. |
| 2658 | if (adjustment != 0) { |
| 2659 | __ addl(ESP, Immediate(adjustment)); |
| 2660 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2661 | break; |
| 2662 | } |
| 2663 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2665 | // Processing a Dex `double-to-float' instruction. |
| 2666 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
| 2669 | default: |
| 2670 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2671 | << " to " << result_type; |
| 2672 | }; |
| 2673 | break; |
| 2674 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2675 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2677 | case Primitive::kPrimBoolean: |
| 2678 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2679 | case Primitive::kPrimByte: |
| 2680 | case Primitive::kPrimShort: |
| 2681 | case Primitive::kPrimInt: |
| 2682 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2683 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2684 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2687 | case Primitive::kPrimLong: { |
| 2688 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2689 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2690 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2691 | // Create stack space for the call to |
| 2692 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2693 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2694 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2695 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2696 | __ subl(ESP, Immediate(adjustment)); |
| 2697 | } |
| 2698 | |
| 2699 | // Load the value to the FP stack, using temporaries if needed. |
| 2700 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2701 | |
| 2702 | if (out.IsDoubleStackSlot()) { |
| 2703 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2704 | } else { |
| 2705 | __ fstpl(Address(ESP, 0)); |
| 2706 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2707 | codegen_->Move64(out, stack_temp); |
| 2708 | } |
| 2709 | |
| 2710 | // Remove the temporary stack space we allocated. |
| 2711 | if (adjustment != 0) { |
| 2712 | __ addl(ESP, Immediate(adjustment)); |
| 2713 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2714 | break; |
| 2715 | } |
| 2716 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2718 | // Processing a Dex `float-to-double' instruction. |
| 2719 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 | break; |
| 2721 | |
| 2722 | default: |
| 2723 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2724 | << " to " << result_type; |
| 2725 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2726 | break; |
| 2727 | |
| 2728 | default: |
| 2729 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2730 | << " to " << result_type; |
| 2731 | } |
| 2732 | } |
| 2733 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2734 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2735 | LocationSummary* locations = |
| 2736 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2737 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2738 | case Primitive::kPrimInt: { |
| 2739 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2740 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2741 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2742 | break; |
| 2743 | } |
| 2744 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2745 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2746 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2747 | locations->SetInAt(1, Location::Any()); |
| 2748 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2749 | break; |
| 2750 | } |
| 2751 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2752 | case Primitive::kPrimFloat: |
| 2753 | case Primitive::kPrimDouble: { |
| 2754 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2755 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2756 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2757 | } else if (add->InputAt(1)->IsConstant()) { |
| 2758 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2759 | } else { |
| 2760 | locations->SetInAt(1, Location::Any()); |
| 2761 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2762 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2763 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2764 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2765 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2766 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2767 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2768 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2769 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2773 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2774 | Location first = locations->InAt(0); |
| 2775 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2776 | Location out = locations->Out(); |
| 2777 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2778 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2779 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2780 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2781 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2782 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2783 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2784 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2785 | } else { |
| 2786 | __ leal(out.AsRegister<Register>(), Address( |
| 2787 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2788 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2789 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2790 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2791 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2792 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2793 | } else { |
| 2794 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2795 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2796 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2797 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2798 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2799 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2800 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2804 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2805 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2806 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2807 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2808 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2809 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2810 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2811 | } else { |
| 2812 | DCHECK(second.IsConstant()) << second; |
| 2813 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2814 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2815 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2816 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2817 | break; |
| 2818 | } |
| 2819 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2820 | case Primitive::kPrimFloat: { |
| 2821 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2822 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2823 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2824 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2825 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2826 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2827 | codegen_->LiteralFloatAddress( |
| 2828 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2829 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2830 | } else { |
| 2831 | DCHECK(second.IsStackSlot()); |
| 2832 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2833 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2834 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | case Primitive::kPrimDouble: { |
| 2838 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2839 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2840 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2841 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2842 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2843 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2844 | codegen_->LiteralDoubleAddress( |
| 2845 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2846 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2847 | } else { |
| 2848 | DCHECK(second.IsDoubleStackSlot()); |
| 2849 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2850 | } |
| 2851 | break; |
| 2852 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2853 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2854 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2855 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2859 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2860 | LocationSummary* locations = |
| 2861 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2862 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2863 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2864 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2865 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2866 | locations->SetInAt(1, Location::Any()); |
| 2867 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2868 | break; |
| 2869 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2870 | case Primitive::kPrimFloat: |
| 2871 | case Primitive::kPrimDouble: { |
| 2872 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2873 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2874 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2875 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2876 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2877 | } else { |
| 2878 | locations->SetInAt(1, Location::Any()); |
| 2879 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2880 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2881 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2882 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2883 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2884 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2885 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2886 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2890 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2891 | Location first = locations->InAt(0); |
| 2892 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2893 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2894 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2895 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2896 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2897 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2898 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2899 | __ subl(first.AsRegister<Register>(), |
| 2900 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2901 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2902 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2903 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2904 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2908 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2909 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2910 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2911 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2912 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2913 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2914 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2915 | } else { |
| 2916 | DCHECK(second.IsConstant()) << second; |
| 2917 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2918 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2919 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2920 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2921 | break; |
| 2922 | } |
| 2923 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2924 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2925 | if (second.IsFpuRegister()) { |
| 2926 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2927 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2928 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2929 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2930 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2931 | codegen_->LiteralFloatAddress( |
| 2932 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2933 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2934 | } else { |
| 2935 | DCHECK(second.IsStackSlot()); |
| 2936 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2937 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2938 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2942 | if (second.IsFpuRegister()) { |
| 2943 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2944 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2945 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2946 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2947 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2948 | codegen_->LiteralDoubleAddress( |
| 2949 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2950 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2951 | } else { |
| 2952 | DCHECK(second.IsDoubleStackSlot()); |
| 2953 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2954 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2955 | break; |
| 2956 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2957 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2958 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2959 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2960 | } |
| 2961 | } |
| 2962 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2963 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2964 | LocationSummary* locations = |
| 2965 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2966 | switch (mul->GetResultType()) { |
| 2967 | case Primitive::kPrimInt: |
| 2968 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2969 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2970 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2971 | // Can use 3 operand multiply. |
| 2972 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2973 | } else { |
| 2974 | locations->SetOut(Location::SameAsFirstInput()); |
| 2975 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2976 | break; |
| 2977 | case Primitive::kPrimLong: { |
| 2978 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2979 | locations->SetInAt(1, Location::Any()); |
| 2980 | locations->SetOut(Location::SameAsFirstInput()); |
| 2981 | // Needed for imul on 32bits with 64bits output. |
| 2982 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2983 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2984 | break; |
| 2985 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2986 | case Primitive::kPrimFloat: |
| 2987 | case Primitive::kPrimDouble: { |
| 2988 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2989 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2990 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2991 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2992 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2993 | } else { |
| 2994 | locations->SetInAt(1, Location::Any()); |
| 2995 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2996 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2997 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2998 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2999 | |
| 3000 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3001 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3002 | } |
| 3003 | } |
| 3004 | |
| 3005 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3006 | LocationSummary* locations = mul->GetLocations(); |
| 3007 | Location first = locations->InAt(0); |
| 3008 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3009 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3010 | |
| 3011 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3012 | case Primitive::kPrimInt: |
| 3013 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3014 | // problems where the output may not be the same as the first operand. |
| 3015 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3016 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3017 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3018 | } else if (second.IsRegister()) { |
| 3019 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3020 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3021 | } else { |
| 3022 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3023 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3024 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3025 | } |
| 3026 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3027 | |
| 3028 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3029 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3030 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3031 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3032 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3033 | |
| 3034 | DCHECK_EQ(EAX, eax); |
| 3035 | DCHECK_EQ(EDX, edx); |
| 3036 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3037 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3038 | // output: in1 |
| 3039 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3040 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3041 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3042 | if (second.IsConstant()) { |
| 3043 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3044 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3045 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3046 | int32_t low_value = Low32Bits(value); |
| 3047 | int32_t high_value = High32Bits(value); |
| 3048 | Immediate low(low_value); |
| 3049 | Immediate high(high_value); |
| 3050 | |
| 3051 | __ movl(eax, high); |
| 3052 | // eax <- in1.lo * in2.hi |
| 3053 | __ imull(eax, in1_lo); |
| 3054 | // in1.hi <- in1.hi * in2.lo |
| 3055 | __ imull(in1_hi, low); |
| 3056 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3057 | __ addl(in1_hi, eax); |
| 3058 | // move in2_lo to eax to prepare for double precision |
| 3059 | __ movl(eax, low); |
| 3060 | // edx:eax <- in1.lo * in2.lo |
| 3061 | __ mull(in1_lo); |
| 3062 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3063 | __ addl(in1_hi, edx); |
| 3064 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3065 | __ movl(in1_lo, eax); |
| 3066 | } else if (second.IsRegisterPair()) { |
| 3067 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3068 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3069 | |
| 3070 | __ movl(eax, in2_hi); |
| 3071 | // eax <- in1.lo * in2.hi |
| 3072 | __ imull(eax, in1_lo); |
| 3073 | // in1.hi <- in1.hi * in2.lo |
| 3074 | __ imull(in1_hi, in2_lo); |
| 3075 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3076 | __ addl(in1_hi, eax); |
| 3077 | // move in1_lo to eax to prepare for double precision |
| 3078 | __ movl(eax, in1_lo); |
| 3079 | // edx:eax <- in1.lo * in2.lo |
| 3080 | __ mull(in2_lo); |
| 3081 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3082 | __ addl(in1_hi, edx); |
| 3083 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3084 | __ movl(in1_lo, eax); |
| 3085 | } else { |
| 3086 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3087 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3088 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3089 | |
| 3090 | __ movl(eax, in2_hi); |
| 3091 | // eax <- in1.lo * in2.hi |
| 3092 | __ imull(eax, in1_lo); |
| 3093 | // in1.hi <- in1.hi * in2.lo |
| 3094 | __ imull(in1_hi, in2_lo); |
| 3095 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3096 | __ addl(in1_hi, eax); |
| 3097 | // move in1_lo to eax to prepare for double precision |
| 3098 | __ movl(eax, in1_lo); |
| 3099 | // edx:eax <- in1.lo * in2.lo |
| 3100 | __ mull(in2_lo); |
| 3101 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3102 | __ addl(in1_hi, edx); |
| 3103 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3104 | __ movl(in1_lo, eax); |
| 3105 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3106 | |
| 3107 | break; |
| 3108 | } |
| 3109 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3110 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3111 | DCHECK(first.Equals(locations->Out())); |
| 3112 | if (second.IsFpuRegister()) { |
| 3113 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3114 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3115 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3116 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3117 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3118 | codegen_->LiteralFloatAddress( |
| 3119 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3120 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3121 | } else { |
| 3122 | DCHECK(second.IsStackSlot()); |
| 3123 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3124 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3129 | DCHECK(first.Equals(locations->Out())); |
| 3130 | if (second.IsFpuRegister()) { |
| 3131 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3132 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3133 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3134 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3135 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3136 | codegen_->LiteralDoubleAddress( |
| 3137 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3138 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3139 | } else { |
| 3140 | DCHECK(second.IsDoubleStackSlot()); |
| 3141 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3142 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3143 | break; |
| 3144 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3145 | |
| 3146 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3147 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3151 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3152 | uint32_t temp_offset, |
| 3153 | uint32_t stack_adjustment, |
| 3154 | bool is_fp, |
| 3155 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3156 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3157 | DCHECK(!is_wide); |
| 3158 | if (is_fp) { |
| 3159 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3160 | } else { |
| 3161 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3162 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3163 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3164 | DCHECK(is_wide); |
| 3165 | if (is_fp) { |
| 3166 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3167 | } else { |
| 3168 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3169 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3170 | } else { |
| 3171 | // 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] | 3172 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3173 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3174 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3175 | if (is_fp) { |
| 3176 | __ flds(Address(ESP, temp_offset)); |
| 3177 | } else { |
| 3178 | __ filds(Address(ESP, temp_offset)); |
| 3179 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3180 | } else { |
| 3181 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3182 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3183 | if (is_fp) { |
| 3184 | __ fldl(Address(ESP, temp_offset)); |
| 3185 | } else { |
| 3186 | __ fildl(Address(ESP, temp_offset)); |
| 3187 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3193 | Primitive::Type type = rem->GetResultType(); |
| 3194 | bool is_float = type == Primitive::kPrimFloat; |
| 3195 | size_t elem_size = Primitive::ComponentSize(type); |
| 3196 | LocationSummary* locations = rem->GetLocations(); |
| 3197 | Location first = locations->InAt(0); |
| 3198 | Location second = locations->InAt(1); |
| 3199 | Location out = locations->Out(); |
| 3200 | |
| 3201 | // Create stack space for 2 elements. |
| 3202 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3203 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3204 | |
| 3205 | // 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] | 3206 | const bool is_wide = !is_float; |
| 3207 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3208 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3209 | |
| 3210 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3211 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3212 | __ Bind(&retry); |
| 3213 | __ fprem(); |
| 3214 | |
| 3215 | // Move FP status to AX. |
| 3216 | __ fstsw(); |
| 3217 | |
| 3218 | // And see if the argument reduction is complete. This is signaled by the |
| 3219 | // C2 FPU flag bit set to 0. |
| 3220 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3221 | __ j(kNotEqual, &retry); |
| 3222 | |
| 3223 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3224 | // Store FP top of stack to real stack. |
| 3225 | if (is_float) { |
| 3226 | __ fsts(Address(ESP, 0)); |
| 3227 | } else { |
| 3228 | __ fstl(Address(ESP, 0)); |
| 3229 | } |
| 3230 | |
| 3231 | // Pop the 2 items from the FP stack. |
| 3232 | __ fucompp(); |
| 3233 | |
| 3234 | // Load the value from the stack into an XMM register. |
| 3235 | DCHECK(out.IsFpuRegister()) << out; |
| 3236 | if (is_float) { |
| 3237 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3238 | } else { |
| 3239 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3240 | } |
| 3241 | |
| 3242 | // And remove the temporary stack space we allocated. |
| 3243 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3244 | } |
| 3245 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3246 | |
| 3247 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3248 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3249 | |
| 3250 | LocationSummary* locations = instruction->GetLocations(); |
| 3251 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3252 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3253 | |
| 3254 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3255 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3256 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3257 | |
| 3258 | DCHECK(imm == 1 || imm == -1); |
| 3259 | |
| 3260 | if (instruction->IsRem()) { |
| 3261 | __ xorl(out_register, out_register); |
| 3262 | } else { |
| 3263 | __ movl(out_register, input_register); |
| 3264 | if (imm == -1) { |
| 3265 | __ negl(out_register); |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3271 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3272 | LocationSummary* locations = instruction->GetLocations(); |
| 3273 | |
| 3274 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3275 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3276 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3277 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3278 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3279 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3280 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3281 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3282 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3283 | __ testl(input_register, input_register); |
| 3284 | __ cmovl(kGreaterEqual, num, input_register); |
| 3285 | int shift = CTZ(imm); |
| 3286 | __ sarl(num, Immediate(shift)); |
| 3287 | |
| 3288 | if (imm < 0) { |
| 3289 | __ negl(num); |
| 3290 | } |
| 3291 | |
| 3292 | __ movl(out_register, num); |
| 3293 | } |
| 3294 | |
| 3295 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3296 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3297 | |
| 3298 | LocationSummary* locations = instruction->GetLocations(); |
| 3299 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3300 | |
| 3301 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3302 | Register out = locations->Out().AsRegister<Register>(); |
| 3303 | Register num; |
| 3304 | Register edx; |
| 3305 | |
| 3306 | if (instruction->IsDiv()) { |
| 3307 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3308 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3309 | } else { |
| 3310 | edx = locations->Out().AsRegister<Register>(); |
| 3311 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3312 | } |
| 3313 | |
| 3314 | DCHECK_EQ(EAX, eax); |
| 3315 | DCHECK_EQ(EDX, edx); |
| 3316 | if (instruction->IsDiv()) { |
| 3317 | DCHECK_EQ(EAX, out); |
| 3318 | } else { |
| 3319 | DCHECK_EQ(EDX, out); |
| 3320 | } |
| 3321 | |
| 3322 | int64_t magic; |
| 3323 | int shift; |
| 3324 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3325 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3326 | NearLabel ndiv; |
| 3327 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3328 | // If numerator is 0, the result is 0, no computation needed. |
| 3329 | __ testl(eax, eax); |
| 3330 | __ j(kNotEqual, &ndiv); |
| 3331 | |
| 3332 | __ xorl(out, out); |
| 3333 | __ jmp(&end); |
| 3334 | |
| 3335 | __ Bind(&ndiv); |
| 3336 | |
| 3337 | // Save the numerator. |
| 3338 | __ movl(num, eax); |
| 3339 | |
| 3340 | // EAX = magic |
| 3341 | __ movl(eax, Immediate(magic)); |
| 3342 | |
| 3343 | // EDX:EAX = magic * numerator |
| 3344 | __ imull(num); |
| 3345 | |
| 3346 | if (imm > 0 && magic < 0) { |
| 3347 | // EDX += num |
| 3348 | __ addl(edx, num); |
| 3349 | } else if (imm < 0 && magic > 0) { |
| 3350 | __ subl(edx, num); |
| 3351 | } |
| 3352 | |
| 3353 | // Shift if needed. |
| 3354 | if (shift != 0) { |
| 3355 | __ sarl(edx, Immediate(shift)); |
| 3356 | } |
| 3357 | |
| 3358 | // EDX += 1 if EDX < 0 |
| 3359 | __ movl(eax, edx); |
| 3360 | __ shrl(edx, Immediate(31)); |
| 3361 | __ addl(edx, eax); |
| 3362 | |
| 3363 | if (instruction->IsRem()) { |
| 3364 | __ movl(eax, num); |
| 3365 | __ imull(edx, Immediate(imm)); |
| 3366 | __ subl(eax, edx); |
| 3367 | __ movl(edx, eax); |
| 3368 | } else { |
| 3369 | __ movl(eax, edx); |
| 3370 | } |
| 3371 | __ Bind(&end); |
| 3372 | } |
| 3373 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3374 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3375 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3376 | |
| 3377 | LocationSummary* locations = instruction->GetLocations(); |
| 3378 | Location out = locations->Out(); |
| 3379 | Location first = locations->InAt(0); |
| 3380 | Location second = locations->InAt(1); |
| 3381 | bool is_div = instruction->IsDiv(); |
| 3382 | |
| 3383 | switch (instruction->GetResultType()) { |
| 3384 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3385 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3386 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3387 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3388 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3389 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3390 | |
| 3391 | if (imm == 0) { |
| 3392 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3393 | } else if (imm == 1 || imm == -1) { |
| 3394 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3395 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3396 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3397 | } else { |
| 3398 | DCHECK(imm <= -2 || imm >= 2); |
| 3399 | GenerateDivRemWithAnyConstant(instruction); |
| 3400 | } |
| 3401 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3402 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3403 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3404 | is_div); |
| 3405 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3406 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3407 | Register second_reg = second.AsRegister<Register>(); |
| 3408 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3409 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3410 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3411 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3412 | __ cmpl(second_reg, Immediate(-1)); |
| 3413 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3414 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3415 | // edx:eax <- sign-extended of eax |
| 3416 | __ cdq(); |
| 3417 | // eax = quotient, edx = remainder |
| 3418 | __ idivl(second_reg); |
| 3419 | __ Bind(slow_path->GetExitLabel()); |
| 3420 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | } |
| 3423 | |
| 3424 | case Primitive::kPrimLong: { |
| 3425 | InvokeRuntimeCallingConvention calling_convention; |
| 3426 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3427 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3428 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3429 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3430 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3431 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3432 | |
| 3433 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3434 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3435 | instruction, |
| 3436 | instruction->GetDexPc(), |
| 3437 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3438 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3439 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3440 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3441 | instruction, |
| 3442 | instruction->GetDexPc(), |
| 3443 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3444 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3445 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3446 | break; |
| 3447 | } |
| 3448 | |
| 3449 | default: |
| 3450 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3451 | } |
| 3452 | } |
| 3453 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3454 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3455 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3456 | ? LocationSummary::kCall |
| 3457 | : LocationSummary::kNoCall; |
| 3458 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3459 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3460 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3461 | case Primitive::kPrimInt: { |
| 3462 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3463 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3464 | locations->SetOut(Location::SameAsFirstInput()); |
| 3465 | // Intel uses edx:eax as the dividend. |
| 3466 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3467 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3468 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3469 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3470 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3471 | locations->AddTemp(Location::RequiresRegister()); |
| 3472 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3473 | break; |
| 3474 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3475 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3476 | InvokeRuntimeCallingConvention calling_convention; |
| 3477 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3478 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3479 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3480 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3481 | // Runtime helper puts the result in EAX, EDX. |
| 3482 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3483 | break; |
| 3484 | } |
| 3485 | case Primitive::kPrimFloat: |
| 3486 | case Primitive::kPrimDouble: { |
| 3487 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3488 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3489 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3490 | } else if (div->InputAt(1)->IsConstant()) { |
| 3491 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3492 | } else { |
| 3493 | locations->SetInAt(1, Location::Any()); |
| 3494 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3495 | locations->SetOut(Location::SameAsFirstInput()); |
| 3496 | break; |
| 3497 | } |
| 3498 | |
| 3499 | default: |
| 3500 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3505 | LocationSummary* locations = div->GetLocations(); |
| 3506 | Location first = locations->InAt(0); |
| 3507 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3508 | |
| 3509 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3510 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3511 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3512 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3513 | break; |
| 3514 | } |
| 3515 | |
| 3516 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3517 | if (second.IsFpuRegister()) { |
| 3518 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3519 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3520 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3521 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3522 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3523 | codegen_->LiteralFloatAddress( |
| 3524 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3525 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3526 | } else { |
| 3527 | DCHECK(second.IsStackSlot()); |
| 3528 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3529 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3530 | break; |
| 3531 | } |
| 3532 | |
| 3533 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3534 | if (second.IsFpuRegister()) { |
| 3535 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3536 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3537 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3538 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3539 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3540 | codegen_->LiteralDoubleAddress( |
| 3541 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3542 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3543 | } else { |
| 3544 | DCHECK(second.IsDoubleStackSlot()); |
| 3545 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3546 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3547 | break; |
| 3548 | } |
| 3549 | |
| 3550 | default: |
| 3551 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3552 | } |
| 3553 | } |
| 3554 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3555 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3556 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3557 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3558 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3559 | ? LocationSummary::kCall |
| 3560 | : LocationSummary::kNoCall; |
| 3561 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3563 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3564 | case Primitive::kPrimInt: { |
| 3565 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3566 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3567 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3568 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3569 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3570 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3571 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3572 | locations->AddTemp(Location::RequiresRegister()); |
| 3573 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3574 | break; |
| 3575 | } |
| 3576 | case Primitive::kPrimLong: { |
| 3577 | InvokeRuntimeCallingConvention calling_convention; |
| 3578 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3579 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3580 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3581 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3582 | // Runtime helper puts the result in EAX, EDX. |
| 3583 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3584 | break; |
| 3585 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3586 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3587 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3588 | locations->SetInAt(0, Location::Any()); |
| 3589 | locations->SetInAt(1, Location::Any()); |
| 3590 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3591 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3592 | break; |
| 3593 | } |
| 3594 | |
| 3595 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3596 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3601 | Primitive::Type type = rem->GetResultType(); |
| 3602 | switch (type) { |
| 3603 | case Primitive::kPrimInt: |
| 3604 | case Primitive::kPrimLong: { |
| 3605 | GenerateDivRemIntegral(rem); |
| 3606 | break; |
| 3607 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3608 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3609 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3610 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3611 | break; |
| 3612 | } |
| 3613 | default: |
| 3614 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3615 | } |
| 3616 | } |
| 3617 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3618 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3619 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3620 | ? LocationSummary::kCallOnSlowPath |
| 3621 | : LocationSummary::kNoCall; |
| 3622 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3623 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3624 | case Primitive::kPrimByte: |
| 3625 | case Primitive::kPrimChar: |
| 3626 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3627 | case Primitive::kPrimInt: { |
| 3628 | locations->SetInAt(0, Location::Any()); |
| 3629 | break; |
| 3630 | } |
| 3631 | case Primitive::kPrimLong: { |
| 3632 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3633 | if (!instruction->IsConstant()) { |
| 3634 | locations->AddTemp(Location::RequiresRegister()); |
| 3635 | } |
| 3636 | break; |
| 3637 | } |
| 3638 | default: |
| 3639 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3640 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3641 | if (instruction->HasUses()) { |
| 3642 | locations->SetOut(Location::SameAsFirstInput()); |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3647 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3648 | codegen_->AddSlowPath(slow_path); |
| 3649 | |
| 3650 | LocationSummary* locations = instruction->GetLocations(); |
| 3651 | Location value = locations->InAt(0); |
| 3652 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3653 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3654 | case Primitive::kPrimByte: |
| 3655 | case Primitive::kPrimChar: |
| 3656 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3657 | case Primitive::kPrimInt: { |
| 3658 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3659 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3660 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3661 | } else if (value.IsStackSlot()) { |
| 3662 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3663 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3664 | } else { |
| 3665 | DCHECK(value.IsConstant()) << value; |
| 3666 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3667 | __ jmp(slow_path->GetEntryLabel()); |
| 3668 | } |
| 3669 | } |
| 3670 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3671 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3672 | case Primitive::kPrimLong: { |
| 3673 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3674 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3675 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3676 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3677 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3678 | } else { |
| 3679 | DCHECK(value.IsConstant()) << value; |
| 3680 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3681 | __ jmp(slow_path->GetEntryLabel()); |
| 3682 | } |
| 3683 | } |
| 3684 | break; |
| 3685 | } |
| 3686 | default: |
| 3687 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3688 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3691 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3692 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3693 | |
| 3694 | LocationSummary* locations = |
| 3695 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3696 | |
| 3697 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3698 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3699 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3700 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3701 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3702 | // The shift count needs to be in CL or a constant. |
| 3703 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3704 | locations->SetOut(Location::SameAsFirstInput()); |
| 3705 | break; |
| 3706 | } |
| 3707 | default: |
| 3708 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3713 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3714 | |
| 3715 | LocationSummary* locations = op->GetLocations(); |
| 3716 | Location first = locations->InAt(0); |
| 3717 | Location second = locations->InAt(1); |
| 3718 | DCHECK(first.Equals(locations->Out())); |
| 3719 | |
| 3720 | switch (op->GetResultType()) { |
| 3721 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3722 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3723 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3724 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3725 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3726 | DCHECK_EQ(ECX, second_reg); |
| 3727 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3728 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3729 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3730 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3731 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3732 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3733 | } |
| 3734 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3735 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3736 | if (shift == 0) { |
| 3737 | return; |
| 3738 | } |
| 3739 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3740 | if (op->IsShl()) { |
| 3741 | __ shll(first_reg, imm); |
| 3742 | } else if (op->IsShr()) { |
| 3743 | __ sarl(first_reg, imm); |
| 3744 | } else { |
| 3745 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3746 | } |
| 3747 | } |
| 3748 | break; |
| 3749 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3750 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3751 | if (second.IsRegister()) { |
| 3752 | Register second_reg = second.AsRegister<Register>(); |
| 3753 | DCHECK_EQ(ECX, second_reg); |
| 3754 | if (op->IsShl()) { |
| 3755 | GenerateShlLong(first, second_reg); |
| 3756 | } else if (op->IsShr()) { |
| 3757 | GenerateShrLong(first, second_reg); |
| 3758 | } else { |
| 3759 | GenerateUShrLong(first, second_reg); |
| 3760 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3761 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3762 | // Shift by a constant. |
| 3763 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3764 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3765 | if (shift != 0) { |
| 3766 | if (op->IsShl()) { |
| 3767 | GenerateShlLong(first, shift); |
| 3768 | } else if (op->IsShr()) { |
| 3769 | GenerateShrLong(first, shift); |
| 3770 | } else { |
| 3771 | GenerateUShrLong(first, shift); |
| 3772 | } |
| 3773 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3774 | } |
| 3775 | break; |
| 3776 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3777 | default: |
| 3778 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3779 | } |
| 3780 | } |
| 3781 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3782 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3783 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3784 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3785 | if (shift == 1) { |
| 3786 | // This is just an addition. |
| 3787 | __ addl(low, low); |
| 3788 | __ adcl(high, high); |
| 3789 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3790 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3791 | codegen_->EmitParallelMoves( |
| 3792 | loc.ToLow(), |
| 3793 | loc.ToHigh(), |
| 3794 | Primitive::kPrimInt, |
| 3795 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3796 | loc.ToLow(), |
| 3797 | Primitive::kPrimInt); |
| 3798 | } else if (shift > 32) { |
| 3799 | // Low part becomes 0. High part is low part << (shift-32). |
| 3800 | __ movl(high, low); |
| 3801 | __ shll(high, Immediate(shift - 32)); |
| 3802 | __ xorl(low, low); |
| 3803 | } else { |
| 3804 | // Between 1 and 31. |
| 3805 | __ shld(high, low, Immediate(shift)); |
| 3806 | __ shll(low, Immediate(shift)); |
| 3807 | } |
| 3808 | } |
| 3809 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3810 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3811 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3812 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3813 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3814 | __ testl(shifter, Immediate(32)); |
| 3815 | __ j(kEqual, &done); |
| 3816 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3817 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3818 | __ Bind(&done); |
| 3819 | } |
| 3820 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3821 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3822 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3823 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3824 | if (shift == 32) { |
| 3825 | // Need to copy the sign. |
| 3826 | DCHECK_NE(low, high); |
| 3827 | __ movl(low, high); |
| 3828 | __ sarl(high, Immediate(31)); |
| 3829 | } else if (shift > 32) { |
| 3830 | DCHECK_NE(low, high); |
| 3831 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3832 | __ movl(low, high); |
| 3833 | __ sarl(high, Immediate(31)); |
| 3834 | __ sarl(low, Immediate(shift - 32)); |
| 3835 | } else { |
| 3836 | // Between 1 and 31. |
| 3837 | __ shrd(low, high, Immediate(shift)); |
| 3838 | __ sarl(high, Immediate(shift)); |
| 3839 | } |
| 3840 | } |
| 3841 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3842 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3843 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3844 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3845 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3846 | __ testl(shifter, Immediate(32)); |
| 3847 | __ j(kEqual, &done); |
| 3848 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3849 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3850 | __ Bind(&done); |
| 3851 | } |
| 3852 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3853 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3854 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3855 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3856 | if (shift == 32) { |
| 3857 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3858 | codegen_->EmitParallelMoves( |
| 3859 | loc.ToHigh(), |
| 3860 | loc.ToLow(), |
| 3861 | Primitive::kPrimInt, |
| 3862 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3863 | loc.ToHigh(), |
| 3864 | Primitive::kPrimInt); |
| 3865 | } else if (shift > 32) { |
| 3866 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3867 | __ movl(low, high); |
| 3868 | __ shrl(low, Immediate(shift - 32)); |
| 3869 | __ xorl(high, high); |
| 3870 | } else { |
| 3871 | // Between 1 and 31. |
| 3872 | __ shrd(low, high, Immediate(shift)); |
| 3873 | __ shrl(high, Immediate(shift)); |
| 3874 | } |
| 3875 | } |
| 3876 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3877 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3878 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3879 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3880 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3881 | __ testl(shifter, Immediate(32)); |
| 3882 | __ j(kEqual, &done); |
| 3883 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3884 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3885 | __ Bind(&done); |
| 3886 | } |
| 3887 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3888 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3889 | LocationSummary* locations = |
| 3890 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3891 | |
| 3892 | switch (ror->GetResultType()) { |
| 3893 | case Primitive::kPrimLong: |
| 3894 | // Add the temporary needed. |
| 3895 | locations->AddTemp(Location::RequiresRegister()); |
| 3896 | FALLTHROUGH_INTENDED; |
| 3897 | case Primitive::kPrimInt: |
| 3898 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3899 | // The shift count needs to be in CL (unless it is a constant). |
| 3900 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3901 | locations->SetOut(Location::SameAsFirstInput()); |
| 3902 | break; |
| 3903 | default: |
| 3904 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3905 | UNREACHABLE(); |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3910 | LocationSummary* locations = ror->GetLocations(); |
| 3911 | Location first = locations->InAt(0); |
| 3912 | Location second = locations->InAt(1); |
| 3913 | |
| 3914 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3915 | Register first_reg = first.AsRegister<Register>(); |
| 3916 | if (second.IsRegister()) { |
| 3917 | Register second_reg = second.AsRegister<Register>(); |
| 3918 | __ rorl(first_reg, second_reg); |
| 3919 | } else { |
| 3920 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3921 | __ rorl(first_reg, imm); |
| 3922 | } |
| 3923 | return; |
| 3924 | } |
| 3925 | |
| 3926 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3927 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3928 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3929 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3930 | if (second.IsRegister()) { |
| 3931 | Register second_reg = second.AsRegister<Register>(); |
| 3932 | DCHECK_EQ(second_reg, ECX); |
| 3933 | __ movl(temp_reg, first_reg_hi); |
| 3934 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3935 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3936 | __ movl(temp_reg, first_reg_hi); |
| 3937 | __ testl(second_reg, Immediate(32)); |
| 3938 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3939 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3940 | } else { |
| 3941 | int32_t shift_amt = |
| 3942 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3943 | if (shift_amt == 0) { |
| 3944 | // Already fine. |
| 3945 | return; |
| 3946 | } |
| 3947 | if (shift_amt == 32) { |
| 3948 | // Just swap. |
| 3949 | __ movl(temp_reg, first_reg_lo); |
| 3950 | __ movl(first_reg_lo, first_reg_hi); |
| 3951 | __ movl(first_reg_hi, temp_reg); |
| 3952 | return; |
| 3953 | } |
| 3954 | |
| 3955 | Immediate imm(shift_amt); |
| 3956 | // Save the constents of the low value. |
| 3957 | __ movl(temp_reg, first_reg_lo); |
| 3958 | |
| 3959 | // Shift right into low, feeding bits from high. |
| 3960 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3961 | |
| 3962 | // Shift right into high, feeding bits from the original low. |
| 3963 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3964 | |
| 3965 | // Swap if needed. |
| 3966 | if (shift_amt > 32) { |
| 3967 | __ movl(temp_reg, first_reg_lo); |
| 3968 | __ movl(first_reg_lo, first_reg_hi); |
| 3969 | __ movl(first_reg_hi, temp_reg); |
| 3970 | } |
| 3971 | } |
| 3972 | } |
| 3973 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3974 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3975 | HandleShift(shl); |
| 3976 | } |
| 3977 | |
| 3978 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3979 | HandleShift(shl); |
| 3980 | } |
| 3981 | |
| 3982 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3983 | HandleShift(shr); |
| 3984 | } |
| 3985 | |
| 3986 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3987 | HandleShift(shr); |
| 3988 | } |
| 3989 | |
| 3990 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3991 | HandleShift(ushr); |
| 3992 | } |
| 3993 | |
| 3994 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3995 | HandleShift(ushr); |
| 3996 | } |
| 3997 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3998 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3999 | LocationSummary* locations = |
| 4000 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4001 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4002 | if (instruction->IsStringAlloc()) { |
| 4003 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4004 | } else { |
| 4005 | InvokeRuntimeCallingConvention calling_convention; |
| 4006 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4007 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4008 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
| 4011 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4012 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4013 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4014 | if (instruction->IsStringAlloc()) { |
| 4015 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4016 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4017 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4018 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4019 | __ call(Address(temp, code_offset.Int32Value())); |
| 4020 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4021 | } else { |
| 4022 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4023 | instruction, |
| 4024 | instruction->GetDexPc(), |
| 4025 | nullptr); |
| 4026 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4027 | DCHECK(!codegen_->IsLeafMethod()); |
| 4028 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4029 | } |
| 4030 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4031 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4032 | LocationSummary* locations = |
| 4033 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4034 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4035 | InvokeRuntimeCallingConvention calling_convention; |
| 4036 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4037 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4038 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4039 | } |
| 4040 | |
| 4041 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4042 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4043 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4044 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4045 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4046 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4047 | instruction, |
| 4048 | instruction->GetDexPc(), |
| 4049 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4050 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4051 | DCHECK(!codegen_->IsLeafMethod()); |
| 4052 | } |
| 4053 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4054 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4055 | LocationSummary* locations = |
| 4056 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4057 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4058 | if (location.IsStackSlot()) { |
| 4059 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4060 | } else if (location.IsDoubleStackSlot()) { |
| 4061 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4062 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4063 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4064 | } |
| 4065 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4066 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4067 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4068 | } |
| 4069 | |
| 4070 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4071 | LocationSummary* locations = |
| 4072 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4073 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4074 | } |
| 4075 | |
| 4076 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4079 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4080 | LocationSummary* locations = |
| 4081 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4082 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4083 | locations->SetOut(Location::RequiresRegister()); |
| 4084 | } |
| 4085 | |
| 4086 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4087 | LocationSummary* locations = instruction->GetLocations(); |
| 4088 | uint32_t method_offset = 0; |
| 4089 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4090 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4091 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4092 | } else { |
| 4093 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4094 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4095 | } |
| 4096 | __ movl(locations->Out().AsRegister<Register>(), |
| 4097 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4098 | } |
| 4099 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4100 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4101 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4102 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4103 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4104 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4105 | } |
| 4106 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4107 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4108 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4109 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4110 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4111 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4112 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4113 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4114 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4115 | break; |
| 4116 | |
| 4117 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4118 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4119 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4120 | break; |
| 4121 | |
| 4122 | default: |
| 4123 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4124 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4127 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4128 | LocationSummary* locations = |
| 4129 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4130 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4131 | locations->SetOut(Location::SameAsFirstInput()); |
| 4132 | } |
| 4133 | |
| 4134 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4135 | LocationSummary* locations = bool_not->GetLocations(); |
| 4136 | Location in = locations->InAt(0); |
| 4137 | Location out = locations->Out(); |
| 4138 | DCHECK(in.Equals(out)); |
| 4139 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4140 | } |
| 4141 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4142 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4143 | LocationSummary* locations = |
| 4144 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4145 | switch (compare->InputAt(0)->GetType()) { |
| 4146 | case Primitive::kPrimLong: { |
| 4147 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4148 | locations->SetInAt(1, Location::Any()); |
| 4149 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4150 | break; |
| 4151 | } |
| 4152 | case Primitive::kPrimFloat: |
| 4153 | case Primitive::kPrimDouble: { |
| 4154 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4155 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4156 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4157 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4158 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4159 | } else { |
| 4160 | locations->SetInAt(1, Location::Any()); |
| 4161 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4162 | locations->SetOut(Location::RequiresRegister()); |
| 4163 | break; |
| 4164 | } |
| 4165 | default: |
| 4166 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4167 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4171 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4172 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4173 | Location left = locations->InAt(0); |
| 4174 | Location right = locations->InAt(1); |
| 4175 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4176 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4177 | switch (compare->InputAt(0)->GetType()) { |
| 4178 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4179 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4180 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4181 | int32_t val_low = 0; |
| 4182 | int32_t val_high = 0; |
| 4183 | bool right_is_const = false; |
| 4184 | |
| 4185 | if (right.IsConstant()) { |
| 4186 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4187 | right_is_const = true; |
| 4188 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4189 | val_low = Low32Bits(val); |
| 4190 | val_high = High32Bits(val); |
| 4191 | } |
| 4192 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4193 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4194 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4195 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4196 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4197 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4198 | DCHECK(right_is_const) << right; |
| 4199 | if (val_high == 0) { |
| 4200 | __ testl(left_high, left_high); |
| 4201 | } else { |
| 4202 | __ cmpl(left_high, Immediate(val_high)); |
| 4203 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4204 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4205 | __ j(kLess, &less); // Signed compare. |
| 4206 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4207 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4208 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4209 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4210 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4211 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4212 | DCHECK(right_is_const) << right; |
| 4213 | if (val_low == 0) { |
| 4214 | __ testl(left_low, left_low); |
| 4215 | } else { |
| 4216 | __ cmpl(left_low, Immediate(val_low)); |
| 4217 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4218 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4219 | break; |
| 4220 | } |
| 4221 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4222 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4223 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4224 | break; |
| 4225 | } |
| 4226 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4227 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4228 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4229 | break; |
| 4230 | } |
| 4231 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4232 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4233 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4234 | __ movl(out, Immediate(0)); |
| 4235 | __ j(kEqual, &done); |
| 4236 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4237 | |
| 4238 | __ Bind(&greater); |
| 4239 | __ movl(out, Immediate(1)); |
| 4240 | __ jmp(&done); |
| 4241 | |
| 4242 | __ Bind(&less); |
| 4243 | __ movl(out, Immediate(-1)); |
| 4244 | |
| 4245 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4246 | } |
| 4247 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4248 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4249 | LocationSummary* locations = |
| 4250 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4251 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4252 | locations->SetInAt(i, Location::Any()); |
| 4253 | } |
| 4254 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4255 | } |
| 4256 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4257 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4258 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4259 | } |
| 4260 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4261 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4262 | /* |
| 4263 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4264 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4265 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4266 | */ |
| 4267 | switch (kind) { |
| 4268 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4269 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4270 | break; |
| 4271 | } |
| 4272 | case MemBarrierKind::kAnyStore: |
| 4273 | case MemBarrierKind::kLoadAny: |
| 4274 | case MemBarrierKind::kStoreStore: { |
| 4275 | // nop |
| 4276 | break; |
| 4277 | } |
| 4278 | default: |
| 4279 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4280 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4281 | } |
| 4282 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4283 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4284 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4285 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4286 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4287 | |
| 4288 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4289 | // is incompatible with it. |
| 4290 | if (GetGraph()->HasIrreducibleLoops() && |
| 4291 | (dispatch_info.method_load_kind == |
| 4292 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4293 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4294 | } |
| 4295 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4296 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4297 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4298 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4299 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4300 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4301 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4302 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4303 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4304 | 0u |
| 4305 | }; |
| 4306 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4307 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4308 | } |
| 4309 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4310 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4311 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4312 | Register temp) { |
| 4313 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4314 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4315 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4316 | return location.AsRegister<Register>(); |
| 4317 | } |
| 4318 | // For intrinsics we allow any location, so it may be on the stack. |
| 4319 | if (!location.IsRegister()) { |
| 4320 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4321 | return temp; |
| 4322 | } |
| 4323 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4324 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4325 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4326 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4327 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4328 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4329 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4330 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4331 | __ movl(temp, Address(ESP, stack_offset)); |
| 4332 | return temp; |
| 4333 | } |
| 4334 | return location.AsRegister<Register>(); |
| 4335 | } |
| 4336 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4337 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4338 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4339 | switch (invoke->GetMethodLoadKind()) { |
| 4340 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4341 | // temp = thread->string_init_entrypoint |
| 4342 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4343 | break; |
| 4344 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4345 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4346 | break; |
| 4347 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4348 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4349 | break; |
| 4350 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4351 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4352 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4353 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4354 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4355 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4356 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4357 | temp.AsRegister<Register>()); |
| 4358 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4359 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4360 | // Add the patch entry and bind its label at the end of the instruction. |
| 4361 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4362 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4363 | break; |
| 4364 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4365 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4366 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4367 | Register method_reg; |
| 4368 | Register reg = temp.AsRegister<Register>(); |
| 4369 | if (current_method.IsRegister()) { |
| 4370 | method_reg = current_method.AsRegister<Register>(); |
| 4371 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4372 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4373 | DCHECK(!current_method.IsValid()); |
| 4374 | method_reg = reg; |
| 4375 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4376 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4377 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4378 | __ movl(reg, Address(method_reg, |
| 4379 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4380 | // temp = temp[index_in_cache] |
| 4381 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4382 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4383 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4384 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | switch (invoke->GetCodePtrLocation()) { |
| 4388 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4389 | __ call(GetFrameEntryLabel()); |
| 4390 | break; |
| 4391 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4392 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4393 | Label* label = &relative_call_patches_.back().label; |
| 4394 | __ call(label); // Bind to the patch label, override at link time. |
| 4395 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4396 | break; |
| 4397 | } |
| 4398 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4399 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4400 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4401 | LOG(FATAL) << "Unsupported"; |
| 4402 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4403 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4404 | // (callee_method + offset_of_quick_compiled_code)() |
| 4405 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4406 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4407 | kX86WordSize).Int32Value())); |
| 4408 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4412 | } |
| 4413 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4414 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4415 | Register temp = temp_in.AsRegister<Register>(); |
| 4416 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4417 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4418 | |
| 4419 | // Use the calling convention instead of the location of the receiver, as |
| 4420 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4421 | // slow path, the arguments have been moved to the right place, so here we are |
| 4422 | // guaranteed that the receiver is the first register of the calling convention. |
| 4423 | InvokeDexCallingConvention calling_convention; |
| 4424 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4425 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4426 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4427 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4428 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4429 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4430 | // emit a read barrier for the previous class reference load. |
| 4431 | // However this is not required in practice, as this is an |
| 4432 | // intermediate/temporary reference and because the current |
| 4433 | // concurrent copying collector keeps the from-space memory |
| 4434 | // intact/accessible until the end of the marking phase (the |
| 4435 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4436 | __ MaybeUnpoisonHeapReference(temp); |
| 4437 | // temp = temp->GetMethodAt(method_offset); |
| 4438 | __ movl(temp, Address(temp, method_offset)); |
| 4439 | // call temp->GetEntryPoint(); |
| 4440 | __ call(Address( |
| 4441 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4442 | } |
| 4443 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4444 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4445 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4446 | size_t size = |
| 4447 | method_patches_.size() + |
| 4448 | relative_call_patches_.size() + |
| 4449 | pc_relative_dex_cache_patches_.size(); |
| 4450 | linker_patches->reserve(size); |
| 4451 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4452 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4453 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4454 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4455 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4456 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4457 | info.target_method.dex_file, |
| 4458 | info.target_method.dex_method_index)); |
| 4459 | } |
| 4460 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4461 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4462 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4463 | info.target_method.dex_file, |
| 4464 | info.target_method.dex_method_index)); |
| 4465 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4466 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4467 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4468 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4469 | &info.target_dex_file, |
| 4470 | GetMethodAddressOffset(), |
| 4471 | info.element_offset)); |
| 4472 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4473 | } |
| 4474 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4475 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4476 | Register card, |
| 4477 | Register object, |
| 4478 | Register value, |
| 4479 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4480 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4481 | if (value_can_be_null) { |
| 4482 | __ testl(value, value); |
| 4483 | __ j(kEqual, &is_null); |
| 4484 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4485 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4486 | __ movl(temp, object); |
| 4487 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4488 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4489 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4490 | if (value_can_be_null) { |
| 4491 | __ Bind(&is_null); |
| 4492 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4495 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4496 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4497 | |
| 4498 | bool object_field_get_with_read_barrier = |
| 4499 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4500 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4501 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4502 | kEmitCompilerReadBarrier ? |
| 4503 | LocationSummary::kCallOnSlowPath : |
| 4504 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4505 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4506 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4507 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4508 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4509 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4510 | // The output overlaps in case of long: we don't want the low move |
| 4511 | // to overwrite the object's location. Likewise, in the case of |
| 4512 | // an object field get with read barriers enabled, we do not want |
| 4513 | // the move to overwrite the object's location, as we need it to emit |
| 4514 | // the read barrier. |
| 4515 | locations->SetOut( |
| 4516 | Location::RequiresRegister(), |
| 4517 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4518 | Location::kOutputOverlap : |
| 4519 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4520 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4521 | |
| 4522 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4523 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4524 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4525 | // load the temp into the XMM and then copy the XMM into the |
| 4526 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4527 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4528 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4529 | // We need a temporary register for the read barrier marking slow |
| 4530 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4531 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4533 | } |
| 4534 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4536 | const FieldInfo& field_info) { |
| 4537 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4538 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4539 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4540 | Location base_loc = locations->InAt(0); |
| 4541 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4542 | Location out = locations->Out(); |
| 4543 | bool is_volatile = field_info.IsVolatile(); |
| 4544 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4545 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4546 | |
| 4547 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4548 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4549 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4550 | break; |
| 4551 | } |
| 4552 | |
| 4553 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4555 | break; |
| 4556 | } |
| 4557 | |
| 4558 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4560 | break; |
| 4561 | } |
| 4562 | |
| 4563 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4564 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4565 | break; |
| 4566 | } |
| 4567 | |
| 4568 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4569 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4570 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4571 | |
| 4572 | case Primitive::kPrimNot: { |
| 4573 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4574 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4575 | Location temp_loc = locations->GetTemp(0); |
| 4576 | // Note that a potential implicit null check is handled in this |
| 4577 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4578 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4579 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4580 | if (is_volatile) { |
| 4581 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4582 | } |
| 4583 | } else { |
| 4584 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4585 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4586 | if (is_volatile) { |
| 4587 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4588 | } |
| 4589 | // If read barriers are enabled, emit read barriers other than |
| 4590 | // Baker's using a slow path (and also unpoison the loaded |
| 4591 | // reference, if heap poisoning is enabled). |
| 4592 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4593 | } |
| 4594 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4598 | if (is_volatile) { |
| 4599 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4600 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4601 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4602 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4603 | __ psrlq(temp, Immediate(32)); |
| 4604 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4605 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4606 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4607 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4608 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4609 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4610 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4611 | break; |
| 4612 | } |
| 4613 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4614 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4615 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4616 | break; |
| 4617 | } |
| 4618 | |
| 4619 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4620 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4621 | break; |
| 4622 | } |
| 4623 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4624 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4625 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4626 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4627 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4628 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4629 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4630 | // Potential implicit null checks, in the case of reference or |
| 4631 | // long fields, are handled in the previous switch statement. |
| 4632 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4633 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4634 | } |
| 4635 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4636 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4637 | if (field_type == Primitive::kPrimNot) { |
| 4638 | // Memory barriers, in the case of references, are also handled |
| 4639 | // in the previous switch statement. |
| 4640 | } else { |
| 4641 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4642 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4643 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4647 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4648 | |
| 4649 | LocationSummary* locations = |
| 4650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4652 | bool is_volatile = field_info.IsVolatile(); |
| 4653 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4654 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4655 | || (field_type == Primitive::kPrimByte); |
| 4656 | |
| 4657 | // The register allocator does not support multiple |
| 4658 | // inputs that die at entry with one in a specific register. |
| 4659 | if (is_byte_type) { |
| 4660 | // Ensure the value is in a byte register. |
| 4661 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4662 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4663 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4664 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4665 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4666 | } else { |
| 4667 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4668 | } |
| 4669 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4670 | // 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] | 4671 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4672 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4673 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4674 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4675 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4676 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4677 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4678 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4679 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4680 | } else { |
| 4681 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4682 | |
| 4683 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4684 | // Temporary registers for the write barrier. |
| 4685 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4686 | // Ensure the card is in a byte register. |
| 4687 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4688 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4693 | const FieldInfo& field_info, |
| 4694 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4695 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4696 | |
| 4697 | LocationSummary* locations = instruction->GetLocations(); |
| 4698 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4699 | Location value = locations->InAt(1); |
| 4700 | bool is_volatile = field_info.IsVolatile(); |
| 4701 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4702 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4703 | bool needs_write_barrier = |
| 4704 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4705 | |
| 4706 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4707 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4710 | bool maybe_record_implicit_null_check_done = false; |
| 4711 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4712 | switch (field_type) { |
| 4713 | case Primitive::kPrimBoolean: |
| 4714 | case Primitive::kPrimByte: { |
| 4715 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4716 | break; |
| 4717 | } |
| 4718 | |
| 4719 | case Primitive::kPrimShort: |
| 4720 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4721 | if (value.IsConstant()) { |
| 4722 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4723 | __ movw(Address(base, offset), Immediate(v)); |
| 4724 | } else { |
| 4725 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4726 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4727 | break; |
| 4728 | } |
| 4729 | |
| 4730 | case Primitive::kPrimInt: |
| 4731 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4732 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4733 | // Note that in the case where `value` is a null reference, |
| 4734 | // we do not enter this block, as the reference does not |
| 4735 | // need poisoning. |
| 4736 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4737 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4738 | __ movl(temp, value.AsRegister<Register>()); |
| 4739 | __ PoisonHeapReference(temp); |
| 4740 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4741 | } else if (value.IsConstant()) { |
| 4742 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4743 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4744 | } else { |
| 4745 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4746 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4747 | break; |
| 4748 | } |
| 4749 | |
| 4750 | case Primitive::kPrimLong: { |
| 4751 | if (is_volatile) { |
| 4752 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4753 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4754 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4755 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4756 | __ punpckldq(temp1, temp2); |
| 4757 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4758 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4759 | } else if (value.IsConstant()) { |
| 4760 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4761 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4762 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4763 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4764 | } else { |
| 4765 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4766 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4767 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4768 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4769 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 | break; |
| 4771 | } |
| 4772 | |
| 4773 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4774 | if (value.IsConstant()) { |
| 4775 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4776 | __ movl(Address(base, offset), Immediate(v)); |
| 4777 | } else { |
| 4778 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4779 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4780 | break; |
| 4781 | } |
| 4782 | |
| 4783 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4784 | if (value.IsConstant()) { |
| 4785 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4786 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4787 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4788 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4789 | maybe_record_implicit_null_check_done = true; |
| 4790 | } else { |
| 4791 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4792 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4793 | break; |
| 4794 | } |
| 4795 | |
| 4796 | case Primitive::kPrimVoid: |
| 4797 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4798 | UNREACHABLE(); |
| 4799 | } |
| 4800 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4801 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4802 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4803 | } |
| 4804 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4805 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4806 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4807 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4808 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4809 | } |
| 4810 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4811 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4812 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4813 | } |
| 4814 | } |
| 4815 | |
| 4816 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4817 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4818 | } |
| 4819 | |
| 4820 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4821 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4822 | } |
| 4823 | |
| 4824 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4825 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4826 | } |
| 4827 | |
| 4828 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4829 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4830 | } |
| 4831 | |
| 4832 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4833 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4834 | } |
| 4835 | |
| 4836 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4837 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4841 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4842 | } |
| 4843 | |
| 4844 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4845 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4846 | } |
| 4847 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4848 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4849 | HUnresolvedInstanceFieldGet* instruction) { |
| 4850 | FieldAccessCallingConventionX86 calling_convention; |
| 4851 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4852 | instruction, instruction->GetFieldType(), calling_convention); |
| 4853 | } |
| 4854 | |
| 4855 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4856 | HUnresolvedInstanceFieldGet* instruction) { |
| 4857 | FieldAccessCallingConventionX86 calling_convention; |
| 4858 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4859 | instruction->GetFieldType(), |
| 4860 | instruction->GetFieldIndex(), |
| 4861 | instruction->GetDexPc(), |
| 4862 | calling_convention); |
| 4863 | } |
| 4864 | |
| 4865 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4866 | HUnresolvedInstanceFieldSet* instruction) { |
| 4867 | FieldAccessCallingConventionX86 calling_convention; |
| 4868 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4869 | instruction, instruction->GetFieldType(), calling_convention); |
| 4870 | } |
| 4871 | |
| 4872 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4873 | HUnresolvedInstanceFieldSet* instruction) { |
| 4874 | FieldAccessCallingConventionX86 calling_convention; |
| 4875 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4876 | instruction->GetFieldType(), |
| 4877 | instruction->GetFieldIndex(), |
| 4878 | instruction->GetDexPc(), |
| 4879 | calling_convention); |
| 4880 | } |
| 4881 | |
| 4882 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4883 | HUnresolvedStaticFieldGet* instruction) { |
| 4884 | FieldAccessCallingConventionX86 calling_convention; |
| 4885 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4886 | instruction, instruction->GetFieldType(), calling_convention); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4890 | HUnresolvedStaticFieldGet* instruction) { |
| 4891 | FieldAccessCallingConventionX86 calling_convention; |
| 4892 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4893 | instruction->GetFieldType(), |
| 4894 | instruction->GetFieldIndex(), |
| 4895 | instruction->GetDexPc(), |
| 4896 | calling_convention); |
| 4897 | } |
| 4898 | |
| 4899 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4900 | HUnresolvedStaticFieldSet* instruction) { |
| 4901 | FieldAccessCallingConventionX86 calling_convention; |
| 4902 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4903 | instruction, instruction->GetFieldType(), calling_convention); |
| 4904 | } |
| 4905 | |
| 4906 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4907 | HUnresolvedStaticFieldSet* instruction) { |
| 4908 | FieldAccessCallingConventionX86 calling_convention; |
| 4909 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4910 | instruction->GetFieldType(), |
| 4911 | instruction->GetFieldIndex(), |
| 4912 | instruction->GetDexPc(), |
| 4913 | calling_convention); |
| 4914 | } |
| 4915 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4916 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4917 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4918 | ? LocationSummary::kCallOnSlowPath |
| 4919 | : LocationSummary::kNoCall; |
| 4920 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4921 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4922 | ? Location::RequiresRegister() |
| 4923 | : Location::Any(); |
| 4924 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4925 | if (instruction->HasUses()) { |
| 4926 | locations->SetOut(Location::SameAsFirstInput()); |
| 4927 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4928 | } |
| 4929 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4930 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4931 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4932 | return; |
| 4933 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4934 | LocationSummary* locations = instruction->GetLocations(); |
| 4935 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4936 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4937 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4938 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4939 | } |
| 4940 | |
| 4941 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4942 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4943 | codegen_->AddSlowPath(slow_path); |
| 4944 | |
| 4945 | LocationSummary* locations = instruction->GetLocations(); |
| 4946 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4947 | |
| 4948 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4949 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4950 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4951 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4952 | } else { |
| 4953 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4954 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4955 | __ jmp(slow_path->GetEntryLabel()); |
| 4956 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4957 | } |
| 4958 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4959 | } |
| 4960 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4961 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4962 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4963 | GenerateImplicitNullCheck(instruction); |
| 4964 | } else { |
| 4965 | GenerateExplicitNullCheck(instruction); |
| 4966 | } |
| 4967 | } |
| 4968 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4969 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4970 | bool object_array_get_with_read_barrier = |
| 4971 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4972 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4973 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4974 | object_array_get_with_read_barrier ? |
| 4975 | LocationSummary::kCallOnSlowPath : |
| 4976 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4977 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4978 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4979 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4980 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4981 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4982 | // The output overlaps in case of long: we don't want the low move |
| 4983 | // to overwrite the array's location. Likewise, in the case of an |
| 4984 | // object array get with read barriers enabled, we do not want the |
| 4985 | // move to overwrite the array's location, as we need it to emit |
| 4986 | // the read barrier. |
| 4987 | locations->SetOut( |
| 4988 | Location::RequiresRegister(), |
| 4989 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4990 | Location::kOutputOverlap : |
| 4991 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4992 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4993 | // We need a temporary register for the read barrier marking slow |
| 4994 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4995 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4996 | locations->AddTemp(Location::RequiresRegister()); |
| 4997 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5001 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5002 | Location obj_loc = locations->InAt(0); |
| 5003 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5004 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5005 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5006 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5007 | Primitive::Type type = instruction->GetType(); |
| 5008 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5009 | case Primitive::kPrimBoolean: { |
| 5010 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5011 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5012 | if (index.IsConstant()) { |
| 5013 | __ movzxb(out, Address(obj, |
| 5014 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5015 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5016 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5017 | } |
| 5018 | break; |
| 5019 | } |
| 5020 | |
| 5021 | case Primitive::kPrimByte: { |
| 5022 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5023 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5024 | if (index.IsConstant()) { |
| 5025 | __ movsxb(out, Address(obj, |
| 5026 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5027 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5028 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | } |
| 5030 | break; |
| 5031 | } |
| 5032 | |
| 5033 | case Primitive::kPrimShort: { |
| 5034 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5035 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5036 | if (index.IsConstant()) { |
| 5037 | __ movsxw(out, Address(obj, |
| 5038 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5039 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5040 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5041 | } |
| 5042 | break; |
| 5043 | } |
| 5044 | |
| 5045 | case Primitive::kPrimChar: { |
| 5046 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5047 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5048 | if (index.IsConstant()) { |
| 5049 | __ movzxw(out, Address(obj, |
| 5050 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5051 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5052 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5053 | } |
| 5054 | break; |
| 5055 | } |
| 5056 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5057 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5058 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5059 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5060 | if (index.IsConstant()) { |
| 5061 | __ movl(out, Address(obj, |
| 5062 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5063 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5064 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5065 | } |
| 5066 | break; |
| 5067 | } |
| 5068 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5069 | case Primitive::kPrimNot: { |
| 5070 | static_assert( |
| 5071 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5072 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5073 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5074 | // /* HeapReference<Object> */ out = |
| 5075 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5076 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5077 | Location temp = locations->GetTemp(0); |
| 5078 | // Note that a potential implicit null check is handled in this |
| 5079 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5080 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5081 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5082 | } else { |
| 5083 | Register out = out_loc.AsRegister<Register>(); |
| 5084 | if (index.IsConstant()) { |
| 5085 | uint32_t offset = |
| 5086 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5087 | __ movl(out, Address(obj, offset)); |
| 5088 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5089 | // If read barriers are enabled, emit read barriers other than |
| 5090 | // Baker's using a slow path (and also unpoison the loaded |
| 5091 | // reference, if heap poisoning is enabled). |
| 5092 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5093 | } else { |
| 5094 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5095 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5096 | // If read barriers are enabled, emit read barriers other than |
| 5097 | // Baker's using a slow path (and also unpoison the loaded |
| 5098 | // reference, if heap poisoning is enabled). |
| 5099 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5100 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5101 | } |
| 5102 | } |
| 5103 | break; |
| 5104 | } |
| 5105 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5106 | case Primitive::kPrimLong: { |
| 5107 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5108 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5109 | if (index.IsConstant()) { |
| 5110 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5111 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5112 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5113 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5114 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5115 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5116 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5117 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5118 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5119 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5120 | } |
| 5121 | break; |
| 5122 | } |
| 5123 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5124 | case Primitive::kPrimFloat: { |
| 5125 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5126 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5127 | if (index.IsConstant()) { |
| 5128 | __ movss(out, Address(obj, |
| 5129 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5130 | } else { |
| 5131 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5132 | } |
| 5133 | break; |
| 5134 | } |
| 5135 | |
| 5136 | case Primitive::kPrimDouble: { |
| 5137 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5138 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5139 | if (index.IsConstant()) { |
| 5140 | __ movsd(out, Address(obj, |
| 5141 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5142 | } else { |
| 5143 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5144 | } |
| 5145 | break; |
| 5146 | } |
| 5147 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5148 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5149 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5150 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5151 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5152 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5153 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5154 | // Potential implicit null checks, in the case of reference or |
| 5155 | // long arrays, are handled in the previous switch statement. |
| 5156 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5157 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5158 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5162 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5163 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5164 | bool needs_write_barrier = |
| 5165 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5166 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5167 | bool object_array_set_with_read_barrier = |
| 5168 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5169 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5170 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5171 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5172 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5173 | LocationSummary::kCallOnSlowPath : |
| 5174 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5175 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5176 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5177 | || (value_type == Primitive::kPrimByte); |
| 5178 | // We need the inputs to be different than the output in case of long operation. |
| 5179 | // In case of a byte operation, the register allocator does not support multiple |
| 5180 | // inputs that die at entry with one in a specific register. |
| 5181 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5182 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5183 | if (is_byte_type) { |
| 5184 | // Ensure the value is in a byte register. |
| 5185 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5186 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5187 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5188 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5189 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5190 | } |
| 5191 | if (needs_write_barrier) { |
| 5192 | // Temporary registers for the write barrier. |
| 5193 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5194 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5195 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5196 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5200 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5201 | Location array_loc = locations->InAt(0); |
| 5202 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5203 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5204 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5205 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5206 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5207 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5208 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5209 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5210 | bool needs_write_barrier = |
| 5211 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5212 | |
| 5213 | switch (value_type) { |
| 5214 | case Primitive::kPrimBoolean: |
| 5215 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5216 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5217 | Address address = index.IsConstant() |
| 5218 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5219 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5220 | if (value.IsRegister()) { |
| 5221 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5222 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5223 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5224 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5225 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5226 | break; |
| 5227 | } |
| 5228 | |
| 5229 | case Primitive::kPrimShort: |
| 5230 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5231 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5232 | Address address = index.IsConstant() |
| 5233 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5234 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5235 | if (value.IsRegister()) { |
| 5236 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5237 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5238 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5239 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5240 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5241 | break; |
| 5242 | } |
| 5243 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5244 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5245 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5246 | Address address = index.IsConstant() |
| 5247 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5248 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5249 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5250 | if (!value.IsRegister()) { |
| 5251 | // Just setting null. |
| 5252 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5253 | DCHECK(value.IsConstant()) << value; |
| 5254 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5255 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5256 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5257 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5258 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5259 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5260 | |
| 5261 | DCHECK(needs_write_barrier); |
| 5262 | Register register_value = value.AsRegister<Register>(); |
| 5263 | NearLabel done, not_null, do_put; |
| 5264 | SlowPathCode* slow_path = nullptr; |
| 5265 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5266 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5267 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5268 | codegen_->AddSlowPath(slow_path); |
| 5269 | if (instruction->GetValueCanBeNull()) { |
| 5270 | __ testl(register_value, register_value); |
| 5271 | __ j(kNotEqual, ¬_null); |
| 5272 | __ movl(address, Immediate(0)); |
| 5273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5274 | __ jmp(&done); |
| 5275 | __ Bind(¬_null); |
| 5276 | } |
| 5277 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5278 | if (kEmitCompilerReadBarrier) { |
| 5279 | // When read barriers are enabled, the type checking |
| 5280 | // instrumentation requires two read barriers: |
| 5281 | // |
| 5282 | // __ movl(temp2, temp); |
| 5283 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5284 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5285 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5286 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5287 | // |
| 5288 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5289 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5290 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5291 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5292 | // |
| 5293 | // __ cmpl(temp, temp2); |
| 5294 | // |
| 5295 | // However, the second read barrier may trash `temp`, as it |
| 5296 | // is a temporary register, and as such would not be saved |
| 5297 | // along with live registers before calling the runtime (nor |
| 5298 | // restored afterwards). So in this case, we bail out and |
| 5299 | // delegate the work to the array set slow path. |
| 5300 | // |
| 5301 | // TODO: Extend the register allocator to support a new |
| 5302 | // "(locally) live temp" location so as to avoid always |
| 5303 | // going into the slow path when read barriers are enabled. |
| 5304 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5306 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5307 | __ movl(temp, Address(array, class_offset)); |
| 5308 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5309 | __ MaybeUnpoisonHeapReference(temp); |
| 5310 | |
| 5311 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5312 | __ movl(temp, Address(temp, component_offset)); |
| 5313 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5314 | // nor the object reference in `register_value->klass`, as |
| 5315 | // we are comparing two poisoned references. |
| 5316 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5317 | |
| 5318 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5319 | __ j(kEqual, &do_put); |
| 5320 | // If heap poisoning is enabled, the `temp` reference has |
| 5321 | // not been unpoisoned yet; unpoison it now. |
| 5322 | __ MaybeUnpoisonHeapReference(temp); |
| 5323 | |
| 5324 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5325 | __ movl(temp, Address(temp, super_offset)); |
| 5326 | // If heap poisoning is enabled, no need to unpoison |
| 5327 | // `temp`, as we are comparing against null below. |
| 5328 | __ testl(temp, temp); |
| 5329 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5330 | __ Bind(&do_put); |
| 5331 | } else { |
| 5332 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5333 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5334 | } |
| 5335 | } |
| 5336 | |
| 5337 | if (kPoisonHeapReferences) { |
| 5338 | __ movl(temp, register_value); |
| 5339 | __ PoisonHeapReference(temp); |
| 5340 | __ movl(address, temp); |
| 5341 | } else { |
| 5342 | __ movl(address, register_value); |
| 5343 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5344 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5346 | } |
| 5347 | |
| 5348 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5349 | codegen_->MarkGCCard( |
| 5350 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5351 | __ Bind(&done); |
| 5352 | |
| 5353 | if (slow_path != nullptr) { |
| 5354 | __ Bind(slow_path->GetExitLabel()); |
| 5355 | } |
| 5356 | |
| 5357 | break; |
| 5358 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5359 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5360 | case Primitive::kPrimInt: { |
| 5361 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5362 | Address address = index.IsConstant() |
| 5363 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5364 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5365 | if (value.IsRegister()) { |
| 5366 | __ movl(address, value.AsRegister<Register>()); |
| 5367 | } else { |
| 5368 | DCHECK(value.IsConstant()) << value; |
| 5369 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5370 | __ movl(address, Immediate(v)); |
| 5371 | } |
| 5372 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5373 | break; |
| 5374 | } |
| 5375 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5376 | case Primitive::kPrimLong: { |
| 5377 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5378 | if (index.IsConstant()) { |
| 5379 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5380 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5381 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5382 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5383 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5384 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5385 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5386 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5387 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5388 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5389 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5390 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5391 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5392 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5393 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5394 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5395 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5396 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5397 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5398 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5399 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5400 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5401 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5402 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5403 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5405 | Immediate(High32Bits(val))); |
| 5406 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5407 | } |
| 5408 | break; |
| 5409 | } |
| 5410 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5411 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5412 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5413 | Address address = index.IsConstant() |
| 5414 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5415 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5416 | if (value.IsFpuRegister()) { |
| 5417 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5418 | } else { |
| 5419 | DCHECK(value.IsConstant()); |
| 5420 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5421 | __ movl(address, Immediate(v)); |
| 5422 | } |
| 5423 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5424 | break; |
| 5425 | } |
| 5426 | |
| 5427 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5428 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5429 | Address address = index.IsConstant() |
| 5430 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5431 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5432 | if (value.IsFpuRegister()) { |
| 5433 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5434 | } else { |
| 5435 | DCHECK(value.IsConstant()); |
| 5436 | Address address_hi = index.IsConstant() ? |
| 5437 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5438 | offset + kX86WordSize) : |
| 5439 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5440 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5441 | __ movl(address, Immediate(Low32Bits(v))); |
| 5442 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5443 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5444 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5445 | break; |
| 5446 | } |
| 5447 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5448 | case Primitive::kPrimVoid: |
| 5449 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5450 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5455 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5456 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5457 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5461 | LocationSummary* locations = instruction->GetLocations(); |
| 5462 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5463 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5464 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5465 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5466 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5467 | } |
| 5468 | |
| 5469 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5470 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5471 | ? LocationSummary::kCallOnSlowPath |
| 5472 | : LocationSummary::kNoCall; |
| 5473 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5474 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5475 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5476 | if (instruction->HasUses()) { |
| 5477 | locations->SetOut(Location::SameAsFirstInput()); |
| 5478 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5482 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5483 | Location index_loc = locations->InAt(0); |
| 5484 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5485 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5486 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5487 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5488 | if (length_loc.IsConstant()) { |
| 5489 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5490 | if (index_loc.IsConstant()) { |
| 5491 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5492 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5493 | if (index < 0 || index >= length) { |
| 5494 | codegen_->AddSlowPath(slow_path); |
| 5495 | __ jmp(slow_path->GetEntryLabel()); |
| 5496 | } else { |
| 5497 | // Some optimization after BCE may have generated this, and we should not |
| 5498 | // generate a bounds check if it is a valid range. |
| 5499 | } |
| 5500 | return; |
| 5501 | } |
| 5502 | |
| 5503 | // We have to reverse the jump condition because the length is the constant. |
| 5504 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5505 | __ cmpl(index_reg, Immediate(length)); |
| 5506 | codegen_->AddSlowPath(slow_path); |
| 5507 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5508 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5509 | Register length = length_loc.AsRegister<Register>(); |
| 5510 | if (index_loc.IsConstant()) { |
| 5511 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5512 | __ cmpl(length, Immediate(value)); |
| 5513 | } else { |
| 5514 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5515 | } |
| 5516 | codegen_->AddSlowPath(slow_path); |
| 5517 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5518 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5519 | } |
| 5520 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5521 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5522 | temp->SetLocations(nullptr); |
| 5523 | } |
| 5524 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5525 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5526 | // Nothing to do, this is driven by the code generator. |
| 5527 | } |
| 5528 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5529 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5530 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5534 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5535 | } |
| 5536 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5537 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5538 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5539 | } |
| 5540 | |
| 5541 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5542 | HBasicBlock* block = instruction->GetBlock(); |
| 5543 | if (block->GetLoopInformation() != nullptr) { |
| 5544 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5545 | // The back edge will generate the suspend check. |
| 5546 | return; |
| 5547 | } |
| 5548 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5549 | // The goto will generate the suspend check. |
| 5550 | return; |
| 5551 | } |
| 5552 | GenerateSuspendCheck(instruction, nullptr); |
| 5553 | } |
| 5554 | |
| 5555 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5556 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5557 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5558 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5559 | if (slow_path == nullptr) { |
| 5560 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5561 | instruction->SetSlowPath(slow_path); |
| 5562 | codegen_->AddSlowPath(slow_path); |
| 5563 | if (successor != nullptr) { |
| 5564 | DCHECK(successor->IsLoopHeader()); |
| 5565 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5566 | } |
| 5567 | } else { |
| 5568 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5569 | } |
| 5570 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5571 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5572 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5573 | if (successor == nullptr) { |
| 5574 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5575 | __ Bind(slow_path->GetReturnLabel()); |
| 5576 | } else { |
| 5577 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5578 | __ jmp(slow_path->GetEntryLabel()); |
| 5579 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5580 | } |
| 5581 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5582 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5583 | return codegen_->GetAssembler(); |
| 5584 | } |
| 5585 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5586 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5587 | ScratchRegisterScope ensure_scratch( |
| 5588 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5589 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5590 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5591 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5592 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5593 | } |
| 5594 | |
| 5595 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5596 | ScratchRegisterScope ensure_scratch( |
| 5597 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5598 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5599 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5600 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5601 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5602 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5603 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5607 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5608 | Location source = move->GetSource(); |
| 5609 | Location destination = move->GetDestination(); |
| 5610 | |
| 5611 | if (source.IsRegister()) { |
| 5612 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5613 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5614 | } else if (destination.IsFpuRegister()) { |
| 5615 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5616 | } else { |
| 5617 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5618 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5619 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5620 | } else if (source.IsRegisterPair()) { |
| 5621 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5622 | // Create stack space for 2 elements. |
| 5623 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5624 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5625 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5626 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5627 | // And remove the temporary stack space we allocated. |
| 5628 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5629 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5630 | if (destination.IsRegister()) { |
| 5631 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5632 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5633 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5634 | } else if (destination.IsRegisterPair()) { |
| 5635 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5636 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5637 | __ psrlq(src_reg, Immediate(32)); |
| 5638 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5639 | } else if (destination.IsStackSlot()) { |
| 5640 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5641 | } else { |
| 5642 | DCHECK(destination.IsDoubleStackSlot()); |
| 5643 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5644 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5645 | } else if (source.IsStackSlot()) { |
| 5646 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5647 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5648 | } else if (destination.IsFpuRegister()) { |
| 5649 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5650 | } else { |
| 5651 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5652 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5653 | } |
| 5654 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5655 | if (destination.IsRegisterPair()) { |
| 5656 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5657 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5658 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5659 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5660 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5661 | } else { |
| 5662 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5663 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5664 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5665 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5666 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5667 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5668 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5669 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5670 | if (value == 0) { |
| 5671 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5672 | } else { |
| 5673 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5674 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5675 | } else { |
| 5676 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5677 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5678 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5679 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5680 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5681 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5682 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5683 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5684 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5685 | if (value == 0) { |
| 5686 | // Easy handling of 0.0. |
| 5687 | __ xorps(dest, dest); |
| 5688 | } else { |
| 5689 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5690 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5691 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5692 | __ movl(temp, Immediate(value)); |
| 5693 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5694 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5695 | } else { |
| 5696 | DCHECK(destination.IsStackSlot()) << destination; |
| 5697 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5698 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5699 | } else if (constant->IsLongConstant()) { |
| 5700 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5701 | int32_t low_value = Low32Bits(value); |
| 5702 | int32_t high_value = High32Bits(value); |
| 5703 | Immediate low(low_value); |
| 5704 | Immediate high(high_value); |
| 5705 | if (destination.IsDoubleStackSlot()) { |
| 5706 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5707 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5708 | } else { |
| 5709 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5710 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5711 | } |
| 5712 | } else { |
| 5713 | DCHECK(constant->IsDoubleConstant()); |
| 5714 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5715 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5716 | int32_t low_value = Low32Bits(value); |
| 5717 | int32_t high_value = High32Bits(value); |
| 5718 | Immediate low(low_value); |
| 5719 | Immediate high(high_value); |
| 5720 | if (destination.IsFpuRegister()) { |
| 5721 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5722 | if (value == 0) { |
| 5723 | // Easy handling of 0.0. |
| 5724 | __ xorpd(dest, dest); |
| 5725 | } else { |
| 5726 | __ pushl(high); |
| 5727 | __ pushl(low); |
| 5728 | __ movsd(dest, Address(ESP, 0)); |
| 5729 | __ addl(ESP, Immediate(8)); |
| 5730 | } |
| 5731 | } else { |
| 5732 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5733 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5734 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5735 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5736 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5737 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5738 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5739 | } |
| 5740 | } |
| 5741 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5742 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5743 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5744 | ScratchRegisterScope ensure_scratch( |
| 5745 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5746 | |
| 5747 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5748 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5749 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5750 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5751 | } |
| 5752 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5753 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5754 | ScratchRegisterScope ensure_scratch( |
| 5755 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5756 | |
| 5757 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5758 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5759 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5760 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5761 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5762 | } |
| 5763 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5764 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5765 | ScratchRegisterScope ensure_scratch1( |
| 5766 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5767 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5768 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5769 | ScratchRegisterScope ensure_scratch2( |
| 5770 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5771 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5772 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5773 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5774 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5775 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5776 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5777 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5781 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5782 | Location source = move->GetSource(); |
| 5783 | Location destination = move->GetDestination(); |
| 5784 | |
| 5785 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5786 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5787 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5788 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5789 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5790 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5791 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5792 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5793 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5794 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5795 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5796 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5797 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5798 | // Use XOR Swap algorithm to avoid a temporary. |
| 5799 | DCHECK_NE(source.reg(), destination.reg()); |
| 5800 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5801 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5802 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5803 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5804 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5805 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5806 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5807 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5808 | // Take advantage of the 16 bytes in the XMM register. |
| 5809 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5810 | Address stack(ESP, destination.GetStackIndex()); |
| 5811 | // Load the double into the high doubleword. |
| 5812 | __ movhpd(reg, stack); |
| 5813 | |
| 5814 | // Store the low double into the destination. |
| 5815 | __ movsd(stack, reg); |
| 5816 | |
| 5817 | // Move the high double to the low double. |
| 5818 | __ psrldq(reg, Immediate(8)); |
| 5819 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5820 | // Take advantage of the 16 bytes in the XMM register. |
| 5821 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5822 | Address stack(ESP, source.GetStackIndex()); |
| 5823 | // Load the double into the high doubleword. |
| 5824 | __ movhpd(reg, stack); |
| 5825 | |
| 5826 | // Store the low double into the destination. |
| 5827 | __ movsd(stack, reg); |
| 5828 | |
| 5829 | // Move the high double to the low double. |
| 5830 | __ psrldq(reg, Immediate(8)); |
| 5831 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5832 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5833 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5834 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5835 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5840 | __ pushl(static_cast<Register>(reg)); |
| 5841 | } |
| 5842 | |
| 5843 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5844 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5845 | } |
| 5846 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5847 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5848 | InvokeRuntimeCallingConvention calling_convention; |
| 5849 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5850 | cls, |
| 5851 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5852 | Location::RegisterLocation(EAX), |
| 5853 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5854 | } |
| 5855 | |
| 5856 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5857 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5858 | if (cls->NeedsAccessCheck()) { |
| 5859 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5860 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5861 | cls, |
| 5862 | cls->GetDexPc(), |
| 5863 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5864 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5865 | return; |
| 5866 | } |
| 5867 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5868 | Location out_loc = locations->Out(); |
| 5869 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5870 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5871 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5872 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5873 | DCHECK(!cls->CanCallRuntime()); |
| 5874 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5875 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5876 | GenerateGcRootFieldLoad( |
| 5877 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5878 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5879 | // /* GcRoot<mirror::Class>[] */ out = |
| 5880 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5881 | __ movl(out, Address(current_method, |
| 5882 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5883 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5884 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5885 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5886 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5887 | DCHECK(cls->CanCallRuntime()); |
| 5888 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5889 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5890 | codegen_->AddSlowPath(slow_path); |
| 5891 | |
| 5892 | if (!cls->IsInDexCache()) { |
| 5893 | __ testl(out, out); |
| 5894 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5895 | } |
| 5896 | |
| 5897 | if (cls->MustGenerateClinitCheck()) { |
| 5898 | GenerateClassInitializationCheck(slow_path, out); |
| 5899 | } else { |
| 5900 | __ Bind(slow_path->GetExitLabel()); |
| 5901 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5902 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5907 | LocationSummary* locations = |
| 5908 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5909 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5910 | if (check->HasUses()) { |
| 5911 | locations->SetOut(Location::SameAsFirstInput()); |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5916 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5917 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5918 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5919 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5920 | GenerateClassInitializationCheck(slow_path, |
| 5921 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5922 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5923 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5924 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5925 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5926 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5927 | Immediate(mirror::Class::kStatusInitialized)); |
| 5928 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5929 | __ Bind(slow_path->GetExitLabel()); |
| 5930 | // No need for memory fence, thanks to the X86 memory model. |
| 5931 | } |
| 5932 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5933 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5934 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5935 | ? LocationSummary::kCallOnSlowPath |
| 5936 | : LocationSummary::kNoCall; |
| 5937 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5938 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5939 | locations->SetOut(Location::RequiresRegister()); |
| 5940 | } |
| 5941 | |
| 5942 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5943 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5944 | Location out_loc = locations->Out(); |
| 5945 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5946 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5947 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5948 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5949 | GenerateGcRootFieldLoad( |
| 5950 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5951 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5952 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5953 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5954 | GenerateGcRootFieldLoad( |
| 5955 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5957 | if (!load->IsInDexCache()) { |
| 5958 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5959 | codegen_->AddSlowPath(slow_path); |
| 5960 | __ testl(out, out); |
| 5961 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5962 | __ Bind(slow_path->GetExitLabel()); |
| 5963 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5966 | static Address GetExceptionTlsAddress() { |
| 5967 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5968 | } |
| 5969 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5970 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5971 | LocationSummary* locations = |
| 5972 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5973 | locations->SetOut(Location::RequiresRegister()); |
| 5974 | } |
| 5975 | |
| 5976 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5977 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5978 | } |
| 5979 | |
| 5980 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5981 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5982 | } |
| 5983 | |
| 5984 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5985 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5989 | LocationSummary* locations = |
| 5990 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5991 | InvokeRuntimeCallingConvention calling_convention; |
| 5992 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5993 | } |
| 5994 | |
| 5995 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5996 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5997 | instruction, |
| 5998 | instruction->GetDexPc(), |
| 5999 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6000 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6001 | } |
| 6002 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6003 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6004 | return kEmitCompilerReadBarrier && |
| 6005 | (kUseBakerReadBarrier || |
| 6006 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6007 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6008 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6009 | } |
| 6010 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6011 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6012 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6013 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6014 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6015 | case TypeCheckKind::kExactCheck: |
| 6016 | case TypeCheckKind::kAbstractClassCheck: |
| 6017 | case TypeCheckKind::kClassHierarchyCheck: |
| 6018 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6019 | call_kind = |
| 6020 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6021 | break; |
| 6022 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6023 | case TypeCheckKind::kUnresolvedCheck: |
| 6024 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6025 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6026 | break; |
| 6027 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6028 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6029 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6030 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6031 | locations->SetInAt(1, Location::Any()); |
| 6032 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6033 | locations->SetOut(Location::RequiresRegister()); |
| 6034 | // When read barriers are enabled, we need a temporary register for |
| 6035 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6036 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6037 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6038 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6039 | } |
| 6040 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6041 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6042 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6043 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6044 | Location obj_loc = locations->InAt(0); |
| 6045 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6046 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6047 | Location out_loc = locations->Out(); |
| 6048 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6049 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6050 | locations->GetTemp(0) : |
| 6051 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6052 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6053 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6054 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6055 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6056 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6057 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6058 | |
| 6059 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6060 | // Avoid null check if we know obj is not null. |
| 6061 | if (instruction->MustDoNullCheck()) { |
| 6062 | __ testl(obj, obj); |
| 6063 | __ j(kEqual, &zero); |
| 6064 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6065 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6066 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6067 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6068 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6069 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6070 | case TypeCheckKind::kExactCheck: { |
| 6071 | if (cls.IsRegister()) { |
| 6072 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6073 | } else { |
| 6074 | DCHECK(cls.IsStackSlot()) << cls; |
| 6075 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6076 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6077 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6078 | // Classes must be equal for the instanceof to succeed. |
| 6079 | __ j(kNotEqual, &zero); |
| 6080 | __ movl(out, Immediate(1)); |
| 6081 | __ jmp(&done); |
| 6082 | break; |
| 6083 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6084 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6085 | case TypeCheckKind::kAbstractClassCheck: { |
| 6086 | // If the class is abstract, we eagerly fetch the super class of the |
| 6087 | // object to avoid doing a comparison we know will fail. |
| 6088 | NearLabel loop; |
| 6089 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6090 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6091 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6092 | __ testl(out, out); |
| 6093 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6094 | __ j(kEqual, &done); |
| 6095 | if (cls.IsRegister()) { |
| 6096 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6097 | } else { |
| 6098 | DCHECK(cls.IsStackSlot()) << cls; |
| 6099 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6100 | } |
| 6101 | __ j(kNotEqual, &loop); |
| 6102 | __ movl(out, Immediate(1)); |
| 6103 | if (zero.IsLinked()) { |
| 6104 | __ jmp(&done); |
| 6105 | } |
| 6106 | break; |
| 6107 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6108 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6109 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6110 | // Walk over the class hierarchy to find a match. |
| 6111 | NearLabel loop, success; |
| 6112 | __ Bind(&loop); |
| 6113 | if (cls.IsRegister()) { |
| 6114 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6115 | } else { |
| 6116 | DCHECK(cls.IsStackSlot()) << cls; |
| 6117 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6118 | } |
| 6119 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6120 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6121 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6122 | __ testl(out, out); |
| 6123 | __ j(kNotEqual, &loop); |
| 6124 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6125 | __ jmp(&done); |
| 6126 | __ Bind(&success); |
| 6127 | __ movl(out, Immediate(1)); |
| 6128 | if (zero.IsLinked()) { |
| 6129 | __ jmp(&done); |
| 6130 | } |
| 6131 | break; |
| 6132 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6133 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6134 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6135 | // Do an exact check. |
| 6136 | NearLabel exact_check; |
| 6137 | if (cls.IsRegister()) { |
| 6138 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6139 | } else { |
| 6140 | DCHECK(cls.IsStackSlot()) << cls; |
| 6141 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6142 | } |
| 6143 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6144 | // 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] | 6145 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6146 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6147 | __ testl(out, out); |
| 6148 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6149 | __ j(kEqual, &done); |
| 6150 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6151 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6152 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6153 | __ movl(out, Immediate(1)); |
| 6154 | __ jmp(&done); |
| 6155 | break; |
| 6156 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6157 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | case TypeCheckKind::kArrayCheck: { |
| 6159 | if (cls.IsRegister()) { |
| 6160 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6161 | } else { |
| 6162 | DCHECK(cls.IsStackSlot()) << cls; |
| 6163 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6164 | } |
| 6165 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6166 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6167 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6168 | codegen_->AddSlowPath(slow_path); |
| 6169 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6170 | __ movl(out, Immediate(1)); |
| 6171 | if (zero.IsLinked()) { |
| 6172 | __ jmp(&done); |
| 6173 | } |
| 6174 | break; |
| 6175 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6176 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6177 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6178 | case TypeCheckKind::kInterfaceCheck: { |
| 6179 | // 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] | 6180 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6181 | // cases. |
| 6182 | // |
| 6183 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6184 | // entry point without resorting to a type checking slow path |
| 6185 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6186 | // require to assign fixed registers for the inputs of this |
| 6187 | // HInstanceOf instruction (following the runtime calling |
| 6188 | // convention), which might be cluttered by the potential first |
| 6189 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6190 | // |
| 6191 | // TODO: Introduce a new runtime entry point taking the object |
| 6192 | // to test (instead of its class) as argument, and let it deal |
| 6193 | // with the read barrier issues. This will let us refactor this |
| 6194 | // case of the `switch` code as it was previously (with a direct |
| 6195 | // call to the runtime not using a type checking slow path). |
| 6196 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6197 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6198 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6199 | /* is_fatal */ false); |
| 6200 | codegen_->AddSlowPath(slow_path); |
| 6201 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6202 | if (zero.IsLinked()) { |
| 6203 | __ jmp(&done); |
| 6204 | } |
| 6205 | break; |
| 6206 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6209 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6210 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6211 | __ xorl(out, out); |
| 6212 | } |
| 6213 | |
| 6214 | if (done.IsLinked()) { |
| 6215 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6216 | } |
| 6217 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6218 | if (slow_path != nullptr) { |
| 6219 | __ Bind(slow_path->GetExitLabel()); |
| 6220 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6221 | } |
| 6222 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6223 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6224 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6225 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6226 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6227 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6228 | case TypeCheckKind::kExactCheck: |
| 6229 | case TypeCheckKind::kAbstractClassCheck: |
| 6230 | case TypeCheckKind::kClassHierarchyCheck: |
| 6231 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6232 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6233 | LocationSummary::kCallOnSlowPath : |
| 6234 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6235 | break; |
| 6236 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6237 | case TypeCheckKind::kUnresolvedCheck: |
| 6238 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6240 | break; |
| 6241 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6242 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6244 | locations->SetInAt(1, Location::Any()); |
| 6245 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6246 | locations->AddTemp(Location::RequiresRegister()); |
| 6247 | // When read barriers are enabled, we need an additional temporary |
| 6248 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6249 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6250 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6251 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6255 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6256 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6257 | Location obj_loc = locations->InAt(0); |
| 6258 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6259 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6260 | Location temp_loc = locations->GetTemp(0); |
| 6261 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6262 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6263 | locations->GetTemp(1) : |
| 6264 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6265 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6266 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6267 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6268 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6269 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6270 | bool is_type_check_slow_path_fatal = |
| 6271 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6272 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6273 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6274 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6275 | !instruction->CanThrowIntoCatchBlock(); |
| 6276 | SlowPathCode* type_check_slow_path = |
| 6277 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6278 | is_type_check_slow_path_fatal); |
| 6279 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6280 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6282 | // Avoid null check if we know obj is not null. |
| 6283 | if (instruction->MustDoNullCheck()) { |
| 6284 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6285 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6286 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6287 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6288 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6289 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6290 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6291 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6292 | case TypeCheckKind::kExactCheck: |
| 6293 | case TypeCheckKind::kArrayCheck: { |
| 6294 | if (cls.IsRegister()) { |
| 6295 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6296 | } else { |
| 6297 | DCHECK(cls.IsStackSlot()) << cls; |
| 6298 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6299 | } |
| 6300 | // Jump to slow path for throwing the exception or doing a |
| 6301 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | __ j(kNotEqual, 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 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6306 | case TypeCheckKind::kAbstractClassCheck: { |
| 6307 | // If the class is abstract, we eagerly fetch the super class of the |
| 6308 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6309 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6310 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6311 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6312 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6313 | |
| 6314 | // If the class reference currently in `temp` is not null, jump |
| 6315 | // to the `compare_classes` label to compare it with the checked |
| 6316 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6317 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6318 | __ j(kNotEqual, &compare_classes); |
| 6319 | // Otherwise, jump to the slow path to throw the exception. |
| 6320 | // |
| 6321 | // But before, move back the object's class into `temp` before |
| 6322 | // going into the slow path, as it has been overwritten in the |
| 6323 | // meantime. |
| 6324 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6325 | GenerateReferenceLoadTwoRegisters( |
| 6326 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6327 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6328 | |
| 6329 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6330 | if (cls.IsRegister()) { |
| 6331 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6332 | } else { |
| 6333 | DCHECK(cls.IsStackSlot()) << cls; |
| 6334 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6335 | } |
| 6336 | __ j(kNotEqual, &loop); |
| 6337 | break; |
| 6338 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6339 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6340 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6341 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6342 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6343 | __ Bind(&loop); |
| 6344 | if (cls.IsRegister()) { |
| 6345 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6346 | } else { |
| 6347 | DCHECK(cls.IsStackSlot()) << cls; |
| 6348 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6349 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6350 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6351 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6352 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6353 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 | |
| 6355 | // If the class reference currently in `temp` is not null, jump |
| 6356 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6357 | __ testl(temp, temp); |
| 6358 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6359 | // Otherwise, jump to the slow path to throw the exception. |
| 6360 | // |
| 6361 | // But before, move back the object's class into `temp` before |
| 6362 | // going into the slow path, as it has been overwritten in the |
| 6363 | // meantime. |
| 6364 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6365 | GenerateReferenceLoadTwoRegisters( |
| 6366 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6367 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6368 | break; |
| 6369 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6370 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6371 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6372 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6373 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6374 | if (cls.IsRegister()) { |
| 6375 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6376 | } else { |
| 6377 | DCHECK(cls.IsStackSlot()) << cls; |
| 6378 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6379 | } |
| 6380 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6381 | |
| 6382 | // 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] | 6383 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6384 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6385 | |
| 6386 | // If the component type is not null (i.e. the object is indeed |
| 6387 | // an array), jump to label `check_non_primitive_component_type` |
| 6388 | // to further check that this component type is not a primitive |
| 6389 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6390 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6391 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6392 | // Otherwise, jump to the slow path to throw the exception. |
| 6393 | // |
| 6394 | // But before, move back the object's class into `temp` before |
| 6395 | // going into the slow path, as it has been overwritten in the |
| 6396 | // meantime. |
| 6397 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6398 | GenerateReferenceLoadTwoRegisters( |
| 6399 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6400 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6401 | |
| 6402 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6403 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 | __ j(kEqual, &done); |
| 6405 | // Same comment as above regarding `temp` and the slow path. |
| 6406 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6407 | GenerateReferenceLoadTwoRegisters( |
| 6408 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6409 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6410 | break; |
| 6411 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6412 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6413 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6414 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6415 | // We always go into the type check slow path for the unresolved |
| 6416 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6417 | // |
| 6418 | // We cannot directly call the CheckCast runtime entry point |
| 6419 | // without resorting to a type checking slow path here (i.e. by |
| 6420 | // calling InvokeRuntime directly), as it would require to |
| 6421 | // assign fixed registers for the inputs of this HInstanceOf |
| 6422 | // instruction (following the runtime calling convention), which |
| 6423 | // might be cluttered by the potential first read barrier |
| 6424 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6425 | // |
| 6426 | // TODO: Introduce a new runtime entry point taking the object |
| 6427 | // to test (instead of its class) as argument, and let it deal |
| 6428 | // with the read barrier issues. This will let us refactor this |
| 6429 | // case of the `switch` code as it was previously (with a direct |
| 6430 | // call to the runtime not using a type checking slow path). |
| 6431 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6432 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6433 | break; |
| 6434 | } |
| 6435 | __ Bind(&done); |
| 6436 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6437 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6438 | } |
| 6439 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6440 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6441 | LocationSummary* locations = |
| 6442 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6443 | InvokeRuntimeCallingConvention calling_convention; |
| 6444 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6445 | } |
| 6446 | |
| 6447 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6448 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6449 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6450 | instruction, |
| 6451 | instruction->GetDexPc(), |
| 6452 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6453 | if (instruction->IsEnter()) { |
| 6454 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6455 | } else { |
| 6456 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6457 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6458 | } |
| 6459 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6460 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6461 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6462 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6463 | |
| 6464 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6465 | LocationSummary* locations = |
| 6466 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6467 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6468 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6469 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6470 | locations->SetInAt(1, Location::Any()); |
| 6471 | locations->SetOut(Location::SameAsFirstInput()); |
| 6472 | } |
| 6473 | |
| 6474 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6475 | HandleBitwiseOperation(instruction); |
| 6476 | } |
| 6477 | |
| 6478 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6479 | HandleBitwiseOperation(instruction); |
| 6480 | } |
| 6481 | |
| 6482 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6483 | HandleBitwiseOperation(instruction); |
| 6484 | } |
| 6485 | |
| 6486 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6487 | LocationSummary* locations = instruction->GetLocations(); |
| 6488 | Location first = locations->InAt(0); |
| 6489 | Location second = locations->InAt(1); |
| 6490 | DCHECK(first.Equals(locations->Out())); |
| 6491 | |
| 6492 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6493 | if (second.IsRegister()) { |
| 6494 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6495 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6496 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6497 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6498 | } else { |
| 6499 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6500 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6501 | } |
| 6502 | } else if (second.IsConstant()) { |
| 6503 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6504 | __ andl(first.AsRegister<Register>(), |
| 6505 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6506 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6507 | __ orl(first.AsRegister<Register>(), |
| 6508 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6509 | } else { |
| 6510 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6511 | __ xorl(first.AsRegister<Register>(), |
| 6512 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6513 | } |
| 6514 | } else { |
| 6515 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6516 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6517 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6518 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6519 | } else { |
| 6520 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6521 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6522 | } |
| 6523 | } |
| 6524 | } else { |
| 6525 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6526 | if (second.IsRegisterPair()) { |
| 6527 | if (instruction->IsAnd()) { |
| 6528 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6529 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6530 | } else if (instruction->IsOr()) { |
| 6531 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6532 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6533 | } else { |
| 6534 | DCHECK(instruction->IsXor()); |
| 6535 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6536 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6537 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6538 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6539 | if (instruction->IsAnd()) { |
| 6540 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6541 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6542 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6543 | } else if (instruction->IsOr()) { |
| 6544 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6545 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6546 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6547 | } else { |
| 6548 | DCHECK(instruction->IsXor()); |
| 6549 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6550 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6551 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6552 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6553 | } else { |
| 6554 | DCHECK(second.IsConstant()) << second; |
| 6555 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6556 | int32_t low_value = Low32Bits(value); |
| 6557 | int32_t high_value = High32Bits(value); |
| 6558 | Immediate low(low_value); |
| 6559 | Immediate high(high_value); |
| 6560 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6561 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6562 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6563 | if (low_value == 0) { |
| 6564 | __ xorl(first_low, first_low); |
| 6565 | } else if (low_value != -1) { |
| 6566 | __ andl(first_low, low); |
| 6567 | } |
| 6568 | if (high_value == 0) { |
| 6569 | __ xorl(first_high, first_high); |
| 6570 | } else if (high_value != -1) { |
| 6571 | __ andl(first_high, high); |
| 6572 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6573 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6574 | if (low_value != 0) { |
| 6575 | __ orl(first_low, low); |
| 6576 | } |
| 6577 | if (high_value != 0) { |
| 6578 | __ orl(first_high, high); |
| 6579 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6580 | } else { |
| 6581 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6582 | if (low_value != 0) { |
| 6583 | __ xorl(first_low, low); |
| 6584 | } |
| 6585 | if (high_value != 0) { |
| 6586 | __ xorl(first_high, high); |
| 6587 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6588 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6589 | } |
| 6590 | } |
| 6591 | } |
| 6592 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6593 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6594 | Location out, |
| 6595 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6596 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6597 | Register out_reg = out.AsRegister<Register>(); |
| 6598 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6599 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6600 | if (kUseBakerReadBarrier) { |
| 6601 | // Load with fast path based Baker's read barrier. |
| 6602 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6603 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6604 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6605 | } else { |
| 6606 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6607 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6608 | // in the following move operation, as we will need it for the |
| 6609 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6610 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6611 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6612 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6613 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6614 | } |
| 6615 | } else { |
| 6616 | // Plain load with no read barrier. |
| 6617 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6618 | __ movl(out_reg, Address(out_reg, offset)); |
| 6619 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6624 | Location out, |
| 6625 | Location obj, |
| 6626 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6627 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6628 | Register out_reg = out.AsRegister<Register>(); |
| 6629 | Register obj_reg = obj.AsRegister<Register>(); |
| 6630 | if (kEmitCompilerReadBarrier) { |
| 6631 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6632 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6633 | // Load with fast path based Baker's read barrier. |
| 6634 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6635 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6636 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6637 | } else { |
| 6638 | // Load with slow path based read barrier. |
| 6639 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6640 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6641 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6642 | } |
| 6643 | } else { |
| 6644 | // Plain load with no read barrier. |
| 6645 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6646 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6647 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6648 | } |
| 6649 | } |
| 6650 | |
| 6651 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6652 | Location root, |
| 6653 | Register obj, |
| 6654 | uint32_t offset) { |
| 6655 | Register root_reg = root.AsRegister<Register>(); |
| 6656 | if (kEmitCompilerReadBarrier) { |
| 6657 | if (kUseBakerReadBarrier) { |
| 6658 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6659 | // Baker's read barrier are used: |
| 6660 | // |
| 6661 | // root = obj.field; |
| 6662 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6663 | // root = ReadBarrier::Mark(root) |
| 6664 | // } |
| 6665 | |
| 6666 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6667 | __ movl(root_reg, Address(obj, offset)); |
| 6668 | static_assert( |
| 6669 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6670 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6671 | "have different sizes."); |
| 6672 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6673 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6674 | "have different sizes."); |
| 6675 | |
| 6676 | // Slow path used to mark the GC root `root`. |
| 6677 | SlowPathCode* slow_path = |
| 6678 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6679 | codegen_->AddSlowPath(slow_path); |
| 6680 | |
| 6681 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6682 | Immediate(0)); |
| 6683 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6684 | __ Bind(slow_path->GetExitLabel()); |
| 6685 | } else { |
| 6686 | // GC root loaded through a slow path for read barriers other |
| 6687 | // than Baker's. |
| 6688 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6689 | __ leal(root_reg, Address(obj, offset)); |
| 6690 | // /* mirror::Object* */ root = root->Read() |
| 6691 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6692 | } |
| 6693 | } else { |
| 6694 | // Plain GC root load with no read barrier. |
| 6695 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6696 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6697 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6698 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6703 | Location ref, |
| 6704 | Register obj, |
| 6705 | uint32_t offset, |
| 6706 | Location temp, |
| 6707 | bool needs_null_check) { |
| 6708 | DCHECK(kEmitCompilerReadBarrier); |
| 6709 | DCHECK(kUseBakerReadBarrier); |
| 6710 | |
| 6711 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6712 | Address src(obj, offset); |
| 6713 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6714 | } |
| 6715 | |
| 6716 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6717 | Location ref, |
| 6718 | Register obj, |
| 6719 | uint32_t data_offset, |
| 6720 | Location index, |
| 6721 | Location temp, |
| 6722 | bool needs_null_check) { |
| 6723 | DCHECK(kEmitCompilerReadBarrier); |
| 6724 | DCHECK(kUseBakerReadBarrier); |
| 6725 | |
| 6726 | // /* HeapReference<Object> */ ref = |
| 6727 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6728 | Address src = index.IsConstant() ? |
| 6729 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6730 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6731 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6732 | } |
| 6733 | |
| 6734 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6735 | Location ref, |
| 6736 | Register obj, |
| 6737 | const Address& src, |
| 6738 | Location temp, |
| 6739 | bool needs_null_check) { |
| 6740 | DCHECK(kEmitCompilerReadBarrier); |
| 6741 | DCHECK(kUseBakerReadBarrier); |
| 6742 | |
| 6743 | // In slow path based read barriers, the read barrier call is |
| 6744 | // inserted after the original load. However, in fast path based |
| 6745 | // Baker's read barriers, we need to perform the load of |
| 6746 | // mirror::Object::monitor_ *before* the original reference load. |
| 6747 | // This load-load ordering is required by the read barrier. |
| 6748 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6749 | // |
| 6750 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6751 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6752 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6753 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6754 | // if (is_gray) { |
| 6755 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6756 | // } |
| 6757 | // |
| 6758 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6759 | // slightly more complex as: |
| 6760 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6761 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6762 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6763 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6764 | // - it performs additional checks that we do not do here for |
| 6765 | // performance reasons. |
| 6766 | |
| 6767 | Register ref_reg = ref.AsRegister<Register>(); |
| 6768 | Register temp_reg = temp.AsRegister<Register>(); |
| 6769 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6770 | |
| 6771 | // /* int32_t */ monitor = obj->monitor_ |
| 6772 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6773 | if (needs_null_check) { |
| 6774 | MaybeRecordImplicitNullCheck(instruction); |
| 6775 | } |
| 6776 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6777 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6778 | "art::LockWord and int32_t have different sizes."); |
| 6779 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6780 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6781 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6782 | static_assert( |
| 6783 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6784 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6785 | |
| 6786 | // Load fence to prevent load-load reordering. |
| 6787 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6788 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6789 | |
| 6790 | // The actual reference load. |
| 6791 | // /* HeapReference<Object> */ ref = *src |
| 6792 | __ movl(ref_reg, src); |
| 6793 | |
| 6794 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6795 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6796 | |
| 6797 | // Slow path used to mark the object `ref` when it is gray. |
| 6798 | SlowPathCode* slow_path = |
| 6799 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6800 | AddSlowPath(slow_path); |
| 6801 | |
| 6802 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6803 | // ref = ReadBarrier::Mark(ref); |
| 6804 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6805 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6806 | __ Bind(slow_path->GetExitLabel()); |
| 6807 | } |
| 6808 | |
| 6809 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6810 | Location out, |
| 6811 | Location ref, |
| 6812 | Location obj, |
| 6813 | uint32_t offset, |
| 6814 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6815 | DCHECK(kEmitCompilerReadBarrier); |
| 6816 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6817 | // Insert a slow path based read barrier *after* the reference load. |
| 6818 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6819 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6820 | // reference will be carried out by the runtime within the slow |
| 6821 | // path. |
| 6822 | // |
| 6823 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6824 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6825 | // not used by the artReadBarrierSlow entry point. |
| 6826 | // |
| 6827 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6828 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6829 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6830 | AddSlowPath(slow_path); |
| 6831 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6832 | __ jmp(slow_path->GetEntryLabel()); |
| 6833 | __ Bind(slow_path->GetExitLabel()); |
| 6834 | } |
| 6835 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6836 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6837 | Location out, |
| 6838 | Location ref, |
| 6839 | Location obj, |
| 6840 | uint32_t offset, |
| 6841 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6842 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6843 | // Baker's read barriers shall be handled by the fast path |
| 6844 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6845 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6846 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6847 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6848 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6849 | } else if (kPoisonHeapReferences) { |
| 6850 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6851 | } |
| 6852 | } |
| 6853 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6854 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6855 | Location out, |
| 6856 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6857 | DCHECK(kEmitCompilerReadBarrier); |
| 6858 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6859 | // Insert a slow path based read barrier *after* the GC root load. |
| 6860 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6861 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6862 | // not need to do anything special for this here. |
| 6863 | SlowPathCode* slow_path = |
| 6864 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6865 | AddSlowPath(slow_path); |
| 6866 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6867 | __ jmp(slow_path->GetEntryLabel()); |
| 6868 | __ Bind(slow_path->GetExitLabel()); |
| 6869 | } |
| 6870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6871 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6872 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6873 | LOG(FATAL) << "Unreachable"; |
| 6874 | } |
| 6875 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6876 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6877 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6878 | LOG(FATAL) << "Unreachable"; |
| 6879 | } |
| 6880 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6881 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6882 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6883 | LocationSummary* locations = |
| 6884 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6885 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6886 | } |
| 6887 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6888 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6889 | int32_t lower_bound, |
| 6890 | uint32_t num_entries, |
| 6891 | HBasicBlock* switch_block, |
| 6892 | HBasicBlock* default_block) { |
| 6893 | // Figure out the correct compare values and jump conditions. |
| 6894 | // Handle the first compare/branch as a special case because it might |
| 6895 | // jump to the default case. |
| 6896 | DCHECK_GT(num_entries, 2u); |
| 6897 | Condition first_condition; |
| 6898 | uint32_t index; |
| 6899 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6900 | if (lower_bound != 0) { |
| 6901 | first_condition = kLess; |
| 6902 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6903 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6904 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6905 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6906 | index = 1; |
| 6907 | } else { |
| 6908 | // Handle all the compare/jumps below. |
| 6909 | first_condition = kBelow; |
| 6910 | index = 0; |
| 6911 | } |
| 6912 | |
| 6913 | // Handle the rest of the compare/jumps. |
| 6914 | for (; index + 1 < num_entries; index += 2) { |
| 6915 | int32_t compare_to_value = lower_bound + index + 1; |
| 6916 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6917 | // Jump to successors[index] if value < case_value[index]. |
| 6918 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6919 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6920 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6921 | } |
| 6922 | |
| 6923 | if (index != num_entries) { |
| 6924 | // There are an odd number of entries. Handle the last one. |
| 6925 | DCHECK_EQ(index + 1, num_entries); |
| 6926 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6927 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6928 | } |
| 6929 | |
| 6930 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6931 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6932 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6933 | } |
| 6934 | } |
| 6935 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6936 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6937 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6938 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6939 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6940 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6941 | |
| 6942 | GenPackedSwitchWithCompares(value_reg, |
| 6943 | lower_bound, |
| 6944 | num_entries, |
| 6945 | switch_instr->GetBlock(), |
| 6946 | switch_instr->GetDefaultBlock()); |
| 6947 | } |
| 6948 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6949 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6950 | LocationSummary* locations = |
| 6951 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6953 | |
| 6954 | // Constant area pointer. |
| 6955 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6956 | |
| 6957 | // And the temporary we need. |
| 6958 | locations->AddTemp(Location::RequiresRegister()); |
| 6959 | } |
| 6960 | |
| 6961 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6962 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6963 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6964 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6965 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6966 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6967 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6968 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6969 | GenPackedSwitchWithCompares(value_reg, |
| 6970 | lower_bound, |
| 6971 | num_entries, |
| 6972 | switch_instr->GetBlock(), |
| 6973 | default_block); |
| 6974 | return; |
| 6975 | } |
| 6976 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6977 | // Optimizing has a jump area. |
| 6978 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6979 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6980 | |
| 6981 | // Remove the bias, if needed. |
| 6982 | if (lower_bound != 0) { |
| 6983 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6984 | value_reg = temp_reg; |
| 6985 | } |
| 6986 | |
| 6987 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6988 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6989 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6990 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6991 | |
| 6992 | // We are in the range of the table. |
| 6993 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6994 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6995 | |
| 6996 | // Compute the actual target address by adding in constant_area. |
| 6997 | __ addl(temp_reg, constant_area); |
| 6998 | |
| 6999 | // And jump. |
| 7000 | __ jmp(temp_reg); |
| 7001 | } |
| 7002 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7003 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7004 | HX86ComputeBaseMethodAddress* insn) { |
| 7005 | LocationSummary* locations = |
| 7006 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7007 | locations->SetOut(Location::RequiresRegister()); |
| 7008 | } |
| 7009 | |
| 7010 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7011 | HX86ComputeBaseMethodAddress* insn) { |
| 7012 | LocationSummary* locations = insn->GetLocations(); |
| 7013 | Register reg = locations->Out().AsRegister<Register>(); |
| 7014 | |
| 7015 | // Generate call to next instruction. |
| 7016 | Label next_instruction; |
| 7017 | __ call(&next_instruction); |
| 7018 | __ Bind(&next_instruction); |
| 7019 | |
| 7020 | // Remember this offset for later use with constant area. |
| 7021 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7022 | |
| 7023 | // Grab the return address off the stack. |
| 7024 | __ popl(reg); |
| 7025 | } |
| 7026 | |
| 7027 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7028 | HX86LoadFromConstantTable* insn) { |
| 7029 | LocationSummary* locations = |
| 7030 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7031 | |
| 7032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7033 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7034 | |
| 7035 | // If we don't need to be materialized, we only need the inputs to be set. |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7036 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7037 | return; |
| 7038 | } |
| 7039 | |
| 7040 | switch (insn->GetType()) { |
| 7041 | case Primitive::kPrimFloat: |
| 7042 | case Primitive::kPrimDouble: |
| 7043 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7044 | break; |
| 7045 | |
| 7046 | case Primitive::kPrimInt: |
| 7047 | locations->SetOut(Location::RequiresRegister()); |
| 7048 | break; |
| 7049 | |
| 7050 | default: |
| 7051 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7052 | } |
| 7053 | } |
| 7054 | |
| 7055 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7056 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7057 | return; |
| 7058 | } |
| 7059 | |
| 7060 | LocationSummary* locations = insn->GetLocations(); |
| 7061 | Location out = locations->Out(); |
| 7062 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7063 | HConstant *value = insn->GetConstant(); |
| 7064 | |
| 7065 | switch (insn->GetType()) { |
| 7066 | case Primitive::kPrimFloat: |
| 7067 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7068 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7069 | break; |
| 7070 | |
| 7071 | case Primitive::kPrimDouble: |
| 7072 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7073 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7074 | break; |
| 7075 | |
| 7076 | case Primitive::kPrimInt: |
| 7077 | __ movl(out.AsRegister<Register>(), |
| 7078 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7079 | break; |
| 7080 | |
| 7081 | default: |
| 7082 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7083 | } |
| 7084 | } |
| 7085 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7086 | /** |
| 7087 | * Class to handle late fixup of offsets into constant area. |
| 7088 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7089 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7090 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7091 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7092 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7093 | |
| 7094 | protected: |
| 7095 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7096 | |
| 7097 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7098 | |
| 7099 | private: |
| 7100 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7101 | // Patch the correct offset for the instruction. The place to patch is the |
| 7102 | // last 4 bytes of the instruction. |
| 7103 | // The value to patch is the distance from the offset in the constant area |
| 7104 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7105 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7106 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7107 | |
| 7108 | // Patch in the right value. |
| 7109 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7110 | } |
| 7111 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7112 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7113 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7114 | }; |
| 7115 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7116 | /** |
| 7117 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7118 | * constant area. |
| 7119 | */ |
| 7120 | class JumpTableRIPFixup : public RIPFixup { |
| 7121 | public: |
| 7122 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7123 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7124 | |
| 7125 | void CreateJumpTable() { |
| 7126 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7127 | |
| 7128 | // Ensure that the reference to the jump table has the correct offset. |
| 7129 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7130 | SetOffset(offset_in_constant_table); |
| 7131 | |
| 7132 | // The label values in the jump table are computed relative to the |
| 7133 | // instruction addressing the constant area. |
| 7134 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7135 | |
| 7136 | // Populate the jump table with the correct values for the jump table. |
| 7137 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7138 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7139 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7140 | // The value that we want is the target offset - the position of the table. |
| 7141 | for (int32_t i = 0; i < num_entries; i++) { |
| 7142 | HBasicBlock* b = successors[i]; |
| 7143 | Label* l = codegen_->GetLabelOf(b); |
| 7144 | DCHECK(l->IsBound()); |
| 7145 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7146 | assembler->AppendInt32(offset_to_block); |
| 7147 | } |
| 7148 | } |
| 7149 | |
| 7150 | private: |
| 7151 | const HX86PackedSwitch* switch_instr_; |
| 7152 | }; |
| 7153 | |
| 7154 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7155 | // Generate the constant area if needed. |
| 7156 | X86Assembler* assembler = GetAssembler(); |
| 7157 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7158 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7159 | // byte values. |
| 7160 | assembler->Align(4, 0); |
| 7161 | constant_area_start_ = assembler->CodeSize(); |
| 7162 | |
| 7163 | // Populate any jump tables. |
| 7164 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7165 | jump_table->CreateJumpTable(); |
| 7166 | } |
| 7167 | |
| 7168 | // And now add the constant area to the generated code. |
| 7169 | assembler->AddConstantArea(); |
| 7170 | } |
| 7171 | |
| 7172 | // And finish up. |
| 7173 | CodeGenerator::Finalize(allocator); |
| 7174 | } |
| 7175 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7176 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7177 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7178 | return Address(reg, kDummy32BitOffset, fixup); |
| 7179 | } |
| 7180 | |
| 7181 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7182 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7183 | return Address(reg, kDummy32BitOffset, fixup); |
| 7184 | } |
| 7185 | |
| 7186 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7187 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7188 | return Address(reg, kDummy32BitOffset, fixup); |
| 7189 | } |
| 7190 | |
| 7191 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7192 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7193 | return Address(reg, kDummy32BitOffset, fixup); |
| 7194 | } |
| 7195 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7196 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7197 | Register reg, |
| 7198 | Register value) { |
| 7199 | // Create a fixup to be used to create and address the jump table. |
| 7200 | JumpTableRIPFixup* table_fixup = |
| 7201 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7202 | |
| 7203 | // We have to populate the jump tables. |
| 7204 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7205 | |
| 7206 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7207 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7208 | } |
| 7209 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7210 | // TODO: target as memory. |
| 7211 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7212 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7213 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7214 | return; |
| 7215 | } |
| 7216 | |
| 7217 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7218 | |
| 7219 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7220 | if (target.Equals(return_loc)) { |
| 7221 | return; |
| 7222 | } |
| 7223 | |
| 7224 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7225 | // with the else branch. |
| 7226 | if (type == Primitive::kPrimLong) { |
| 7227 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7228 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7229 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7230 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7231 | } else { |
| 7232 | // Let the parallel move resolver take care of all of this. |
| 7233 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7234 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7235 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7236 | } |
| 7237 | } |
| 7238 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7239 | #undef __ |
| 7240 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7241 | } // namespace x86 |
| 7242 | } // namespace art |