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 Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1392 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1393 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1394 | LabelType* true_target_in, |
| 1395 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1396 | // Generated branching requires both targets to be explicit. If either of the |
| 1397 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1398 | LabelType fallthrough_target; |
| 1399 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1400 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1401 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1402 | LocationSummary* locations = condition->GetLocations(); |
| 1403 | Location left = locations->InAt(0); |
| 1404 | Location right = locations->InAt(1); |
| 1405 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1406 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1407 | switch (type) { |
| 1408 | case Primitive::kPrimLong: |
| 1409 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1410 | break; |
| 1411 | case Primitive::kPrimFloat: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1412 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | GenerateFPJumps(condition, true_target, false_target); |
| 1414 | break; |
| 1415 | case Primitive::kPrimDouble: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1416 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1417 | GenerateFPJumps(condition, true_target, false_target); |
| 1418 | break; |
| 1419 | default: |
| 1420 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1421 | } |
| 1422 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1423 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1424 | __ jmp(false_target); |
| 1425 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1426 | |
| 1427 | if (fallthrough_target.IsLinked()) { |
| 1428 | __ Bind(&fallthrough_target); |
| 1429 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1430 | } |
| 1431 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1432 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1433 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1434 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1435 | // conditions if they are materialized due to the complex branching. |
| 1436 | return cond->IsCondition() && |
| 1437 | cond->GetNext() == branch && |
| 1438 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1439 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1440 | } |
| 1441 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1442 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1443 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1444 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1445 | LabelType* true_target, |
| 1446 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1447 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1448 | |
| 1449 | if (true_target == nullptr && false_target == nullptr) { |
| 1450 | // Nothing to do. The code always falls through. |
| 1451 | return; |
| 1452 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1453 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1454 | if (cond->AsIntConstant()->IsOne()) { |
| 1455 | if (true_target != nullptr) { |
| 1456 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1457 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1458 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1460 | if (false_target != nullptr) { |
| 1461 | __ jmp(false_target); |
| 1462 | } |
| 1463 | } |
| 1464 | return; |
| 1465 | } |
| 1466 | |
| 1467 | // The following code generates these patterns: |
| 1468 | // (1) true_target == nullptr && false_target != nullptr |
| 1469 | // - opposite condition true => branch to false_target |
| 1470 | // (2) true_target != nullptr && false_target == nullptr |
| 1471 | // - condition true => branch to true_target |
| 1472 | // (3) true_target != nullptr && false_target != nullptr |
| 1473 | // - condition true => branch to true_target |
| 1474 | // - branch to false_target |
| 1475 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1476 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1477 | if (true_target == nullptr) { |
| 1478 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1479 | } else { |
| 1480 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1481 | } |
| 1482 | } else { |
| 1483 | // Materialized condition, compare against 0. |
| 1484 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1485 | if (lhs.IsRegister()) { |
| 1486 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1487 | } else { |
| 1488 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1489 | } |
| 1490 | if (true_target == nullptr) { |
| 1491 | __ j(kEqual, false_target); |
| 1492 | } else { |
| 1493 | __ j(kNotEqual, true_target); |
| 1494 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1495 | } |
| 1496 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1497 | // Condition has not been materialized, use its inputs as the comparison and |
| 1498 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1499 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1500 | |
| 1501 | // If this is a long or FP comparison that has been folded into |
| 1502 | // the HCondition, generate the comparison directly. |
| 1503 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1504 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1505 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1506 | return; |
| 1507 | } |
| 1508 | |
| 1509 | Location lhs = condition->GetLocations()->InAt(0); |
| 1510 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1511 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1512 | if (rhs.IsRegister()) { |
| 1513 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1514 | } else if (rhs.IsConstant()) { |
| 1515 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1516 | if (constant == 0) { |
| 1517 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1518 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1519 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1520 | } |
| 1521 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1522 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1523 | } |
| 1524 | if (true_target == nullptr) { |
| 1525 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1526 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1527 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1528 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1529 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1530 | |
| 1531 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1532 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1533 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1534 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1538 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1539 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1540 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1541 | locations->SetInAt(0, Location::Any()); |
| 1542 | } |
| 1543 | } |
| 1544 | |
| 1545 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1546 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1547 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1548 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1549 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1550 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1551 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1552 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1556 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1557 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1558 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1559 | locations->SetInAt(0, Location::Any()); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1564 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1565 | GenerateTestAndBranch<Label>(deoptimize, |
| 1566 | /* condition_input_index */ 0, |
| 1567 | slow_path->GetEntryLabel(), |
| 1568 | /* false_target */ nullptr); |
| 1569 | } |
| 1570 | |
| 1571 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1572 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1573 | Primitive::Type select_type = select->GetType(); |
| 1574 | HInstruction* cond = select->GetCondition(); |
| 1575 | |
| 1576 | if (Primitive::IsFloatingPointType(select_type)) { |
| 1577 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1578 | } else { |
| 1579 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1580 | } |
| 1581 | locations->SetInAt(1, Location::Any()); |
| 1582 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1583 | locations->SetInAt(2, Location::Any()); |
| 1584 | } |
| 1585 | locations->SetOut(Location::SameAsFirstInput()); |
| 1586 | } |
| 1587 | |
| 1588 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1589 | LocationSummary* locations = select->GetLocations(); |
| 1590 | NearLabel false_target; |
| 1591 | GenerateTestAndBranch<NearLabel>( |
| 1592 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1593 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1594 | __ Bind(&false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1597 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1598 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1599 | } |
| 1600 | |
| 1601 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1602 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1603 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1604 | __ nop(); |
| 1605 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1606 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1607 | } |
| 1608 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1609 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1610 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1613 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1614 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1617 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1618 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1621 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1622 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1625 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1626 | LocationSummary* locations = |
| 1627 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1628 | switch (store->InputAt(1)->GetType()) { |
| 1629 | case Primitive::kPrimBoolean: |
| 1630 | case Primitive::kPrimByte: |
| 1631 | case Primitive::kPrimChar: |
| 1632 | case Primitive::kPrimShort: |
| 1633 | case Primitive::kPrimInt: |
| 1634 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1635 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1636 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1637 | break; |
| 1638 | |
| 1639 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1640 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1641 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1642 | break; |
| 1643 | |
| 1644 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1645 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1646 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1649 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1652 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1653 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1654 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1655 | // Handle the long/FP comparisons made in instruction simplification. |
| 1656 | switch (cond->InputAt(0)->GetType()) { |
| 1657 | case Primitive::kPrimLong: { |
| 1658 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1659 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1660 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1661 | locations->SetOut(Location::RequiresRegister()); |
| 1662 | } |
| 1663 | break; |
| 1664 | } |
| 1665 | case Primitive::kPrimFloat: |
| 1666 | case Primitive::kPrimDouble: { |
| 1667 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1668 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1669 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1670 | locations->SetOut(Location::RequiresRegister()); |
| 1671 | } |
| 1672 | break; |
| 1673 | } |
| 1674 | default: |
| 1675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1676 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1677 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1678 | // We need a byte register. |
| 1679 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1680 | } |
| 1681 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1682 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1685 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1686 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1687 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1688 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1689 | |
| 1690 | LocationSummary* locations = cond->GetLocations(); |
| 1691 | Location lhs = locations->InAt(0); |
| 1692 | Location rhs = locations->InAt(1); |
| 1693 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1694 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 | |
| 1696 | switch (cond->InputAt(0)->GetType()) { |
| 1697 | default: { |
| 1698 | // Integer case. |
| 1699 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1700 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1701 | __ xorl(reg, reg); |
| 1702 | |
| 1703 | if (rhs.IsRegister()) { |
| 1704 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1705 | } else if (rhs.IsConstant()) { |
| 1706 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1707 | if (constant == 0) { |
| 1708 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1709 | } else { |
| 1710 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1711 | } |
| 1712 | } else { |
| 1713 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1714 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1715 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1716 | return; |
| 1717 | } |
| 1718 | case Primitive::kPrimLong: |
| 1719 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1720 | break; |
| 1721 | case Primitive::kPrimFloat: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1722 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1723 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1724 | break; |
| 1725 | case Primitive::kPrimDouble: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1726 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1727 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1728 | break; |
| 1729 | } |
| 1730 | |
| 1731 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1732 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1733 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1734 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1735 | __ Bind(&false_label); |
| 1736 | __ xorl(reg, reg); |
| 1737 | __ jmp(&done_label); |
| 1738 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1739 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1740 | __ Bind(&true_label); |
| 1741 | __ movl(reg, Immediate(1)); |
| 1742 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1746 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1754 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* 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::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1793 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1825 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1826 | LocationSummary* locations = |
| 1827 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1828 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1831 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1832 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1835 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1836 | LocationSummary* locations = |
| 1837 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1838 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1839 | } |
| 1840 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1841 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1842 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1845 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1846 | LocationSummary* locations = |
| 1847 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1848 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1849 | } |
| 1850 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1851 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1852 | // Will be generated at use site. |
| 1853 | } |
| 1854 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1855 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1856 | LocationSummary* locations = |
| 1857 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1858 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1859 | } |
| 1860 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1861 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1862 | // Will be generated at use site. |
| 1863 | } |
| 1864 | |
| 1865 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1866 | LocationSummary* locations = |
| 1867 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1868 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1869 | } |
| 1870 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1871 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1872 | // Will be generated at use site. |
| 1873 | } |
| 1874 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1875 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1876 | memory_barrier->SetLocations(nullptr); |
| 1877 | } |
| 1878 | |
| 1879 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1880 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1881 | } |
| 1882 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1883 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1884 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1887 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1888 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1891 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1892 | LocationSummary* locations = |
| 1893 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1894 | switch (ret->InputAt(0)->GetType()) { |
| 1895 | case Primitive::kPrimBoolean: |
| 1896 | case Primitive::kPrimByte: |
| 1897 | case Primitive::kPrimChar: |
| 1898 | case Primitive::kPrimShort: |
| 1899 | case Primitive::kPrimInt: |
| 1900 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1901 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1902 | break; |
| 1903 | |
| 1904 | case Primitive::kPrimLong: |
| 1905 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1906 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1907 | break; |
| 1908 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1909 | case Primitive::kPrimFloat: |
| 1910 | case Primitive::kPrimDouble: |
| 1911 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1912 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1913 | break; |
| 1914 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1915 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1916 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1917 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1920 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1921 | if (kIsDebugBuild) { |
| 1922 | switch (ret->InputAt(0)->GetType()) { |
| 1923 | case Primitive::kPrimBoolean: |
| 1924 | case Primitive::kPrimByte: |
| 1925 | case Primitive::kPrimChar: |
| 1926 | case Primitive::kPrimShort: |
| 1927 | case Primitive::kPrimInt: |
| 1928 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1929 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1930 | break; |
| 1931 | |
| 1932 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1933 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1934 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1935 | break; |
| 1936 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1937 | case Primitive::kPrimFloat: |
| 1938 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1939 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1940 | break; |
| 1941 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1942 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1943 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1944 | } |
| 1945 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1946 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1949 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1950 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1951 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1952 | // the method_idx. |
| 1953 | HandleInvoke(invoke); |
| 1954 | } |
| 1955 | |
| 1956 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1957 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1958 | } |
| 1959 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1960 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1961 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1962 | // art::PrepareForRegisterAllocation. |
| 1963 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1964 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1965 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1966 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1967 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1968 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1969 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1970 | return; |
| 1971 | } |
| 1972 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1973 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1974 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1975 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1976 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1977 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1978 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1979 | } |
| 1980 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1981 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1982 | if (invoke->GetLocations()->Intrinsified()) { |
| 1983 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1984 | intrinsic.Dispatch(invoke); |
| 1985 | return true; |
| 1986 | } |
| 1987 | return false; |
| 1988 | } |
| 1989 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1990 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1991 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1992 | // art::PrepareForRegisterAllocation. |
| 1993 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1994 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1995 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1996 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1997 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1998 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1999 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2000 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2001 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2002 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2006 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2007 | if (intrinsic.TryDispatch(invoke)) { |
| 2008 | return; |
| 2009 | } |
| 2010 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2011 | HandleInvoke(invoke); |
| 2012 | } |
| 2013 | |
| 2014 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2015 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2016 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2019 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2020 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2021 | return; |
| 2022 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2023 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2024 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2025 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2026 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2029 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2030 | // This call to HandleInvoke allocates a temporary (core) register |
| 2031 | // which is also used to transfer the hidden argument from FP to |
| 2032 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2033 | HandleInvoke(invoke); |
| 2034 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2035 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2039 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2040 | LocationSummary* locations = invoke->GetLocations(); |
| 2041 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2042 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2043 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2044 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2045 | Location receiver = locations->InAt(0); |
| 2046 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2047 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2048 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2049 | // won't be modified thereafter, before the `call` instruction. |
| 2050 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2051 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2052 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2053 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2054 | if (receiver.IsStackSlot()) { |
| 2055 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2056 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2057 | __ movl(temp, Address(temp, class_offset)); |
| 2058 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2059 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2060 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2061 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2062 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2063 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2064 | // emit a read barrier for the previous class reference load. |
| 2065 | // However this is not required in practice, as this is an |
| 2066 | // intermediate/temporary reference and because the current |
| 2067 | // concurrent copying collector keeps the from-space memory |
| 2068 | // intact/accessible until the end of the marking phase (the |
| 2069 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2070 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2071 | // temp = temp->GetImtEntryAt(method_offset); |
| 2072 | __ movl(temp, Address(temp, method_offset)); |
| 2073 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2074 | __ call(Address(temp, |
| 2075 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2076 | |
| 2077 | DCHECK(!codegen_->IsLeafMethod()); |
| 2078 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2079 | } |
| 2080 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2081 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2082 | LocationSummary* locations = |
| 2083 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2084 | switch (neg->GetResultType()) { |
| 2085 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2086 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2087 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2088 | locations->SetOut(Location::SameAsFirstInput()); |
| 2089 | break; |
| 2090 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2091 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2092 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2093 | locations->SetOut(Location::SameAsFirstInput()); |
| 2094 | locations->AddTemp(Location::RequiresRegister()); |
| 2095 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2096 | break; |
| 2097 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2098 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2099 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2100 | locations->SetOut(Location::SameAsFirstInput()); |
| 2101 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2102 | break; |
| 2103 | |
| 2104 | default: |
| 2105 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2110 | LocationSummary* locations = neg->GetLocations(); |
| 2111 | Location out = locations->Out(); |
| 2112 | Location in = locations->InAt(0); |
| 2113 | switch (neg->GetResultType()) { |
| 2114 | case Primitive::kPrimInt: |
| 2115 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2116 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2117 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2118 | break; |
| 2119 | |
| 2120 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2121 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2122 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2123 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2124 | // Negation is similar to subtraction from zero. The least |
| 2125 | // significant byte triggers a borrow when it is different from |
| 2126 | // zero; to take it into account, add 1 to the most significant |
| 2127 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2128 | // operation. |
| 2129 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2130 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2131 | break; |
| 2132 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2133 | case Primitive::kPrimFloat: { |
| 2134 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2135 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2136 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2137 | // Implement float negation with an exclusive or with value |
| 2138 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2139 | // single-precision floating-point number). |
| 2140 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2141 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2142 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2143 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2144 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2145 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimDouble: { |
| 2147 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2148 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2149 | // Implement double negation with an exclusive or with value |
| 2150 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2151 | // a double-precision floating-point number). |
| 2152 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2153 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2154 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2155 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2156 | |
| 2157 | default: |
| 2158 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2159 | } |
| 2160 | } |
| 2161 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2162 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2163 | Primitive::Type result_type = conversion->GetResultType(); |
| 2164 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2165 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2166 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2167 | // The float-to-long and double-to-long type conversions rely on a |
| 2168 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2169 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2170 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2171 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2172 | ? LocationSummary::kCall |
| 2173 | : LocationSummary::kNoCall; |
| 2174 | LocationSummary* locations = |
| 2175 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2176 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2177 | // The Java language does not allow treating boolean as an integral type but |
| 2178 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2179 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2180 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2181 | case Primitive::kPrimByte: |
| 2182 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2183 | case Primitive::kPrimBoolean: |
| 2184 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2185 | case Primitive::kPrimShort: |
| 2186 | case Primitive::kPrimInt: |
| 2187 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2188 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2189 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2190 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2191 | // the validation of the linear scan implementation |
| 2192 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2193 | break; |
| 2194 | |
| 2195 | default: |
| 2196 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2197 | << " to " << result_type; |
| 2198 | } |
| 2199 | break; |
| 2200 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2201 | case Primitive::kPrimShort: |
| 2202 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2203 | case Primitive::kPrimBoolean: |
| 2204 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2205 | case Primitive::kPrimByte: |
| 2206 | case Primitive::kPrimInt: |
| 2207 | case Primitive::kPrimChar: |
| 2208 | // Processing a Dex `int-to-short' instruction. |
| 2209 | locations->SetInAt(0, Location::Any()); |
| 2210 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2211 | break; |
| 2212 | |
| 2213 | default: |
| 2214 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2215 | << " to " << result_type; |
| 2216 | } |
| 2217 | break; |
| 2218 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2219 | case Primitive::kPrimInt: |
| 2220 | switch (input_type) { |
| 2221 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2222 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2223 | locations->SetInAt(0, Location::Any()); |
| 2224 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2225 | break; |
| 2226 | |
| 2227 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2228 | // Processing a Dex `float-to-int' instruction. |
| 2229 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2230 | locations->SetOut(Location::RequiresRegister()); |
| 2231 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2232 | break; |
| 2233 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2235 | // Processing a Dex `double-to-int' instruction. |
| 2236 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2237 | locations->SetOut(Location::RequiresRegister()); |
| 2238 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | |
| 2241 | default: |
| 2242 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2243 | << " to " << result_type; |
| 2244 | } |
| 2245 | break; |
| 2246 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimLong: |
| 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 | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimByte: |
| 2252 | case Primitive::kPrimShort: |
| 2253 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2254 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2255 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2256 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2257 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2258 | break; |
| 2259 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2260 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2262 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2263 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2264 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2265 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2266 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2267 | // The runtime helper puts the result in EAX, EDX. |
| 2268 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2269 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2270 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2271 | |
| 2272 | default: |
| 2273 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2274 | << " to " << result_type; |
| 2275 | } |
| 2276 | break; |
| 2277 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimChar: |
| 2279 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimBoolean: |
| 2281 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2282 | case Primitive::kPrimByte: |
| 2283 | case Primitive::kPrimShort: |
| 2284 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2285 | // Processing a Dex `int-to-char' instruction. |
| 2286 | locations->SetInAt(0, Location::Any()); |
| 2287 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2288 | break; |
| 2289 | |
| 2290 | default: |
| 2291 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2292 | << " to " << result_type; |
| 2293 | } |
| 2294 | break; |
| 2295 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2296 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2297 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2298 | case Primitive::kPrimBoolean: |
| 2299 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2300 | case Primitive::kPrimByte: |
| 2301 | case Primitive::kPrimShort: |
| 2302 | case Primitive::kPrimInt: |
| 2303 | case Primitive::kPrimChar: |
| 2304 | // Processing a Dex `int-to-float' instruction. |
| 2305 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2306 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2307 | break; |
| 2308 | |
| 2309 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2310 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2311 | locations->SetInAt(0, Location::Any()); |
| 2312 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2313 | break; |
| 2314 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2315 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2316 | // Processing a Dex `double-to-float' instruction. |
| 2317 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2318 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2319 | break; |
| 2320 | |
| 2321 | default: |
| 2322 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2323 | << " to " << result_type; |
| 2324 | }; |
| 2325 | break; |
| 2326 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2328 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimBoolean: |
| 2330 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2331 | case Primitive::kPrimByte: |
| 2332 | case Primitive::kPrimShort: |
| 2333 | case Primitive::kPrimInt: |
| 2334 | case Primitive::kPrimChar: |
| 2335 | // Processing a Dex `int-to-double' instruction. |
| 2336 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2337 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2338 | break; |
| 2339 | |
| 2340 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2341 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2342 | locations->SetInAt(0, Location::Any()); |
| 2343 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2344 | break; |
| 2345 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2346 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2347 | // Processing a Dex `float-to-double' instruction. |
| 2348 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2349 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2350 | break; |
| 2351 | |
| 2352 | default: |
| 2353 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2354 | << " to " << result_type; |
| 2355 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2356 | break; |
| 2357 | |
| 2358 | default: |
| 2359 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2360 | << " to " << result_type; |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2365 | LocationSummary* locations = conversion->GetLocations(); |
| 2366 | Location out = locations->Out(); |
| 2367 | Location in = locations->InAt(0); |
| 2368 | Primitive::Type result_type = conversion->GetResultType(); |
| 2369 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2370 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2371 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2372 | case Primitive::kPrimByte: |
| 2373 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimBoolean: |
| 2375 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2376 | case Primitive::kPrimShort: |
| 2377 | case Primitive::kPrimInt: |
| 2378 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2379 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2380 | if (in.IsRegister()) { |
| 2381 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2382 | } else { |
| 2383 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2384 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2385 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2386 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | |
| 2389 | default: |
| 2390 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2391 | << " to " << result_type; |
| 2392 | } |
| 2393 | break; |
| 2394 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2395 | case Primitive::kPrimShort: |
| 2396 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2397 | case Primitive::kPrimBoolean: |
| 2398 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2399 | case Primitive::kPrimByte: |
| 2400 | case Primitive::kPrimInt: |
| 2401 | case Primitive::kPrimChar: |
| 2402 | // Processing a Dex `int-to-short' instruction. |
| 2403 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2404 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2405 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2406 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2407 | } else { |
| 2408 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2409 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2410 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2411 | } |
| 2412 | break; |
| 2413 | |
| 2414 | default: |
| 2415 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2416 | << " to " << result_type; |
| 2417 | } |
| 2418 | break; |
| 2419 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2420 | case Primitive::kPrimInt: |
| 2421 | switch (input_type) { |
| 2422 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2423 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2424 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2425 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2426 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2427 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2428 | } else { |
| 2429 | DCHECK(in.IsConstant()); |
| 2430 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2431 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2432 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2433 | } |
| 2434 | break; |
| 2435 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2436 | case Primitive::kPrimFloat: { |
| 2437 | // Processing a Dex `float-to-int' instruction. |
| 2438 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2439 | Register output = out.AsRegister<Register>(); |
| 2440 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2441 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2442 | |
| 2443 | __ movl(output, Immediate(kPrimIntMax)); |
| 2444 | // temp = int-to-float(output) |
| 2445 | __ cvtsi2ss(temp, output); |
| 2446 | // if input >= temp goto done |
| 2447 | __ comiss(input, temp); |
| 2448 | __ j(kAboveEqual, &done); |
| 2449 | // if input == NaN goto nan |
| 2450 | __ j(kUnordered, &nan); |
| 2451 | // output = float-to-int-truncate(input) |
| 2452 | __ cvttss2si(output, input); |
| 2453 | __ jmp(&done); |
| 2454 | __ Bind(&nan); |
| 2455 | // output = 0 |
| 2456 | __ xorl(output, output); |
| 2457 | __ Bind(&done); |
| 2458 | break; |
| 2459 | } |
| 2460 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2461 | case Primitive::kPrimDouble: { |
| 2462 | // Processing a Dex `double-to-int' instruction. |
| 2463 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2464 | Register output = out.AsRegister<Register>(); |
| 2465 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2466 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2467 | |
| 2468 | __ movl(output, Immediate(kPrimIntMax)); |
| 2469 | // temp = int-to-double(output) |
| 2470 | __ cvtsi2sd(temp, output); |
| 2471 | // if input >= temp goto done |
| 2472 | __ comisd(input, temp); |
| 2473 | __ j(kAboveEqual, &done); |
| 2474 | // if input == NaN goto nan |
| 2475 | __ j(kUnordered, &nan); |
| 2476 | // output = double-to-int-truncate(input) |
| 2477 | __ cvttsd2si(output, input); |
| 2478 | __ jmp(&done); |
| 2479 | __ Bind(&nan); |
| 2480 | // output = 0 |
| 2481 | __ xorl(output, output); |
| 2482 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2483 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2484 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2485 | |
| 2486 | default: |
| 2487 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2488 | << " to " << result_type; |
| 2489 | } |
| 2490 | break; |
| 2491 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2492 | case Primitive::kPrimLong: |
| 2493 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2494 | case Primitive::kPrimBoolean: |
| 2495 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2496 | case Primitive::kPrimByte: |
| 2497 | case Primitive::kPrimShort: |
| 2498 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2500 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2501 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2502 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2503 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2504 | __ cdq(); |
| 2505 | break; |
| 2506 | |
| 2507 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2508 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2509 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2510 | conversion, |
| 2511 | conversion->GetDexPc(), |
| 2512 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2513 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2514 | break; |
| 2515 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2517 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2518 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2519 | conversion, |
| 2520 | conversion->GetDexPc(), |
| 2521 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2522 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2523 | break; |
| 2524 | |
| 2525 | default: |
| 2526 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2527 | << " to " << result_type; |
| 2528 | } |
| 2529 | break; |
| 2530 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimChar: |
| 2532 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2533 | case Primitive::kPrimBoolean: |
| 2534 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimByte: |
| 2536 | case Primitive::kPrimShort: |
| 2537 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2538 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2539 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2540 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2541 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2542 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2543 | } else { |
| 2544 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2545 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2546 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2547 | } |
| 2548 | break; |
| 2549 | |
| 2550 | default: |
| 2551 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2552 | << " to " << result_type; |
| 2553 | } |
| 2554 | break; |
| 2555 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2556 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2557 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2558 | case Primitive::kPrimBoolean: |
| 2559 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimByte: |
| 2561 | case Primitive::kPrimShort: |
| 2562 | case Primitive::kPrimInt: |
| 2563 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2564 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2565 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2566 | break; |
| 2567 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2568 | case Primitive::kPrimLong: { |
| 2569 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2570 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2571 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2572 | // Create stack space for the call to |
| 2573 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2574 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2575 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2576 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2577 | __ subl(ESP, Immediate(adjustment)); |
| 2578 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2579 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2580 | // Load the value to the FP stack, using temporaries if needed. |
| 2581 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2582 | |
| 2583 | if (out.IsStackSlot()) { |
| 2584 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2585 | } else { |
| 2586 | __ fstps(Address(ESP, 0)); |
| 2587 | Location stack_temp = Location::StackSlot(0); |
| 2588 | codegen_->Move32(out, stack_temp); |
| 2589 | } |
| 2590 | |
| 2591 | // Remove the temporary stack space we allocated. |
| 2592 | if (adjustment != 0) { |
| 2593 | __ addl(ESP, Immediate(adjustment)); |
| 2594 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2595 | break; |
| 2596 | } |
| 2597 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2598 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2599 | // Processing a Dex `double-to-float' instruction. |
| 2600 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2601 | break; |
| 2602 | |
| 2603 | default: |
| 2604 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2605 | << " to " << result_type; |
| 2606 | }; |
| 2607 | break; |
| 2608 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2609 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2610 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2611 | case Primitive::kPrimBoolean: |
| 2612 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimByte: |
| 2614 | case Primitive::kPrimShort: |
| 2615 | case Primitive::kPrimInt: |
| 2616 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2617 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2618 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2619 | break; |
| 2620 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2621 | case Primitive::kPrimLong: { |
| 2622 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2623 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2624 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2625 | // Create stack space for the call to |
| 2626 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2627 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2628 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2629 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2630 | __ subl(ESP, Immediate(adjustment)); |
| 2631 | } |
| 2632 | |
| 2633 | // Load the value to the FP stack, using temporaries if needed. |
| 2634 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2635 | |
| 2636 | if (out.IsDoubleStackSlot()) { |
| 2637 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2638 | } else { |
| 2639 | __ fstpl(Address(ESP, 0)); |
| 2640 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2641 | codegen_->Move64(out, stack_temp); |
| 2642 | } |
| 2643 | |
| 2644 | // Remove the temporary stack space we allocated. |
| 2645 | if (adjustment != 0) { |
| 2646 | __ addl(ESP, Immediate(adjustment)); |
| 2647 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | } |
| 2650 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2651 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2652 | // Processing a Dex `float-to-double' instruction. |
| 2653 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2654 | break; |
| 2655 | |
| 2656 | default: |
| 2657 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2658 | << " to " << result_type; |
| 2659 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2660 | break; |
| 2661 | |
| 2662 | default: |
| 2663 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2664 | << " to " << result_type; |
| 2665 | } |
| 2666 | } |
| 2667 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2668 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2669 | LocationSummary* locations = |
| 2670 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2671 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2672 | case Primitive::kPrimInt: { |
| 2673 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2674 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2675 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2676 | break; |
| 2677 | } |
| 2678 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2679 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2680 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2681 | locations->SetInAt(1, Location::Any()); |
| 2682 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2683 | break; |
| 2684 | } |
| 2685 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2686 | case Primitive::kPrimFloat: |
| 2687 | case Primitive::kPrimDouble: { |
| 2688 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2689 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2690 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| 2691 | } else { |
| 2692 | locations->SetInAt(1, Location::Any()); |
| 2693 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2694 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2695 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2696 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2697 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2698 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2699 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2700 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2701 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2705 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2706 | Location first = locations->InAt(0); |
| 2707 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2708 | Location out = locations->Out(); |
| 2709 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2710 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2711 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2712 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2713 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2714 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2715 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2716 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2717 | } else { |
| 2718 | __ leal(out.AsRegister<Register>(), Address( |
| 2719 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2720 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2721 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2722 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2723 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2724 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2725 | } else { |
| 2726 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2727 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2728 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2729 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2730 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2731 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2732 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2736 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2737 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2738 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2739 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2740 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2741 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2742 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2743 | } else { |
| 2744 | DCHECK(second.IsConstant()) << second; |
| 2745 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2746 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2747 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2748 | } |
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 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2754 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2755 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2756 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2757 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2758 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2759 | codegen_->LiteralFloatAddress( |
| 2760 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2761 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2762 | } else { |
| 2763 | DCHECK(second.IsStackSlot()); |
| 2764 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2765 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2766 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | case Primitive::kPrimDouble: { |
| 2770 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2771 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2772 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2773 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2774 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2775 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2776 | codegen_->LiteralDoubleAddress( |
| 2777 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2778 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2779 | } else { |
| 2780 | DCHECK(second.IsDoubleStackSlot()); |
| 2781 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2782 | } |
| 2783 | break; |
| 2784 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2785 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2786 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2787 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2791 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2792 | LocationSummary* locations = |
| 2793 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2794 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2795 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2796 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2797 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2798 | locations->SetInAt(1, Location::Any()); |
| 2799 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2800 | break; |
| 2801 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2802 | case Primitive::kPrimFloat: |
| 2803 | case Primitive::kPrimDouble: { |
| 2804 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2805 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2806 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| 2807 | } else { |
| 2808 | locations->SetInAt(1, Location::Any()); |
| 2809 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2810 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2811 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2812 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2813 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2814 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2815 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2816 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2820 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2821 | Location first = locations->InAt(0); |
| 2822 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2823 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2824 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2825 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2826 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2827 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2828 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2829 | __ subl(first.AsRegister<Register>(), |
| 2830 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2831 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2832 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2833 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2834 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2838 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2839 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2840 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2841 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2842 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2843 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2844 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2845 | } else { |
| 2846 | DCHECK(second.IsConstant()) << second; |
| 2847 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2848 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2849 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2850 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2851 | break; |
| 2852 | } |
| 2853 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2854 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2855 | if (second.IsFpuRegister()) { |
| 2856 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2857 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2858 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2859 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2860 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2861 | codegen_->LiteralFloatAddress( |
| 2862 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2863 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2864 | } else { |
| 2865 | DCHECK(second.IsStackSlot()); |
| 2866 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2867 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2868 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2872 | if (second.IsFpuRegister()) { |
| 2873 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2874 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2875 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2876 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2877 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2878 | codegen_->LiteralDoubleAddress( |
| 2879 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2880 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2881 | } else { |
| 2882 | DCHECK(second.IsDoubleStackSlot()); |
| 2883 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2884 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2885 | break; |
| 2886 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2887 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2888 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2889 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2890 | } |
| 2891 | } |
| 2892 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2893 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2894 | LocationSummary* locations = |
| 2895 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2896 | switch (mul->GetResultType()) { |
| 2897 | case Primitive::kPrimInt: |
| 2898 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2899 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2900 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2901 | // Can use 3 operand multiply. |
| 2902 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2903 | } else { |
| 2904 | locations->SetOut(Location::SameAsFirstInput()); |
| 2905 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2906 | break; |
| 2907 | case Primitive::kPrimLong: { |
| 2908 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2909 | locations->SetInAt(1, Location::Any()); |
| 2910 | locations->SetOut(Location::SameAsFirstInput()); |
| 2911 | // Needed for imul on 32bits with 64bits output. |
| 2912 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2913 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2914 | break; |
| 2915 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2916 | case Primitive::kPrimFloat: |
| 2917 | case Primitive::kPrimDouble: { |
| 2918 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2919 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2920 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| 2921 | } else { |
| 2922 | locations->SetInAt(1, Location::Any()); |
| 2923 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2924 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2925 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2926 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2927 | |
| 2928 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2929 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2934 | LocationSummary* locations = mul->GetLocations(); |
| 2935 | Location first = locations->InAt(0); |
| 2936 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2937 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2938 | |
| 2939 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2940 | case Primitive::kPrimInt: |
| 2941 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2942 | // problems where the output may not be the same as the first operand. |
| 2943 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2944 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2945 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2946 | } else if (second.IsRegister()) { |
| 2947 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2948 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2949 | } else { |
| 2950 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2951 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2952 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2953 | } |
| 2954 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2955 | |
| 2956 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2957 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2958 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2959 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2960 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2961 | |
| 2962 | DCHECK_EQ(EAX, eax); |
| 2963 | DCHECK_EQ(EDX, edx); |
| 2964 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2965 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2966 | // output: in1 |
| 2967 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2968 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2969 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2970 | if (second.IsConstant()) { |
| 2971 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2972 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2973 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2974 | int32_t low_value = Low32Bits(value); |
| 2975 | int32_t high_value = High32Bits(value); |
| 2976 | Immediate low(low_value); |
| 2977 | Immediate high(high_value); |
| 2978 | |
| 2979 | __ movl(eax, high); |
| 2980 | // eax <- in1.lo * in2.hi |
| 2981 | __ imull(eax, in1_lo); |
| 2982 | // in1.hi <- in1.hi * in2.lo |
| 2983 | __ imull(in1_hi, low); |
| 2984 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2985 | __ addl(in1_hi, eax); |
| 2986 | // move in2_lo to eax to prepare for double precision |
| 2987 | __ movl(eax, low); |
| 2988 | // edx:eax <- in1.lo * in2.lo |
| 2989 | __ mull(in1_lo); |
| 2990 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2991 | __ addl(in1_hi, edx); |
| 2992 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2993 | __ movl(in1_lo, eax); |
| 2994 | } else if (second.IsRegisterPair()) { |
| 2995 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2996 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2997 | |
| 2998 | __ movl(eax, in2_hi); |
| 2999 | // eax <- in1.lo * in2.hi |
| 3000 | __ imull(eax, in1_lo); |
| 3001 | // in1.hi <- in1.hi * in2.lo |
| 3002 | __ imull(in1_hi, in2_lo); |
| 3003 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3004 | __ addl(in1_hi, eax); |
| 3005 | // move in1_lo to eax to prepare for double precision |
| 3006 | __ movl(eax, in1_lo); |
| 3007 | // edx:eax <- in1.lo * in2.lo |
| 3008 | __ mull(in2_lo); |
| 3009 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3010 | __ addl(in1_hi, edx); |
| 3011 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3012 | __ movl(in1_lo, eax); |
| 3013 | } else { |
| 3014 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3015 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3016 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3017 | |
| 3018 | __ movl(eax, in2_hi); |
| 3019 | // eax <- in1.lo * in2.hi |
| 3020 | __ imull(eax, in1_lo); |
| 3021 | // in1.hi <- in1.hi * in2.lo |
| 3022 | __ imull(in1_hi, in2_lo); |
| 3023 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3024 | __ addl(in1_hi, eax); |
| 3025 | // move in1_lo to eax to prepare for double precision |
| 3026 | __ movl(eax, in1_lo); |
| 3027 | // edx:eax <- in1.lo * in2.lo |
| 3028 | __ mull(in2_lo); |
| 3029 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3030 | __ addl(in1_hi, edx); |
| 3031 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3032 | __ movl(in1_lo, eax); |
| 3033 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3034 | |
| 3035 | break; |
| 3036 | } |
| 3037 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3038 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3039 | DCHECK(first.Equals(locations->Out())); |
| 3040 | if (second.IsFpuRegister()) { |
| 3041 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3042 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3043 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3044 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3045 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3046 | codegen_->LiteralFloatAddress( |
| 3047 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3048 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3049 | } else { |
| 3050 | DCHECK(second.IsStackSlot()); |
| 3051 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3052 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3053 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3057 | DCHECK(first.Equals(locations->Out())); |
| 3058 | if (second.IsFpuRegister()) { |
| 3059 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3060 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3061 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3062 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3063 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3064 | codegen_->LiteralDoubleAddress( |
| 3065 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3066 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3067 | } else { |
| 3068 | DCHECK(second.IsDoubleStackSlot()); |
| 3069 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3070 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3071 | break; |
| 3072 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3073 | |
| 3074 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3075 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3079 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3080 | uint32_t temp_offset, |
| 3081 | uint32_t stack_adjustment, |
| 3082 | bool is_fp, |
| 3083 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3084 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3085 | DCHECK(!is_wide); |
| 3086 | if (is_fp) { |
| 3087 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3088 | } else { |
| 3089 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3090 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3091 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3092 | DCHECK(is_wide); |
| 3093 | if (is_fp) { |
| 3094 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3095 | } else { |
| 3096 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3097 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3098 | } else { |
| 3099 | // 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] | 3100 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3101 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3102 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3103 | if (is_fp) { |
| 3104 | __ flds(Address(ESP, temp_offset)); |
| 3105 | } else { |
| 3106 | __ filds(Address(ESP, temp_offset)); |
| 3107 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3108 | } else { |
| 3109 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3110 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3111 | if (is_fp) { |
| 3112 | __ fldl(Address(ESP, temp_offset)); |
| 3113 | } else { |
| 3114 | __ fildl(Address(ESP, temp_offset)); |
| 3115 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3121 | Primitive::Type type = rem->GetResultType(); |
| 3122 | bool is_float = type == Primitive::kPrimFloat; |
| 3123 | size_t elem_size = Primitive::ComponentSize(type); |
| 3124 | LocationSummary* locations = rem->GetLocations(); |
| 3125 | Location first = locations->InAt(0); |
| 3126 | Location second = locations->InAt(1); |
| 3127 | Location out = locations->Out(); |
| 3128 | |
| 3129 | // Create stack space for 2 elements. |
| 3130 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3131 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3132 | |
| 3133 | // 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] | 3134 | const bool is_wide = !is_float; |
| 3135 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3136 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3137 | |
| 3138 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3139 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3140 | __ Bind(&retry); |
| 3141 | __ fprem(); |
| 3142 | |
| 3143 | // Move FP status to AX. |
| 3144 | __ fstsw(); |
| 3145 | |
| 3146 | // And see if the argument reduction is complete. This is signaled by the |
| 3147 | // C2 FPU flag bit set to 0. |
| 3148 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3149 | __ j(kNotEqual, &retry); |
| 3150 | |
| 3151 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3152 | // Store FP top of stack to real stack. |
| 3153 | if (is_float) { |
| 3154 | __ fsts(Address(ESP, 0)); |
| 3155 | } else { |
| 3156 | __ fstl(Address(ESP, 0)); |
| 3157 | } |
| 3158 | |
| 3159 | // Pop the 2 items from the FP stack. |
| 3160 | __ fucompp(); |
| 3161 | |
| 3162 | // Load the value from the stack into an XMM register. |
| 3163 | DCHECK(out.IsFpuRegister()) << out; |
| 3164 | if (is_float) { |
| 3165 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3166 | } else { |
| 3167 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3168 | } |
| 3169 | |
| 3170 | // And remove the temporary stack space we allocated. |
| 3171 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3172 | } |
| 3173 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3174 | |
| 3175 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3176 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3177 | |
| 3178 | LocationSummary* locations = instruction->GetLocations(); |
| 3179 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3180 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3181 | |
| 3182 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3183 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3184 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3185 | |
| 3186 | DCHECK(imm == 1 || imm == -1); |
| 3187 | |
| 3188 | if (instruction->IsRem()) { |
| 3189 | __ xorl(out_register, out_register); |
| 3190 | } else { |
| 3191 | __ movl(out_register, input_register); |
| 3192 | if (imm == -1) { |
| 3193 | __ negl(out_register); |
| 3194 | } |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3199 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3200 | LocationSummary* locations = instruction->GetLocations(); |
| 3201 | |
| 3202 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3203 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3204 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3205 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3206 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3207 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3208 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3209 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3210 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3211 | __ testl(input_register, input_register); |
| 3212 | __ cmovl(kGreaterEqual, num, input_register); |
| 3213 | int shift = CTZ(imm); |
| 3214 | __ sarl(num, Immediate(shift)); |
| 3215 | |
| 3216 | if (imm < 0) { |
| 3217 | __ negl(num); |
| 3218 | } |
| 3219 | |
| 3220 | __ movl(out_register, num); |
| 3221 | } |
| 3222 | |
| 3223 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3224 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3225 | |
| 3226 | LocationSummary* locations = instruction->GetLocations(); |
| 3227 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3228 | |
| 3229 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3230 | Register out = locations->Out().AsRegister<Register>(); |
| 3231 | Register num; |
| 3232 | Register edx; |
| 3233 | |
| 3234 | if (instruction->IsDiv()) { |
| 3235 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3236 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3237 | } else { |
| 3238 | edx = locations->Out().AsRegister<Register>(); |
| 3239 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3240 | } |
| 3241 | |
| 3242 | DCHECK_EQ(EAX, eax); |
| 3243 | DCHECK_EQ(EDX, edx); |
| 3244 | if (instruction->IsDiv()) { |
| 3245 | DCHECK_EQ(EAX, out); |
| 3246 | } else { |
| 3247 | DCHECK_EQ(EDX, out); |
| 3248 | } |
| 3249 | |
| 3250 | int64_t magic; |
| 3251 | int shift; |
| 3252 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3253 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3254 | NearLabel ndiv; |
| 3255 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3256 | // If numerator is 0, the result is 0, no computation needed. |
| 3257 | __ testl(eax, eax); |
| 3258 | __ j(kNotEqual, &ndiv); |
| 3259 | |
| 3260 | __ xorl(out, out); |
| 3261 | __ jmp(&end); |
| 3262 | |
| 3263 | __ Bind(&ndiv); |
| 3264 | |
| 3265 | // Save the numerator. |
| 3266 | __ movl(num, eax); |
| 3267 | |
| 3268 | // EAX = magic |
| 3269 | __ movl(eax, Immediate(magic)); |
| 3270 | |
| 3271 | // EDX:EAX = magic * numerator |
| 3272 | __ imull(num); |
| 3273 | |
| 3274 | if (imm > 0 && magic < 0) { |
| 3275 | // EDX += num |
| 3276 | __ addl(edx, num); |
| 3277 | } else if (imm < 0 && magic > 0) { |
| 3278 | __ subl(edx, num); |
| 3279 | } |
| 3280 | |
| 3281 | // Shift if needed. |
| 3282 | if (shift != 0) { |
| 3283 | __ sarl(edx, Immediate(shift)); |
| 3284 | } |
| 3285 | |
| 3286 | // EDX += 1 if EDX < 0 |
| 3287 | __ movl(eax, edx); |
| 3288 | __ shrl(edx, Immediate(31)); |
| 3289 | __ addl(edx, eax); |
| 3290 | |
| 3291 | if (instruction->IsRem()) { |
| 3292 | __ movl(eax, num); |
| 3293 | __ imull(edx, Immediate(imm)); |
| 3294 | __ subl(eax, edx); |
| 3295 | __ movl(edx, eax); |
| 3296 | } else { |
| 3297 | __ movl(eax, edx); |
| 3298 | } |
| 3299 | __ Bind(&end); |
| 3300 | } |
| 3301 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3302 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3303 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3304 | |
| 3305 | LocationSummary* locations = instruction->GetLocations(); |
| 3306 | Location out = locations->Out(); |
| 3307 | Location first = locations->InAt(0); |
| 3308 | Location second = locations->InAt(1); |
| 3309 | bool is_div = instruction->IsDiv(); |
| 3310 | |
| 3311 | switch (instruction->GetResultType()) { |
| 3312 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3313 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3314 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3315 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3316 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3317 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3318 | |
| 3319 | if (imm == 0) { |
| 3320 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3321 | } else if (imm == 1 || imm == -1) { |
| 3322 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3323 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3324 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3325 | } else { |
| 3326 | DCHECK(imm <= -2 || imm >= 2); |
| 3327 | GenerateDivRemWithAnyConstant(instruction); |
| 3328 | } |
| 3329 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3330 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3331 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3332 | is_div); |
| 3333 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3334 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3335 | Register second_reg = second.AsRegister<Register>(); |
| 3336 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3337 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3338 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3339 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3340 | __ cmpl(second_reg, Immediate(-1)); |
| 3341 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3342 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3343 | // edx:eax <- sign-extended of eax |
| 3344 | __ cdq(); |
| 3345 | // eax = quotient, edx = remainder |
| 3346 | __ idivl(second_reg); |
| 3347 | __ Bind(slow_path->GetExitLabel()); |
| 3348 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3349 | break; |
| 3350 | } |
| 3351 | |
| 3352 | case Primitive::kPrimLong: { |
| 3353 | InvokeRuntimeCallingConvention calling_convention; |
| 3354 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3355 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3356 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3357 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3358 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3359 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3360 | |
| 3361 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3362 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3363 | instruction, |
| 3364 | instruction->GetDexPc(), |
| 3365 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3366 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3367 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3368 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3369 | instruction, |
| 3370 | instruction->GetDexPc(), |
| 3371 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3372 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3373 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3374 | break; |
| 3375 | } |
| 3376 | |
| 3377 | default: |
| 3378 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3379 | } |
| 3380 | } |
| 3381 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3382 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3383 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3384 | ? LocationSummary::kCall |
| 3385 | : LocationSummary::kNoCall; |
| 3386 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3387 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3388 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3389 | case Primitive::kPrimInt: { |
| 3390 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3391 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3392 | locations->SetOut(Location::SameAsFirstInput()); |
| 3393 | // Intel uses edx:eax as the dividend. |
| 3394 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3395 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3396 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3397 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3398 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3399 | locations->AddTemp(Location::RequiresRegister()); |
| 3400 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3401 | break; |
| 3402 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3403 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3404 | InvokeRuntimeCallingConvention calling_convention; |
| 3405 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3406 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3407 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3408 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3409 | // Runtime helper puts the result in EAX, EDX. |
| 3410 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3411 | break; |
| 3412 | } |
| 3413 | case Primitive::kPrimFloat: |
| 3414 | case Primitive::kPrimDouble: { |
| 3415 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3416 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3417 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| 3418 | } else { |
| 3419 | locations->SetInAt(1, Location::Any()); |
| 3420 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3421 | locations->SetOut(Location::SameAsFirstInput()); |
| 3422 | break; |
| 3423 | } |
| 3424 | |
| 3425 | default: |
| 3426 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3427 | } |
| 3428 | } |
| 3429 | |
| 3430 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3431 | LocationSummary* locations = div->GetLocations(); |
| 3432 | Location first = locations->InAt(0); |
| 3433 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3434 | |
| 3435 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3436 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3437 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3438 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3439 | break; |
| 3440 | } |
| 3441 | |
| 3442 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3443 | if (second.IsFpuRegister()) { |
| 3444 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3445 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3446 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3447 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3448 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3449 | codegen_->LiteralFloatAddress( |
| 3450 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3451 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3452 | } else { |
| 3453 | DCHECK(second.IsStackSlot()); |
| 3454 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3455 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3456 | break; |
| 3457 | } |
| 3458 | |
| 3459 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3460 | if (second.IsFpuRegister()) { |
| 3461 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3462 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3463 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3464 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3465 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3466 | codegen_->LiteralDoubleAddress( |
| 3467 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3468 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3469 | } else { |
| 3470 | DCHECK(second.IsDoubleStackSlot()); |
| 3471 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3472 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3473 | break; |
| 3474 | } |
| 3475 | |
| 3476 | default: |
| 3477 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3478 | } |
| 3479 | } |
| 3480 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3481 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3482 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3484 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3485 | ? LocationSummary::kCall |
| 3486 | : LocationSummary::kNoCall; |
| 3487 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3488 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3489 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3490 | case Primitive::kPrimInt: { |
| 3491 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3492 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3493 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3494 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3495 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3496 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3497 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3498 | locations->AddTemp(Location::RequiresRegister()); |
| 3499 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3500 | break; |
| 3501 | } |
| 3502 | case Primitive::kPrimLong: { |
| 3503 | InvokeRuntimeCallingConvention calling_convention; |
| 3504 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3505 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3506 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3507 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3508 | // Runtime helper puts the result in EAX, EDX. |
| 3509 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3510 | break; |
| 3511 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3512 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3513 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3514 | locations->SetInAt(0, Location::Any()); |
| 3515 | locations->SetInAt(1, Location::Any()); |
| 3516 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3517 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3518 | break; |
| 3519 | } |
| 3520 | |
| 3521 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3522 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3527 | Primitive::Type type = rem->GetResultType(); |
| 3528 | switch (type) { |
| 3529 | case Primitive::kPrimInt: |
| 3530 | case Primitive::kPrimLong: { |
| 3531 | GenerateDivRemIntegral(rem); |
| 3532 | break; |
| 3533 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3534 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3535 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3536 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3537 | break; |
| 3538 | } |
| 3539 | default: |
| 3540 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3541 | } |
| 3542 | } |
| 3543 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3544 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3545 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3546 | ? LocationSummary::kCallOnSlowPath |
| 3547 | : LocationSummary::kNoCall; |
| 3548 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3549 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3550 | case Primitive::kPrimByte: |
| 3551 | case Primitive::kPrimChar: |
| 3552 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3553 | case Primitive::kPrimInt: { |
| 3554 | locations->SetInAt(0, Location::Any()); |
| 3555 | break; |
| 3556 | } |
| 3557 | case Primitive::kPrimLong: { |
| 3558 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3559 | if (!instruction->IsConstant()) { |
| 3560 | locations->AddTemp(Location::RequiresRegister()); |
| 3561 | } |
| 3562 | break; |
| 3563 | } |
| 3564 | default: |
| 3565 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3566 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3567 | if (instruction->HasUses()) { |
| 3568 | locations->SetOut(Location::SameAsFirstInput()); |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3573 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3574 | codegen_->AddSlowPath(slow_path); |
| 3575 | |
| 3576 | LocationSummary* locations = instruction->GetLocations(); |
| 3577 | Location value = locations->InAt(0); |
| 3578 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3579 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3580 | case Primitive::kPrimByte: |
| 3581 | case Primitive::kPrimChar: |
| 3582 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3583 | case Primitive::kPrimInt: { |
| 3584 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3585 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3586 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3587 | } else if (value.IsStackSlot()) { |
| 3588 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3589 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3590 | } else { |
| 3591 | DCHECK(value.IsConstant()) << value; |
| 3592 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3593 | __ jmp(slow_path->GetEntryLabel()); |
| 3594 | } |
| 3595 | } |
| 3596 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3597 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3598 | case Primitive::kPrimLong: { |
| 3599 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3600 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3601 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3602 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3603 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3604 | } else { |
| 3605 | DCHECK(value.IsConstant()) << value; |
| 3606 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3607 | __ jmp(slow_path->GetEntryLabel()); |
| 3608 | } |
| 3609 | } |
| 3610 | break; |
| 3611 | } |
| 3612 | default: |
| 3613 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3614 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3615 | } |
| 3616 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3617 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3618 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3619 | |
| 3620 | LocationSummary* locations = |
| 3621 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3622 | |
| 3623 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3624 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3625 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3626 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3627 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3628 | // The shift count needs to be in CL or a constant. |
| 3629 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3630 | locations->SetOut(Location::SameAsFirstInput()); |
| 3631 | break; |
| 3632 | } |
| 3633 | default: |
| 3634 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3639 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3640 | |
| 3641 | LocationSummary* locations = op->GetLocations(); |
| 3642 | Location first = locations->InAt(0); |
| 3643 | Location second = locations->InAt(1); |
| 3644 | DCHECK(first.Equals(locations->Out())); |
| 3645 | |
| 3646 | switch (op->GetResultType()) { |
| 3647 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3648 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3649 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3650 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3651 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3652 | DCHECK_EQ(ECX, second_reg); |
| 3653 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3654 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3655 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3656 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3657 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3658 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3659 | } |
| 3660 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3661 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3662 | if (shift == 0) { |
| 3663 | return; |
| 3664 | } |
| 3665 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3666 | if (op->IsShl()) { |
| 3667 | __ shll(first_reg, imm); |
| 3668 | } else if (op->IsShr()) { |
| 3669 | __ sarl(first_reg, imm); |
| 3670 | } else { |
| 3671 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | break; |
| 3675 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3676 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3677 | if (second.IsRegister()) { |
| 3678 | Register second_reg = second.AsRegister<Register>(); |
| 3679 | DCHECK_EQ(ECX, second_reg); |
| 3680 | if (op->IsShl()) { |
| 3681 | GenerateShlLong(first, second_reg); |
| 3682 | } else if (op->IsShr()) { |
| 3683 | GenerateShrLong(first, second_reg); |
| 3684 | } else { |
| 3685 | GenerateUShrLong(first, second_reg); |
| 3686 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3687 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3688 | // Shift by a constant. |
| 3689 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3690 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3691 | if (shift != 0) { |
| 3692 | if (op->IsShl()) { |
| 3693 | GenerateShlLong(first, shift); |
| 3694 | } else if (op->IsShr()) { |
| 3695 | GenerateShrLong(first, shift); |
| 3696 | } else { |
| 3697 | GenerateUShrLong(first, shift); |
| 3698 | } |
| 3699 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3700 | } |
| 3701 | break; |
| 3702 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3703 | default: |
| 3704 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3705 | } |
| 3706 | } |
| 3707 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3708 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3709 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3710 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3711 | if (shift == 1) { |
| 3712 | // This is just an addition. |
| 3713 | __ addl(low, low); |
| 3714 | __ adcl(high, high); |
| 3715 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3716 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3717 | codegen_->EmitParallelMoves( |
| 3718 | loc.ToLow(), |
| 3719 | loc.ToHigh(), |
| 3720 | Primitive::kPrimInt, |
| 3721 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3722 | loc.ToLow(), |
| 3723 | Primitive::kPrimInt); |
| 3724 | } else if (shift > 32) { |
| 3725 | // Low part becomes 0. High part is low part << (shift-32). |
| 3726 | __ movl(high, low); |
| 3727 | __ shll(high, Immediate(shift - 32)); |
| 3728 | __ xorl(low, low); |
| 3729 | } else { |
| 3730 | // Between 1 and 31. |
| 3731 | __ shld(high, low, Immediate(shift)); |
| 3732 | __ shll(low, Immediate(shift)); |
| 3733 | } |
| 3734 | } |
| 3735 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3736 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3737 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3738 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3739 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3740 | __ testl(shifter, Immediate(32)); |
| 3741 | __ j(kEqual, &done); |
| 3742 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3743 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3744 | __ Bind(&done); |
| 3745 | } |
| 3746 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3747 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3748 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3749 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3750 | if (shift == 32) { |
| 3751 | // Need to copy the sign. |
| 3752 | DCHECK_NE(low, high); |
| 3753 | __ movl(low, high); |
| 3754 | __ sarl(high, Immediate(31)); |
| 3755 | } else if (shift > 32) { |
| 3756 | DCHECK_NE(low, high); |
| 3757 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3758 | __ movl(low, high); |
| 3759 | __ sarl(high, Immediate(31)); |
| 3760 | __ sarl(low, Immediate(shift - 32)); |
| 3761 | } else { |
| 3762 | // Between 1 and 31. |
| 3763 | __ shrd(low, high, Immediate(shift)); |
| 3764 | __ sarl(high, Immediate(shift)); |
| 3765 | } |
| 3766 | } |
| 3767 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3768 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3769 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3770 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3771 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3772 | __ testl(shifter, Immediate(32)); |
| 3773 | __ j(kEqual, &done); |
| 3774 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3775 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3776 | __ Bind(&done); |
| 3777 | } |
| 3778 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3779 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3780 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3781 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3782 | if (shift == 32) { |
| 3783 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3784 | codegen_->EmitParallelMoves( |
| 3785 | loc.ToHigh(), |
| 3786 | loc.ToLow(), |
| 3787 | Primitive::kPrimInt, |
| 3788 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3789 | loc.ToHigh(), |
| 3790 | Primitive::kPrimInt); |
| 3791 | } else if (shift > 32) { |
| 3792 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3793 | __ movl(low, high); |
| 3794 | __ shrl(low, Immediate(shift - 32)); |
| 3795 | __ xorl(high, high); |
| 3796 | } else { |
| 3797 | // Between 1 and 31. |
| 3798 | __ shrd(low, high, Immediate(shift)); |
| 3799 | __ shrl(high, Immediate(shift)); |
| 3800 | } |
| 3801 | } |
| 3802 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3803 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3804 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3805 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3806 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3807 | __ testl(shifter, Immediate(32)); |
| 3808 | __ j(kEqual, &done); |
| 3809 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3810 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3811 | __ Bind(&done); |
| 3812 | } |
| 3813 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3814 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3815 | LocationSummary* locations = |
| 3816 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3817 | |
| 3818 | switch (ror->GetResultType()) { |
| 3819 | case Primitive::kPrimLong: |
| 3820 | // Add the temporary needed. |
| 3821 | locations->AddTemp(Location::RequiresRegister()); |
| 3822 | FALLTHROUGH_INTENDED; |
| 3823 | case Primitive::kPrimInt: |
| 3824 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3825 | // The shift count needs to be in CL (unless it is a constant). |
| 3826 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3827 | locations->SetOut(Location::SameAsFirstInput()); |
| 3828 | break; |
| 3829 | default: |
| 3830 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3831 | UNREACHABLE(); |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3836 | LocationSummary* locations = ror->GetLocations(); |
| 3837 | Location first = locations->InAt(0); |
| 3838 | Location second = locations->InAt(1); |
| 3839 | |
| 3840 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3841 | Register first_reg = first.AsRegister<Register>(); |
| 3842 | if (second.IsRegister()) { |
| 3843 | Register second_reg = second.AsRegister<Register>(); |
| 3844 | __ rorl(first_reg, second_reg); |
| 3845 | } else { |
| 3846 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3847 | __ rorl(first_reg, imm); |
| 3848 | } |
| 3849 | return; |
| 3850 | } |
| 3851 | |
| 3852 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3853 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3854 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3855 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3856 | if (second.IsRegister()) { |
| 3857 | Register second_reg = second.AsRegister<Register>(); |
| 3858 | DCHECK_EQ(second_reg, ECX); |
| 3859 | __ movl(temp_reg, first_reg_hi); |
| 3860 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3861 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3862 | __ movl(temp_reg, first_reg_hi); |
| 3863 | __ testl(second_reg, Immediate(32)); |
| 3864 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3865 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3866 | } else { |
| 3867 | int32_t shift_amt = |
| 3868 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3869 | if (shift_amt == 0) { |
| 3870 | // Already fine. |
| 3871 | return; |
| 3872 | } |
| 3873 | if (shift_amt == 32) { |
| 3874 | // Just swap. |
| 3875 | __ movl(temp_reg, first_reg_lo); |
| 3876 | __ movl(first_reg_lo, first_reg_hi); |
| 3877 | __ movl(first_reg_hi, temp_reg); |
| 3878 | return; |
| 3879 | } |
| 3880 | |
| 3881 | Immediate imm(shift_amt); |
| 3882 | // Save the constents of the low value. |
| 3883 | __ movl(temp_reg, first_reg_lo); |
| 3884 | |
| 3885 | // Shift right into low, feeding bits from high. |
| 3886 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3887 | |
| 3888 | // Shift right into high, feeding bits from the original low. |
| 3889 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3890 | |
| 3891 | // Swap if needed. |
| 3892 | if (shift_amt > 32) { |
| 3893 | __ movl(temp_reg, first_reg_lo); |
| 3894 | __ movl(first_reg_lo, first_reg_hi); |
| 3895 | __ movl(first_reg_hi, temp_reg); |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3900 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3901 | HandleShift(shl); |
| 3902 | } |
| 3903 | |
| 3904 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3905 | HandleShift(shl); |
| 3906 | } |
| 3907 | |
| 3908 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3909 | HandleShift(shr); |
| 3910 | } |
| 3911 | |
| 3912 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3913 | HandleShift(shr); |
| 3914 | } |
| 3915 | |
| 3916 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3917 | HandleShift(ushr); |
| 3918 | } |
| 3919 | |
| 3920 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3921 | HandleShift(ushr); |
| 3922 | } |
| 3923 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3924 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3925 | LocationSummary* locations = |
| 3926 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3927 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3928 | if (instruction->IsStringAlloc()) { |
| 3929 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3930 | } else { |
| 3931 | InvokeRuntimeCallingConvention calling_convention; |
| 3932 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3933 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3934 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3938 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3939 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3940 | if (instruction->IsStringAlloc()) { |
| 3941 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3942 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3943 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3944 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3945 | __ call(Address(temp, code_offset.Int32Value())); |
| 3946 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3947 | } else { |
| 3948 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3949 | instruction, |
| 3950 | instruction->GetDexPc(), |
| 3951 | nullptr); |
| 3952 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3953 | DCHECK(!codegen_->IsLeafMethod()); |
| 3954 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3955 | } |
| 3956 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3957 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3958 | LocationSummary* locations = |
| 3959 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3960 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3961 | InvokeRuntimeCallingConvention calling_convention; |
| 3962 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3963 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3964 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3968 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3969 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3970 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3971 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3972 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3973 | instruction, |
| 3974 | instruction->GetDexPc(), |
| 3975 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3976 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3977 | DCHECK(!codegen_->IsLeafMethod()); |
| 3978 | } |
| 3979 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3980 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3981 | LocationSummary* locations = |
| 3982 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3983 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3984 | if (location.IsStackSlot()) { |
| 3985 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3986 | } else if (location.IsDoubleStackSlot()) { |
| 3987 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3988 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3989 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3990 | } |
| 3991 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3992 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3993 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3994 | } |
| 3995 | |
| 3996 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3997 | LocationSummary* locations = |
| 3998 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3999 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4000 | } |
| 4001 | |
| 4002 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4003 | } |
| 4004 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4005 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4006 | LocationSummary* locations = |
| 4007 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4009 | locations->SetOut(Location::RequiresRegister()); |
| 4010 | } |
| 4011 | |
| 4012 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4013 | LocationSummary* locations = instruction->GetLocations(); |
| 4014 | uint32_t method_offset = 0; |
| 4015 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4016 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4017 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4018 | } else { |
| 4019 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4020 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4021 | } |
| 4022 | __ movl(locations->Out().AsRegister<Register>(), |
| 4023 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4024 | } |
| 4025 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4026 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4027 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4028 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4029 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4030 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4031 | } |
| 4032 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4033 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4034 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4035 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4036 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4037 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4038 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4039 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4040 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4041 | break; |
| 4042 | |
| 4043 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4044 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4045 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4046 | break; |
| 4047 | |
| 4048 | default: |
| 4049 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4050 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4051 | } |
| 4052 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4053 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4054 | LocationSummary* locations = |
| 4055 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4056 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4057 | locations->SetOut(Location::SameAsFirstInput()); |
| 4058 | } |
| 4059 | |
| 4060 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4061 | LocationSummary* locations = bool_not->GetLocations(); |
| 4062 | Location in = locations->InAt(0); |
| 4063 | Location out = locations->Out(); |
| 4064 | DCHECK(in.Equals(out)); |
| 4065 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4066 | } |
| 4067 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4068 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4069 | LocationSummary* locations = |
| 4070 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4071 | switch (compare->InputAt(0)->GetType()) { |
| 4072 | case Primitive::kPrimLong: { |
| 4073 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4074 | locations->SetInAt(1, Location::Any()); |
| 4075 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4076 | break; |
| 4077 | } |
| 4078 | case Primitive::kPrimFloat: |
| 4079 | case Primitive::kPrimDouble: { |
| 4080 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 4081 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4082 | locations->SetOut(Location::RequiresRegister()); |
| 4083 | break; |
| 4084 | } |
| 4085 | default: |
| 4086 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4087 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4091 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4092 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4093 | Location left = locations->InAt(0); |
| 4094 | Location right = locations->InAt(1); |
| 4095 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4096 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4097 | switch (compare->InputAt(0)->GetType()) { |
| 4098 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4099 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4100 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4101 | int32_t val_low = 0; |
| 4102 | int32_t val_high = 0; |
| 4103 | bool right_is_const = false; |
| 4104 | |
| 4105 | if (right.IsConstant()) { |
| 4106 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4107 | right_is_const = true; |
| 4108 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4109 | val_low = Low32Bits(val); |
| 4110 | val_high = High32Bits(val); |
| 4111 | } |
| 4112 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4113 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4114 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4115 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4116 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4117 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4118 | DCHECK(right_is_const) << right; |
| 4119 | if (val_high == 0) { |
| 4120 | __ testl(left_high, left_high); |
| 4121 | } else { |
| 4122 | __ cmpl(left_high, Immediate(val_high)); |
| 4123 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4124 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4125 | __ j(kLess, &less); // Signed compare. |
| 4126 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4127 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4128 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4129 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4130 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4131 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4132 | DCHECK(right_is_const) << right; |
| 4133 | if (val_low == 0) { |
| 4134 | __ testl(left_low, left_low); |
| 4135 | } else { |
| 4136 | __ cmpl(left_low, Immediate(val_low)); |
| 4137 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4138 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4139 | break; |
| 4140 | } |
| 4141 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 4142 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4143 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4144 | break; |
| 4145 | } |
| 4146 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 4147 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4148 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4149 | break; |
| 4150 | } |
| 4151 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4152 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4153 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4154 | __ movl(out, Immediate(0)); |
| 4155 | __ j(kEqual, &done); |
| 4156 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4157 | |
| 4158 | __ Bind(&greater); |
| 4159 | __ movl(out, Immediate(1)); |
| 4160 | __ jmp(&done); |
| 4161 | |
| 4162 | __ Bind(&less); |
| 4163 | __ movl(out, Immediate(-1)); |
| 4164 | |
| 4165 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4166 | } |
| 4167 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4168 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4169 | LocationSummary* locations = |
| 4170 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4171 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4172 | locations->SetInAt(i, Location::Any()); |
| 4173 | } |
| 4174 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4177 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4178 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4181 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4182 | /* |
| 4183 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4184 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4185 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4186 | */ |
| 4187 | switch (kind) { |
| 4188 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4189 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4190 | break; |
| 4191 | } |
| 4192 | case MemBarrierKind::kAnyStore: |
| 4193 | case MemBarrierKind::kLoadAny: |
| 4194 | case MemBarrierKind::kStoreStore: { |
| 4195 | // nop |
| 4196 | break; |
| 4197 | } |
| 4198 | default: |
| 4199 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4200 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4201 | } |
| 4202 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4203 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4204 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4205 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4206 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4207 | |
| 4208 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4209 | // is incompatible with it. |
| 4210 | if (GetGraph()->HasIrreducibleLoops() && |
| 4211 | (dispatch_info.method_load_kind == |
| 4212 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4213 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4214 | } |
| 4215 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4216 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4217 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4218 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4219 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4220 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4221 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4222 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4223 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4224 | 0u |
| 4225 | }; |
| 4226 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4227 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4228 | } |
| 4229 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4230 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4231 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4232 | Register temp) { |
| 4233 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4234 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4235 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4236 | return location.AsRegister<Register>(); |
| 4237 | } |
| 4238 | // For intrinsics we allow any location, so it may be on the stack. |
| 4239 | if (!location.IsRegister()) { |
| 4240 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4241 | return temp; |
| 4242 | } |
| 4243 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4244 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4245 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4246 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4247 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4248 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4249 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4250 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4251 | __ movl(temp, Address(ESP, stack_offset)); |
| 4252 | return temp; |
| 4253 | } |
| 4254 | return location.AsRegister<Register>(); |
| 4255 | } |
| 4256 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4257 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4258 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4259 | switch (invoke->GetMethodLoadKind()) { |
| 4260 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4261 | // temp = thread->string_init_entrypoint |
| 4262 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4263 | break; |
| 4264 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4265 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4266 | break; |
| 4267 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4268 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4269 | break; |
| 4270 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4271 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4272 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4273 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4274 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4275 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4276 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4277 | temp.AsRegister<Register>()); |
| 4278 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4279 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4280 | // Add the patch entry and bind its label at the end of the instruction. |
| 4281 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4282 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4283 | break; |
| 4284 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4285 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4286 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4287 | Register method_reg; |
| 4288 | Register reg = temp.AsRegister<Register>(); |
| 4289 | if (current_method.IsRegister()) { |
| 4290 | method_reg = current_method.AsRegister<Register>(); |
| 4291 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4292 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4293 | DCHECK(!current_method.IsValid()); |
| 4294 | method_reg = reg; |
| 4295 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4296 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4297 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4298 | __ movl(reg, Address(method_reg, |
| 4299 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4300 | // temp = temp[index_in_cache] |
| 4301 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4302 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4303 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4304 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | switch (invoke->GetCodePtrLocation()) { |
| 4308 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4309 | __ call(GetFrameEntryLabel()); |
| 4310 | break; |
| 4311 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4312 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4313 | Label* label = &relative_call_patches_.back().label; |
| 4314 | __ call(label); // Bind to the patch label, override at link time. |
| 4315 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4316 | break; |
| 4317 | } |
| 4318 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4319 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4320 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4321 | LOG(FATAL) << "Unsupported"; |
| 4322 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4323 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4324 | // (callee_method + offset_of_quick_compiled_code)() |
| 4325 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4326 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4327 | kX86WordSize).Int32Value())); |
| 4328 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4329 | } |
| 4330 | |
| 4331 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4332 | } |
| 4333 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4334 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4335 | Register temp = temp_in.AsRegister<Register>(); |
| 4336 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4337 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4338 | |
| 4339 | // Use the calling convention instead of the location of the receiver, as |
| 4340 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4341 | // slow path, the arguments have been moved to the right place, so here we are |
| 4342 | // guaranteed that the receiver is the first register of the calling convention. |
| 4343 | InvokeDexCallingConvention calling_convention; |
| 4344 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4345 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4346 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4347 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4348 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4349 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4350 | // emit a read barrier for the previous class reference load. |
| 4351 | // However this is not required in practice, as this is an |
| 4352 | // intermediate/temporary reference and because the current |
| 4353 | // concurrent copying collector keeps the from-space memory |
| 4354 | // intact/accessible until the end of the marking phase (the |
| 4355 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4356 | __ MaybeUnpoisonHeapReference(temp); |
| 4357 | // temp = temp->GetMethodAt(method_offset); |
| 4358 | __ movl(temp, Address(temp, method_offset)); |
| 4359 | // call temp->GetEntryPoint(); |
| 4360 | __ call(Address( |
| 4361 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4362 | } |
| 4363 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4364 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4365 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4366 | size_t size = |
| 4367 | method_patches_.size() + |
| 4368 | relative_call_patches_.size() + |
| 4369 | pc_relative_dex_cache_patches_.size(); |
| 4370 | linker_patches->reserve(size); |
| 4371 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4372 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4373 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4374 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4375 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4376 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4377 | info.target_method.dex_file, |
| 4378 | info.target_method.dex_method_index)); |
| 4379 | } |
| 4380 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4381 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4382 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4383 | info.target_method.dex_file, |
| 4384 | info.target_method.dex_method_index)); |
| 4385 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4386 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4387 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4388 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4389 | &info.target_dex_file, |
| 4390 | GetMethodAddressOffset(), |
| 4391 | info.element_offset)); |
| 4392 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4395 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4396 | Register card, |
| 4397 | Register object, |
| 4398 | Register value, |
| 4399 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4400 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4401 | if (value_can_be_null) { |
| 4402 | __ testl(value, value); |
| 4403 | __ j(kEqual, &is_null); |
| 4404 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4405 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4406 | __ movl(temp, object); |
| 4407 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4408 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4409 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4410 | if (value_can_be_null) { |
| 4411 | __ Bind(&is_null); |
| 4412 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4413 | } |
| 4414 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4415 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4416 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4417 | |
| 4418 | bool object_field_get_with_read_barrier = |
| 4419 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4420 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4421 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4422 | kEmitCompilerReadBarrier ? |
| 4423 | LocationSummary::kCallOnSlowPath : |
| 4424 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4425 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4426 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4427 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4428 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4429 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4430 | // The output overlaps in case of long: we don't want the low move |
| 4431 | // to overwrite the object's location. Likewise, in the case of |
| 4432 | // an object field get with read barriers enabled, we do not want |
| 4433 | // the move to overwrite the object's location, as we need it to emit |
| 4434 | // the read barrier. |
| 4435 | locations->SetOut( |
| 4436 | Location::RequiresRegister(), |
| 4437 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4438 | Location::kOutputOverlap : |
| 4439 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4440 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4441 | |
| 4442 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4443 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4444 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4445 | // load the temp into the XMM and then copy the XMM into the |
| 4446 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4447 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4448 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4449 | // We need a temporary register for the read barrier marking slow |
| 4450 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4451 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4452 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4455 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4456 | const FieldInfo& field_info) { |
| 4457 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4458 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4459 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4460 | Location base_loc = locations->InAt(0); |
| 4461 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4462 | Location out = locations->Out(); |
| 4463 | bool is_volatile = field_info.IsVolatile(); |
| 4464 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4465 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4466 | |
| 4467 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4468 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4469 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4470 | break; |
| 4471 | } |
| 4472 | |
| 4473 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4474 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4475 | break; |
| 4476 | } |
| 4477 | |
| 4478 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4479 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4480 | break; |
| 4481 | } |
| 4482 | |
| 4483 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4484 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | break; |
| 4486 | } |
| 4487 | |
| 4488 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4489 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4490 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4491 | |
| 4492 | case Primitive::kPrimNot: { |
| 4493 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4494 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4495 | Location temp_loc = locations->GetTemp(0); |
| 4496 | // Note that a potential implicit null check is handled in this |
| 4497 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4498 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4499 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4500 | if (is_volatile) { |
| 4501 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4502 | } |
| 4503 | } else { |
| 4504 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4505 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4506 | if (is_volatile) { |
| 4507 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4508 | } |
| 4509 | // If read barriers are enabled, emit read barriers other than |
| 4510 | // Baker's using a slow path (and also unpoison the loaded |
| 4511 | // reference, if heap poisoning is enabled). |
| 4512 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4513 | } |
| 4514 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4518 | if (is_volatile) { |
| 4519 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4520 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4521 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4522 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4523 | __ psrlq(temp, Immediate(32)); |
| 4524 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4525 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4526 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4527 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4528 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4529 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4530 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4531 | break; |
| 4532 | } |
| 4533 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4534 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4536 | break; |
| 4537 | } |
| 4538 | |
| 4539 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4541 | break; |
| 4542 | } |
| 4543 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4544 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4546 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4547 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4548 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4549 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4550 | // Potential implicit null checks, in the case of reference or |
| 4551 | // long fields, are handled in the previous switch statement. |
| 4552 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4553 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4554 | } |
| 4555 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4556 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4557 | if (field_type == Primitive::kPrimNot) { |
| 4558 | // Memory barriers, in the case of references, are also handled |
| 4559 | // in the previous switch statement. |
| 4560 | } else { |
| 4561 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4562 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4563 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4567 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4568 | |
| 4569 | LocationSummary* locations = |
| 4570 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4571 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4572 | bool is_volatile = field_info.IsVolatile(); |
| 4573 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4574 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4575 | || (field_type == Primitive::kPrimByte); |
| 4576 | |
| 4577 | // The register allocator does not support multiple |
| 4578 | // inputs that die at entry with one in a specific register. |
| 4579 | if (is_byte_type) { |
| 4580 | // Ensure the value is in a byte register. |
| 4581 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4582 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4583 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4584 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4585 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4586 | } else { |
| 4587 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4588 | } |
| 4589 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4590 | // 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] | 4591 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4592 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4593 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4594 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4595 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4596 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4597 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4598 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4599 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4600 | } else { |
| 4601 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4602 | |
| 4603 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4604 | // Temporary registers for the write barrier. |
| 4605 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4606 | // Ensure the card is in a byte register. |
| 4607 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4608 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4613 | const FieldInfo& field_info, |
| 4614 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4615 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4616 | |
| 4617 | LocationSummary* locations = instruction->GetLocations(); |
| 4618 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4619 | Location value = locations->InAt(1); |
| 4620 | bool is_volatile = field_info.IsVolatile(); |
| 4621 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4622 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4623 | bool needs_write_barrier = |
| 4624 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4625 | |
| 4626 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4627 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4628 | } |
| 4629 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4630 | bool maybe_record_implicit_null_check_done = false; |
| 4631 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4632 | switch (field_type) { |
| 4633 | case Primitive::kPrimBoolean: |
| 4634 | case Primitive::kPrimByte: { |
| 4635 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4636 | break; |
| 4637 | } |
| 4638 | |
| 4639 | case Primitive::kPrimShort: |
| 4640 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4641 | if (value.IsConstant()) { |
| 4642 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4643 | __ movw(Address(base, offset), Immediate(v)); |
| 4644 | } else { |
| 4645 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4646 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4647 | break; |
| 4648 | } |
| 4649 | |
| 4650 | case Primitive::kPrimInt: |
| 4651 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4652 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4653 | // Note that in the case where `value` is a null reference, |
| 4654 | // we do not enter this block, as the reference does not |
| 4655 | // need poisoning. |
| 4656 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4657 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4658 | __ movl(temp, value.AsRegister<Register>()); |
| 4659 | __ PoisonHeapReference(temp); |
| 4660 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4661 | } else if (value.IsConstant()) { |
| 4662 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4663 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4664 | } else { |
| 4665 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4666 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4667 | break; |
| 4668 | } |
| 4669 | |
| 4670 | case Primitive::kPrimLong: { |
| 4671 | if (is_volatile) { |
| 4672 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4673 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4674 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4675 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4676 | __ punpckldq(temp1, temp2); |
| 4677 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4678 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4679 | } else if (value.IsConstant()) { |
| 4680 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4681 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4682 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4683 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4684 | } else { |
| 4685 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4686 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4688 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4689 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4690 | break; |
| 4691 | } |
| 4692 | |
| 4693 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4694 | if (value.IsConstant()) { |
| 4695 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4696 | __ movl(Address(base, offset), Immediate(v)); |
| 4697 | } else { |
| 4698 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4699 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4700 | break; |
| 4701 | } |
| 4702 | |
| 4703 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4704 | if (value.IsConstant()) { |
| 4705 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4706 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4707 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4708 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4709 | maybe_record_implicit_null_check_done = true; |
| 4710 | } else { |
| 4711 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4712 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4713 | break; |
| 4714 | } |
| 4715 | |
| 4716 | case Primitive::kPrimVoid: |
| 4717 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4718 | UNREACHABLE(); |
| 4719 | } |
| 4720 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4721 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4722 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4723 | } |
| 4724 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4725 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4726 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4727 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4728 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4731 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4732 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4733 | } |
| 4734 | } |
| 4735 | |
| 4736 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4737 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4738 | } |
| 4739 | |
| 4740 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4741 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4742 | } |
| 4743 | |
| 4744 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4745 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4746 | } |
| 4747 | |
| 4748 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4749 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4753 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4754 | } |
| 4755 | |
| 4756 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4757 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4761 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4762 | } |
| 4763 | |
| 4764 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4765 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4766 | } |
| 4767 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4768 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4769 | HUnresolvedInstanceFieldGet* instruction) { |
| 4770 | FieldAccessCallingConventionX86 calling_convention; |
| 4771 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4772 | instruction, instruction->GetFieldType(), calling_convention); |
| 4773 | } |
| 4774 | |
| 4775 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4776 | HUnresolvedInstanceFieldGet* instruction) { |
| 4777 | FieldAccessCallingConventionX86 calling_convention; |
| 4778 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4779 | instruction->GetFieldType(), |
| 4780 | instruction->GetFieldIndex(), |
| 4781 | instruction->GetDexPc(), |
| 4782 | calling_convention); |
| 4783 | } |
| 4784 | |
| 4785 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4786 | HUnresolvedInstanceFieldSet* instruction) { |
| 4787 | FieldAccessCallingConventionX86 calling_convention; |
| 4788 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4789 | instruction, instruction->GetFieldType(), calling_convention); |
| 4790 | } |
| 4791 | |
| 4792 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4793 | HUnresolvedInstanceFieldSet* instruction) { |
| 4794 | FieldAccessCallingConventionX86 calling_convention; |
| 4795 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4796 | instruction->GetFieldType(), |
| 4797 | instruction->GetFieldIndex(), |
| 4798 | instruction->GetDexPc(), |
| 4799 | calling_convention); |
| 4800 | } |
| 4801 | |
| 4802 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4803 | HUnresolvedStaticFieldGet* instruction) { |
| 4804 | FieldAccessCallingConventionX86 calling_convention; |
| 4805 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4806 | instruction, instruction->GetFieldType(), calling_convention); |
| 4807 | } |
| 4808 | |
| 4809 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4810 | HUnresolvedStaticFieldGet* instruction) { |
| 4811 | FieldAccessCallingConventionX86 calling_convention; |
| 4812 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4813 | instruction->GetFieldType(), |
| 4814 | instruction->GetFieldIndex(), |
| 4815 | instruction->GetDexPc(), |
| 4816 | calling_convention); |
| 4817 | } |
| 4818 | |
| 4819 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4820 | HUnresolvedStaticFieldSet* instruction) { |
| 4821 | FieldAccessCallingConventionX86 calling_convention; |
| 4822 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4823 | instruction, instruction->GetFieldType(), calling_convention); |
| 4824 | } |
| 4825 | |
| 4826 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4827 | HUnresolvedStaticFieldSet* instruction) { |
| 4828 | FieldAccessCallingConventionX86 calling_convention; |
| 4829 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4830 | instruction->GetFieldType(), |
| 4831 | instruction->GetFieldIndex(), |
| 4832 | instruction->GetDexPc(), |
| 4833 | calling_convention); |
| 4834 | } |
| 4835 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4836 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4837 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4838 | ? LocationSummary::kCallOnSlowPath |
| 4839 | : LocationSummary::kNoCall; |
| 4840 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4841 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4842 | ? Location::RequiresRegister() |
| 4843 | : Location::Any(); |
| 4844 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4845 | if (instruction->HasUses()) { |
| 4846 | locations->SetOut(Location::SameAsFirstInput()); |
| 4847 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4848 | } |
| 4849 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4850 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4851 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4852 | return; |
| 4853 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4854 | LocationSummary* locations = instruction->GetLocations(); |
| 4855 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4856 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4857 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4858 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4859 | } |
| 4860 | |
| 4861 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4862 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4863 | codegen_->AddSlowPath(slow_path); |
| 4864 | |
| 4865 | LocationSummary* locations = instruction->GetLocations(); |
| 4866 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4867 | |
| 4868 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4869 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4870 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4871 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4872 | } else { |
| 4873 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4874 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4875 | __ jmp(slow_path->GetEntryLabel()); |
| 4876 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4877 | } |
| 4878 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4879 | } |
| 4880 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4881 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4882 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4883 | GenerateImplicitNullCheck(instruction); |
| 4884 | } else { |
| 4885 | GenerateExplicitNullCheck(instruction); |
| 4886 | } |
| 4887 | } |
| 4888 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4889 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4890 | bool object_array_get_with_read_barrier = |
| 4891 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4892 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4893 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4894 | object_array_get_with_read_barrier ? |
| 4895 | LocationSummary::kCallOnSlowPath : |
| 4896 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4897 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4898 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4899 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4900 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4901 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4902 | // The output overlaps in case of long: we don't want the low move |
| 4903 | // to overwrite the array's location. Likewise, in the case of an |
| 4904 | // object array get with read barriers enabled, we do not want the |
| 4905 | // move to overwrite the array's location, as we need it to emit |
| 4906 | // the read barrier. |
| 4907 | locations->SetOut( |
| 4908 | Location::RequiresRegister(), |
| 4909 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4910 | Location::kOutputOverlap : |
| 4911 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4912 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4913 | // We need a temporary register for the read barrier marking slow |
| 4914 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4915 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4916 | locations->AddTemp(Location::RequiresRegister()); |
| 4917 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4921 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4922 | Location obj_loc = locations->InAt(0); |
| 4923 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4924 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4925 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4926 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4927 | Primitive::Type type = instruction->GetType(); |
| 4928 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4929 | case Primitive::kPrimBoolean: { |
| 4930 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4931 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4932 | if (index.IsConstant()) { |
| 4933 | __ movzxb(out, Address(obj, |
| 4934 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4935 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4936 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4937 | } |
| 4938 | break; |
| 4939 | } |
| 4940 | |
| 4941 | case Primitive::kPrimByte: { |
| 4942 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4943 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4944 | if (index.IsConstant()) { |
| 4945 | __ movsxb(out, Address(obj, |
| 4946 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4947 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4948 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4949 | } |
| 4950 | break; |
| 4951 | } |
| 4952 | |
| 4953 | case Primitive::kPrimShort: { |
| 4954 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4955 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4956 | if (index.IsConstant()) { |
| 4957 | __ movsxw(out, Address(obj, |
| 4958 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4959 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4960 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4961 | } |
| 4962 | break; |
| 4963 | } |
| 4964 | |
| 4965 | case Primitive::kPrimChar: { |
| 4966 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4967 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4968 | if (index.IsConstant()) { |
| 4969 | __ movzxw(out, Address(obj, |
| 4970 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4971 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4972 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4973 | } |
| 4974 | break; |
| 4975 | } |
| 4976 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4977 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4978 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4979 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4980 | if (index.IsConstant()) { |
| 4981 | __ movl(out, Address(obj, |
| 4982 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4983 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4984 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4985 | } |
| 4986 | break; |
| 4987 | } |
| 4988 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4989 | case Primitive::kPrimNot: { |
| 4990 | static_assert( |
| 4991 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4992 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4993 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4994 | // /* HeapReference<Object> */ out = |
| 4995 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4996 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4997 | Location temp = locations->GetTemp(0); |
| 4998 | // Note that a potential implicit null check is handled in this |
| 4999 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5000 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5001 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5002 | } else { |
| 5003 | Register out = out_loc.AsRegister<Register>(); |
| 5004 | if (index.IsConstant()) { |
| 5005 | uint32_t offset = |
| 5006 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5007 | __ movl(out, Address(obj, offset)); |
| 5008 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5009 | // If read barriers are enabled, emit read barriers other than |
| 5010 | // Baker's using a slow path (and also unpoison the loaded |
| 5011 | // reference, if heap poisoning is enabled). |
| 5012 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5013 | } else { |
| 5014 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5015 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5016 | // If read barriers are enabled, emit read barriers other than |
| 5017 | // Baker's using a slow path (and also unpoison the loaded |
| 5018 | // reference, if heap poisoning is enabled). |
| 5019 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5020 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5021 | } |
| 5022 | } |
| 5023 | break; |
| 5024 | } |
| 5025 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5026 | case Primitive::kPrimLong: { |
| 5027 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5028 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | if (index.IsConstant()) { |
| 5030 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5031 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5032 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5033 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5034 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5035 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5036 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5037 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5038 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5039 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5040 | } |
| 5041 | break; |
| 5042 | } |
| 5043 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5044 | case Primitive::kPrimFloat: { |
| 5045 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5046 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5047 | if (index.IsConstant()) { |
| 5048 | __ movss(out, Address(obj, |
| 5049 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5050 | } else { |
| 5051 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5052 | } |
| 5053 | break; |
| 5054 | } |
| 5055 | |
| 5056 | case Primitive::kPrimDouble: { |
| 5057 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5058 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5059 | if (index.IsConstant()) { |
| 5060 | __ movsd(out, Address(obj, |
| 5061 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5062 | } else { |
| 5063 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5064 | } |
| 5065 | break; |
| 5066 | } |
| 5067 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5068 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5069 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5070 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5072 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5073 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5074 | // Potential implicit null checks, in the case of reference or |
| 5075 | // long arrays, are handled in the previous switch statement. |
| 5076 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5077 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5078 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5082 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5083 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5084 | bool needs_write_barrier = |
| 5085 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5086 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5087 | bool object_array_set_with_read_barrier = |
| 5088 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5089 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5090 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5091 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5092 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5093 | LocationSummary::kCallOnSlowPath : |
| 5094 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5095 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5096 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5097 | || (value_type == Primitive::kPrimByte); |
| 5098 | // We need the inputs to be different than the output in case of long operation. |
| 5099 | // In case of a byte operation, the register allocator does not support multiple |
| 5100 | // inputs that die at entry with one in a specific register. |
| 5101 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5102 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5103 | if (is_byte_type) { |
| 5104 | // Ensure the value is in a byte register. |
| 5105 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5106 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5107 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5108 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5109 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5110 | } |
| 5111 | if (needs_write_barrier) { |
| 5112 | // Temporary registers for the write barrier. |
| 5113 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5114 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5115 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5116 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5117 | } |
| 5118 | |
| 5119 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5120 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5121 | Location array_loc = locations->InAt(0); |
| 5122 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5123 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5124 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5125 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5126 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5127 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5128 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5129 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5130 | bool needs_write_barrier = |
| 5131 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | |
| 5133 | switch (value_type) { |
| 5134 | case Primitive::kPrimBoolean: |
| 5135 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5136 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5137 | Address address = index.IsConstant() |
| 5138 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5139 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5140 | if (value.IsRegister()) { |
| 5141 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5142 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5143 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5145 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5146 | break; |
| 5147 | } |
| 5148 | |
| 5149 | case Primitive::kPrimShort: |
| 5150 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5151 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5152 | Address address = index.IsConstant() |
| 5153 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5154 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5155 | if (value.IsRegister()) { |
| 5156 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5158 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5160 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5161 | break; |
| 5162 | } |
| 5163 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5164 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5165 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5166 | Address address = index.IsConstant() |
| 5167 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5168 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5169 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5170 | if (!value.IsRegister()) { |
| 5171 | // Just setting null. |
| 5172 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5173 | DCHECK(value.IsConstant()) << value; |
| 5174 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5175 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5176 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5177 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5178 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5179 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5180 | |
| 5181 | DCHECK(needs_write_barrier); |
| 5182 | Register register_value = value.AsRegister<Register>(); |
| 5183 | NearLabel done, not_null, do_put; |
| 5184 | SlowPathCode* slow_path = nullptr; |
| 5185 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5186 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5187 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5188 | codegen_->AddSlowPath(slow_path); |
| 5189 | if (instruction->GetValueCanBeNull()) { |
| 5190 | __ testl(register_value, register_value); |
| 5191 | __ j(kNotEqual, ¬_null); |
| 5192 | __ movl(address, Immediate(0)); |
| 5193 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5194 | __ jmp(&done); |
| 5195 | __ Bind(¬_null); |
| 5196 | } |
| 5197 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5198 | if (kEmitCompilerReadBarrier) { |
| 5199 | // When read barriers are enabled, the type checking |
| 5200 | // instrumentation requires two read barriers: |
| 5201 | // |
| 5202 | // __ movl(temp2, temp); |
| 5203 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5204 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5205 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5206 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5207 | // |
| 5208 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5209 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5210 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5211 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5212 | // |
| 5213 | // __ cmpl(temp, temp2); |
| 5214 | // |
| 5215 | // However, the second read barrier may trash `temp`, as it |
| 5216 | // is a temporary register, and as such would not be saved |
| 5217 | // along with live registers before calling the runtime (nor |
| 5218 | // restored afterwards). So in this case, we bail out and |
| 5219 | // delegate the work to the array set slow path. |
| 5220 | // |
| 5221 | // TODO: Extend the register allocator to support a new |
| 5222 | // "(locally) live temp" location so as to avoid always |
| 5223 | // going into the slow path when read barriers are enabled. |
| 5224 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5225 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5226 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5227 | __ movl(temp, Address(array, class_offset)); |
| 5228 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5229 | __ MaybeUnpoisonHeapReference(temp); |
| 5230 | |
| 5231 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5232 | __ movl(temp, Address(temp, component_offset)); |
| 5233 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5234 | // nor the object reference in `register_value->klass`, as |
| 5235 | // we are comparing two poisoned references. |
| 5236 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5237 | |
| 5238 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5239 | __ j(kEqual, &do_put); |
| 5240 | // If heap poisoning is enabled, the `temp` reference has |
| 5241 | // not been unpoisoned yet; unpoison it now. |
| 5242 | __ MaybeUnpoisonHeapReference(temp); |
| 5243 | |
| 5244 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5245 | __ movl(temp, Address(temp, super_offset)); |
| 5246 | // If heap poisoning is enabled, no need to unpoison |
| 5247 | // `temp`, as we are comparing against null below. |
| 5248 | __ testl(temp, temp); |
| 5249 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5250 | __ Bind(&do_put); |
| 5251 | } else { |
| 5252 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5253 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5254 | } |
| 5255 | } |
| 5256 | |
| 5257 | if (kPoisonHeapReferences) { |
| 5258 | __ movl(temp, register_value); |
| 5259 | __ PoisonHeapReference(temp); |
| 5260 | __ movl(address, temp); |
| 5261 | } else { |
| 5262 | __ movl(address, register_value); |
| 5263 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5264 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5265 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5266 | } |
| 5267 | |
| 5268 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5269 | codegen_->MarkGCCard( |
| 5270 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5271 | __ Bind(&done); |
| 5272 | |
| 5273 | if (slow_path != nullptr) { |
| 5274 | __ Bind(slow_path->GetExitLabel()); |
| 5275 | } |
| 5276 | |
| 5277 | break; |
| 5278 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5279 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5280 | case Primitive::kPrimInt: { |
| 5281 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5282 | Address address = index.IsConstant() |
| 5283 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5284 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5285 | if (value.IsRegister()) { |
| 5286 | __ movl(address, value.AsRegister<Register>()); |
| 5287 | } else { |
| 5288 | DCHECK(value.IsConstant()) << value; |
| 5289 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5290 | __ movl(address, Immediate(v)); |
| 5291 | } |
| 5292 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5293 | break; |
| 5294 | } |
| 5295 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5296 | case Primitive::kPrimLong: { |
| 5297 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5298 | if (index.IsConstant()) { |
| 5299 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5300 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5301 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5302 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5303 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5304 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5305 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5306 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5307 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5308 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5309 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5310 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5311 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5312 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5313 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5314 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5315 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5316 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5317 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5318 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5319 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5320 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5321 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5322 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5323 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5324 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5325 | Immediate(High32Bits(val))); |
| 5326 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5327 | } |
| 5328 | break; |
| 5329 | } |
| 5330 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5331 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5332 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5333 | Address address = index.IsConstant() |
| 5334 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5335 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5336 | if (value.IsFpuRegister()) { |
| 5337 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5338 | } else { |
| 5339 | DCHECK(value.IsConstant()); |
| 5340 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5341 | __ movl(address, Immediate(v)); |
| 5342 | } |
| 5343 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5344 | break; |
| 5345 | } |
| 5346 | |
| 5347 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5348 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5349 | Address address = index.IsConstant() |
| 5350 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5351 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5352 | if (value.IsFpuRegister()) { |
| 5353 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5354 | } else { |
| 5355 | DCHECK(value.IsConstant()); |
| 5356 | Address address_hi = index.IsConstant() ? |
| 5357 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5358 | offset + kX86WordSize) : |
| 5359 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5360 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5361 | __ movl(address, Immediate(Low32Bits(v))); |
| 5362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5363 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5364 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5365 | break; |
| 5366 | } |
| 5367 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5368 | case Primitive::kPrimVoid: |
| 5369 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5370 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5371 | } |
| 5372 | } |
| 5373 | |
| 5374 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5375 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5377 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5381 | LocationSummary* locations = instruction->GetLocations(); |
| 5382 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5383 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5384 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5385 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5386 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5390 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5391 | ? LocationSummary::kCallOnSlowPath |
| 5392 | : LocationSummary::kNoCall; |
| 5393 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5394 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5395 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5396 | if (instruction->HasUses()) { |
| 5397 | locations->SetOut(Location::SameAsFirstInput()); |
| 5398 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5402 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5403 | Location index_loc = locations->InAt(0); |
| 5404 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5405 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5406 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5407 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5408 | if (length_loc.IsConstant()) { |
| 5409 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5410 | if (index_loc.IsConstant()) { |
| 5411 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5412 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5413 | if (index < 0 || index >= length) { |
| 5414 | codegen_->AddSlowPath(slow_path); |
| 5415 | __ jmp(slow_path->GetEntryLabel()); |
| 5416 | } else { |
| 5417 | // Some optimization after BCE may have generated this, and we should not |
| 5418 | // generate a bounds check if it is a valid range. |
| 5419 | } |
| 5420 | return; |
| 5421 | } |
| 5422 | |
| 5423 | // We have to reverse the jump condition because the length is the constant. |
| 5424 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5425 | __ cmpl(index_reg, Immediate(length)); |
| 5426 | codegen_->AddSlowPath(slow_path); |
| 5427 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5428 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5429 | Register length = length_loc.AsRegister<Register>(); |
| 5430 | if (index_loc.IsConstant()) { |
| 5431 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5432 | __ cmpl(length, Immediate(value)); |
| 5433 | } else { |
| 5434 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5435 | } |
| 5436 | codegen_->AddSlowPath(slow_path); |
| 5437 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5438 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5439 | } |
| 5440 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5441 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5442 | temp->SetLocations(nullptr); |
| 5443 | } |
| 5444 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5445 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5446 | // Nothing to do, this is driven by the code generator. |
| 5447 | } |
| 5448 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5449 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5450 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5454 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5455 | } |
| 5456 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5457 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5458 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5459 | } |
| 5460 | |
| 5461 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5462 | HBasicBlock* block = instruction->GetBlock(); |
| 5463 | if (block->GetLoopInformation() != nullptr) { |
| 5464 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5465 | // The back edge will generate the suspend check. |
| 5466 | return; |
| 5467 | } |
| 5468 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5469 | // The goto will generate the suspend check. |
| 5470 | return; |
| 5471 | } |
| 5472 | GenerateSuspendCheck(instruction, nullptr); |
| 5473 | } |
| 5474 | |
| 5475 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5476 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5477 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5478 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5479 | if (slow_path == nullptr) { |
| 5480 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5481 | instruction->SetSlowPath(slow_path); |
| 5482 | codegen_->AddSlowPath(slow_path); |
| 5483 | if (successor != nullptr) { |
| 5484 | DCHECK(successor->IsLoopHeader()); |
| 5485 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5486 | } |
| 5487 | } else { |
| 5488 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5489 | } |
| 5490 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5491 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5492 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5493 | if (successor == nullptr) { |
| 5494 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5495 | __ Bind(slow_path->GetReturnLabel()); |
| 5496 | } else { |
| 5497 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5498 | __ jmp(slow_path->GetEntryLabel()); |
| 5499 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5500 | } |
| 5501 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5502 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5503 | return codegen_->GetAssembler(); |
| 5504 | } |
| 5505 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5506 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5507 | ScratchRegisterScope ensure_scratch( |
| 5508 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5509 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5510 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5511 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5512 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5516 | ScratchRegisterScope ensure_scratch( |
| 5517 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5518 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5519 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5520 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5521 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5522 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5523 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5527 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5528 | Location source = move->GetSource(); |
| 5529 | Location destination = move->GetDestination(); |
| 5530 | |
| 5531 | if (source.IsRegister()) { |
| 5532 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5533 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5534 | } else if (destination.IsFpuRegister()) { |
| 5535 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5536 | } else { |
| 5537 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5538 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5539 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5540 | } else if (source.IsRegisterPair()) { |
| 5541 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5542 | // Create stack space for 2 elements. |
| 5543 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5544 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5545 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5546 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5547 | // And remove the temporary stack space we allocated. |
| 5548 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5549 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5550 | if (destination.IsRegister()) { |
| 5551 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5552 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5553 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5554 | } else if (destination.IsRegisterPair()) { |
| 5555 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5556 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5557 | __ psrlq(src_reg, Immediate(32)); |
| 5558 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5559 | } else if (destination.IsStackSlot()) { |
| 5560 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5561 | } else { |
| 5562 | DCHECK(destination.IsDoubleStackSlot()); |
| 5563 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5564 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5565 | } else if (source.IsStackSlot()) { |
| 5566 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5567 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5568 | } else if (destination.IsFpuRegister()) { |
| 5569 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5570 | } else { |
| 5571 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5572 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5573 | } |
| 5574 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5575 | if (destination.IsRegisterPair()) { |
| 5576 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5577 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5578 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5579 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5580 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5581 | } else { |
| 5582 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5583 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5584 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5585 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5586 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5587 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5588 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5589 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5590 | if (value == 0) { |
| 5591 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5592 | } else { |
| 5593 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5594 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5595 | } else { |
| 5596 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5597 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5598 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5599 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5600 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5601 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5602 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5603 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5604 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5605 | if (value == 0) { |
| 5606 | // Easy handling of 0.0. |
| 5607 | __ xorps(dest, dest); |
| 5608 | } else { |
| 5609 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5610 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5611 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5612 | __ movl(temp, Immediate(value)); |
| 5613 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5614 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5615 | } else { |
| 5616 | DCHECK(destination.IsStackSlot()) << destination; |
| 5617 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5618 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5619 | } else if (constant->IsLongConstant()) { |
| 5620 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5621 | int32_t low_value = Low32Bits(value); |
| 5622 | int32_t high_value = High32Bits(value); |
| 5623 | Immediate low(low_value); |
| 5624 | Immediate high(high_value); |
| 5625 | if (destination.IsDoubleStackSlot()) { |
| 5626 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5627 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5628 | } else { |
| 5629 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5630 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5631 | } |
| 5632 | } else { |
| 5633 | DCHECK(constant->IsDoubleConstant()); |
| 5634 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5635 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5636 | int32_t low_value = Low32Bits(value); |
| 5637 | int32_t high_value = High32Bits(value); |
| 5638 | Immediate low(low_value); |
| 5639 | Immediate high(high_value); |
| 5640 | if (destination.IsFpuRegister()) { |
| 5641 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5642 | if (value == 0) { |
| 5643 | // Easy handling of 0.0. |
| 5644 | __ xorpd(dest, dest); |
| 5645 | } else { |
| 5646 | __ pushl(high); |
| 5647 | __ pushl(low); |
| 5648 | __ movsd(dest, Address(ESP, 0)); |
| 5649 | __ addl(ESP, Immediate(8)); |
| 5650 | } |
| 5651 | } else { |
| 5652 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5653 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5654 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5655 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5656 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5657 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5658 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5659 | } |
| 5660 | } |
| 5661 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5662 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5663 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5664 | ScratchRegisterScope ensure_scratch( |
| 5665 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5666 | |
| 5667 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5668 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5669 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5670 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5671 | } |
| 5672 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5673 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5674 | ScratchRegisterScope ensure_scratch( |
| 5675 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5676 | |
| 5677 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5678 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5679 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5680 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5681 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5682 | } |
| 5683 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5684 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5685 | ScratchRegisterScope ensure_scratch1( |
| 5686 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5687 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5688 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5689 | ScratchRegisterScope ensure_scratch2( |
| 5690 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5691 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5692 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5693 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5694 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5695 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5696 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5697 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5701 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5702 | Location source = move->GetSource(); |
| 5703 | Location destination = move->GetDestination(); |
| 5704 | |
| 5705 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5706 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5707 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5708 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5709 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5710 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5711 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5712 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5713 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5714 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5715 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5716 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5717 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5718 | // Use XOR Swap algorithm to avoid a temporary. |
| 5719 | DCHECK_NE(source.reg(), destination.reg()); |
| 5720 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5721 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5722 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5723 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5724 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5725 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5726 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5727 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5728 | // Take advantage of the 16 bytes in the XMM register. |
| 5729 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5730 | Address stack(ESP, destination.GetStackIndex()); |
| 5731 | // Load the double into the high doubleword. |
| 5732 | __ movhpd(reg, stack); |
| 5733 | |
| 5734 | // Store the low double into the destination. |
| 5735 | __ movsd(stack, reg); |
| 5736 | |
| 5737 | // Move the high double to the low double. |
| 5738 | __ psrldq(reg, Immediate(8)); |
| 5739 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5740 | // Take advantage of the 16 bytes in the XMM register. |
| 5741 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5742 | Address stack(ESP, source.GetStackIndex()); |
| 5743 | // Load the double into the high doubleword. |
| 5744 | __ movhpd(reg, stack); |
| 5745 | |
| 5746 | // Store the low double into the destination. |
| 5747 | __ movsd(stack, reg); |
| 5748 | |
| 5749 | // Move the high double to the low double. |
| 5750 | __ psrldq(reg, Immediate(8)); |
| 5751 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5752 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5753 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5754 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5755 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5760 | __ pushl(static_cast<Register>(reg)); |
| 5761 | } |
| 5762 | |
| 5763 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5764 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5765 | } |
| 5766 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5767 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5768 | InvokeRuntimeCallingConvention calling_convention; |
| 5769 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5770 | cls, |
| 5771 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5772 | Location::RegisterLocation(EAX), |
| 5773 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5777 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5778 | if (cls->NeedsAccessCheck()) { |
| 5779 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5780 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5781 | cls, |
| 5782 | cls->GetDexPc(), |
| 5783 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5784 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5785 | return; |
| 5786 | } |
| 5787 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5788 | Location out_loc = locations->Out(); |
| 5789 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5790 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5791 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5792 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5793 | DCHECK(!cls->CanCallRuntime()); |
| 5794 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5795 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5796 | GenerateGcRootFieldLoad( |
| 5797 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5798 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5799 | // /* GcRoot<mirror::Class>[] */ out = |
| 5800 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5801 | __ movl(out, Address(current_method, |
| 5802 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5803 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5804 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5805 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5806 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5807 | DCHECK(cls->CanCallRuntime()); |
| 5808 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5809 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5810 | codegen_->AddSlowPath(slow_path); |
| 5811 | |
| 5812 | if (!cls->IsInDexCache()) { |
| 5813 | __ testl(out, out); |
| 5814 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5815 | } |
| 5816 | |
| 5817 | if (cls->MustGenerateClinitCheck()) { |
| 5818 | GenerateClassInitializationCheck(slow_path, out); |
| 5819 | } else { |
| 5820 | __ Bind(slow_path->GetExitLabel()); |
| 5821 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5822 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5827 | LocationSummary* locations = |
| 5828 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5829 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5830 | if (check->HasUses()) { |
| 5831 | locations->SetOut(Location::SameAsFirstInput()); |
| 5832 | } |
| 5833 | } |
| 5834 | |
| 5835 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5836 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5837 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5838 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5839 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5840 | GenerateClassInitializationCheck(slow_path, |
| 5841 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5842 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5843 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5844 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5845 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5846 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5847 | Immediate(mirror::Class::kStatusInitialized)); |
| 5848 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5849 | __ Bind(slow_path->GetExitLabel()); |
| 5850 | // No need for memory fence, thanks to the X86 memory model. |
| 5851 | } |
| 5852 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5853 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5854 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5855 | ? LocationSummary::kCallOnSlowPath |
| 5856 | : LocationSummary::kNoCall; |
| 5857 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5858 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5859 | locations->SetOut(Location::RequiresRegister()); |
| 5860 | } |
| 5861 | |
| 5862 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5863 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5864 | Location out_loc = locations->Out(); |
| 5865 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5866 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5867 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5868 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5869 | GenerateGcRootFieldLoad( |
| 5870 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5871 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5872 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5873 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5874 | GenerateGcRootFieldLoad( |
| 5875 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5876 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5877 | if (!load->IsInDexCache()) { |
| 5878 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5879 | codegen_->AddSlowPath(slow_path); |
| 5880 | __ testl(out, out); |
| 5881 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5882 | __ Bind(slow_path->GetExitLabel()); |
| 5883 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5886 | static Address GetExceptionTlsAddress() { |
| 5887 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5888 | } |
| 5889 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5890 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5891 | LocationSummary* locations = |
| 5892 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5893 | locations->SetOut(Location::RequiresRegister()); |
| 5894 | } |
| 5895 | |
| 5896 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5897 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5898 | } |
| 5899 | |
| 5900 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5901 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5902 | } |
| 5903 | |
| 5904 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5905 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5909 | LocationSummary* locations = |
| 5910 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5911 | InvokeRuntimeCallingConvention calling_convention; |
| 5912 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5913 | } |
| 5914 | |
| 5915 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5916 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5917 | instruction, |
| 5918 | instruction->GetDexPc(), |
| 5919 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5920 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5923 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5924 | return kEmitCompilerReadBarrier && |
| 5925 | (kUseBakerReadBarrier || |
| 5926 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5927 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5928 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5929 | } |
| 5930 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5931 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5932 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5933 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5934 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5935 | case TypeCheckKind::kExactCheck: |
| 5936 | case TypeCheckKind::kAbstractClassCheck: |
| 5937 | case TypeCheckKind::kClassHierarchyCheck: |
| 5938 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5939 | call_kind = |
| 5940 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5941 | break; |
| 5942 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5943 | case TypeCheckKind::kUnresolvedCheck: |
| 5944 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5945 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5946 | break; |
| 5947 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5948 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5949 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5951 | locations->SetInAt(1, Location::Any()); |
| 5952 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5953 | locations->SetOut(Location::RequiresRegister()); |
| 5954 | // When read barriers are enabled, we need a temporary register for |
| 5955 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5956 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5957 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5958 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5959 | } |
| 5960 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5961 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5962 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5963 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5964 | Location obj_loc = locations->InAt(0); |
| 5965 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5966 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5967 | Location out_loc = locations->Out(); |
| 5968 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5969 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5970 | locations->GetTemp(0) : |
| 5971 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5972 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5973 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5974 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5975 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5976 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5977 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5978 | |
| 5979 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5980 | // Avoid null check if we know obj is not null. |
| 5981 | if (instruction->MustDoNullCheck()) { |
| 5982 | __ testl(obj, obj); |
| 5983 | __ j(kEqual, &zero); |
| 5984 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5985 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5986 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5987 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5988 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5989 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5990 | case TypeCheckKind::kExactCheck: { |
| 5991 | if (cls.IsRegister()) { |
| 5992 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5993 | } else { |
| 5994 | DCHECK(cls.IsStackSlot()) << cls; |
| 5995 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5996 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5997 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5998 | // Classes must be equal for the instanceof to succeed. |
| 5999 | __ j(kNotEqual, &zero); |
| 6000 | __ movl(out, Immediate(1)); |
| 6001 | __ jmp(&done); |
| 6002 | break; |
| 6003 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6004 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6005 | case TypeCheckKind::kAbstractClassCheck: { |
| 6006 | // If the class is abstract, we eagerly fetch the super class of the |
| 6007 | // object to avoid doing a comparison we know will fail. |
| 6008 | NearLabel loop; |
| 6009 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6010 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6011 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6012 | __ testl(out, out); |
| 6013 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6014 | __ j(kEqual, &done); |
| 6015 | if (cls.IsRegister()) { |
| 6016 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6017 | } else { |
| 6018 | DCHECK(cls.IsStackSlot()) << cls; |
| 6019 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6020 | } |
| 6021 | __ j(kNotEqual, &loop); |
| 6022 | __ movl(out, Immediate(1)); |
| 6023 | if (zero.IsLinked()) { |
| 6024 | __ jmp(&done); |
| 6025 | } |
| 6026 | break; |
| 6027 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6028 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6029 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6030 | // Walk over the class hierarchy to find a match. |
| 6031 | NearLabel loop, success; |
| 6032 | __ Bind(&loop); |
| 6033 | if (cls.IsRegister()) { |
| 6034 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6035 | } else { |
| 6036 | DCHECK(cls.IsStackSlot()) << cls; |
| 6037 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6038 | } |
| 6039 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6040 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6041 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6042 | __ testl(out, out); |
| 6043 | __ j(kNotEqual, &loop); |
| 6044 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6045 | __ jmp(&done); |
| 6046 | __ Bind(&success); |
| 6047 | __ movl(out, Immediate(1)); |
| 6048 | if (zero.IsLinked()) { |
| 6049 | __ jmp(&done); |
| 6050 | } |
| 6051 | break; |
| 6052 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6053 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6054 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6055 | // Do an exact check. |
| 6056 | NearLabel exact_check; |
| 6057 | if (cls.IsRegister()) { |
| 6058 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6059 | } else { |
| 6060 | DCHECK(cls.IsStackSlot()) << cls; |
| 6061 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6062 | } |
| 6063 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6064 | // 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] | 6065 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6066 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6067 | __ testl(out, out); |
| 6068 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6069 | __ j(kEqual, &done); |
| 6070 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6071 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6072 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6073 | __ movl(out, Immediate(1)); |
| 6074 | __ jmp(&done); |
| 6075 | break; |
| 6076 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6077 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6078 | case TypeCheckKind::kArrayCheck: { |
| 6079 | if (cls.IsRegister()) { |
| 6080 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6081 | } else { |
| 6082 | DCHECK(cls.IsStackSlot()) << cls; |
| 6083 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6084 | } |
| 6085 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6086 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6087 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6088 | codegen_->AddSlowPath(slow_path); |
| 6089 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6090 | __ movl(out, Immediate(1)); |
| 6091 | if (zero.IsLinked()) { |
| 6092 | __ jmp(&done); |
| 6093 | } |
| 6094 | break; |
| 6095 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6096 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6097 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6098 | case TypeCheckKind::kInterfaceCheck: { |
| 6099 | // 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] | 6100 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6101 | // cases. |
| 6102 | // |
| 6103 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6104 | // entry point without resorting to a type checking slow path |
| 6105 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6106 | // require to assign fixed registers for the inputs of this |
| 6107 | // HInstanceOf instruction (following the runtime calling |
| 6108 | // convention), which might be cluttered by the potential first |
| 6109 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6110 | // |
| 6111 | // TODO: Introduce a new runtime entry point taking the object |
| 6112 | // to test (instead of its class) as argument, and let it deal |
| 6113 | // with the read barrier issues. This will let us refactor this |
| 6114 | // case of the `switch` code as it was previously (with a direct |
| 6115 | // call to the runtime not using a type checking slow path). |
| 6116 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6117 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6118 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6119 | /* is_fatal */ false); |
| 6120 | codegen_->AddSlowPath(slow_path); |
| 6121 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6122 | if (zero.IsLinked()) { |
| 6123 | __ jmp(&done); |
| 6124 | } |
| 6125 | break; |
| 6126 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6127 | } |
| 6128 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6129 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6130 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6131 | __ xorl(out, out); |
| 6132 | } |
| 6133 | |
| 6134 | if (done.IsLinked()) { |
| 6135 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6136 | } |
| 6137 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6138 | if (slow_path != nullptr) { |
| 6139 | __ Bind(slow_path->GetExitLabel()); |
| 6140 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6143 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6144 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6145 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6146 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6147 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6148 | case TypeCheckKind::kExactCheck: |
| 6149 | case TypeCheckKind::kAbstractClassCheck: |
| 6150 | case TypeCheckKind::kClassHierarchyCheck: |
| 6151 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6152 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6153 | LocationSummary::kCallOnSlowPath : |
| 6154 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6155 | break; |
| 6156 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6157 | case TypeCheckKind::kUnresolvedCheck: |
| 6158 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6159 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6160 | break; |
| 6161 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6162 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6163 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6164 | locations->SetInAt(1, Location::Any()); |
| 6165 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6166 | locations->AddTemp(Location::RequiresRegister()); |
| 6167 | // When read barriers are enabled, we need an additional temporary |
| 6168 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6169 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6170 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6175 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6176 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6177 | Location obj_loc = locations->InAt(0); |
| 6178 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6179 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6180 | Location temp_loc = locations->GetTemp(0); |
| 6181 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6182 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6183 | locations->GetTemp(1) : |
| 6184 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6185 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6186 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6187 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6188 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6189 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6190 | bool is_type_check_slow_path_fatal = |
| 6191 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6192 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6193 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6194 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6195 | !instruction->CanThrowIntoCatchBlock(); |
| 6196 | SlowPathCode* type_check_slow_path = |
| 6197 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6198 | is_type_check_slow_path_fatal); |
| 6199 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6200 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6201 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6202 | // Avoid null check if we know obj is not null. |
| 6203 | if (instruction->MustDoNullCheck()) { |
| 6204 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6205 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6206 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6207 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6208 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6209 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6210 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6212 | case TypeCheckKind::kExactCheck: |
| 6213 | case TypeCheckKind::kArrayCheck: { |
| 6214 | if (cls.IsRegister()) { |
| 6215 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6216 | } else { |
| 6217 | DCHECK(cls.IsStackSlot()) << cls; |
| 6218 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6219 | } |
| 6220 | // Jump to slow path for throwing the exception or doing a |
| 6221 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6222 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6223 | break; |
| 6224 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6225 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6226 | case TypeCheckKind::kAbstractClassCheck: { |
| 6227 | // If the class is abstract, we eagerly fetch the super class of the |
| 6228 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6229 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6230 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6231 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6232 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6233 | |
| 6234 | // If the class reference currently in `temp` is not null, jump |
| 6235 | // to the `compare_classes` label to compare it with the checked |
| 6236 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6237 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6238 | __ j(kNotEqual, &compare_classes); |
| 6239 | // Otherwise, jump to the slow path to throw the exception. |
| 6240 | // |
| 6241 | // But before, move back the object's class into `temp` before |
| 6242 | // going into the slow path, as it has been overwritten in the |
| 6243 | // meantime. |
| 6244 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6245 | GenerateReferenceLoadTwoRegisters( |
| 6246 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6247 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6248 | |
| 6249 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6250 | if (cls.IsRegister()) { |
| 6251 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6252 | } else { |
| 6253 | DCHECK(cls.IsStackSlot()) << cls; |
| 6254 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6255 | } |
| 6256 | __ j(kNotEqual, &loop); |
| 6257 | break; |
| 6258 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6259 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6260 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6261 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6262 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6263 | __ Bind(&loop); |
| 6264 | if (cls.IsRegister()) { |
| 6265 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6266 | } else { |
| 6267 | DCHECK(cls.IsStackSlot()) << cls; |
| 6268 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6269 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6270 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6272 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6273 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | |
| 6275 | // If the class reference currently in `temp` is not null, jump |
| 6276 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6277 | __ testl(temp, temp); |
| 6278 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6279 | // Otherwise, jump to the slow path to throw the exception. |
| 6280 | // |
| 6281 | // But before, move back the object's class into `temp` before |
| 6282 | // going into the slow path, as it has been overwritten in the |
| 6283 | // meantime. |
| 6284 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6285 | GenerateReferenceLoadTwoRegisters( |
| 6286 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6287 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | break; |
| 6289 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6290 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6291 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6292 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6293 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 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 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6301 | |
| 6302 | // 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] | 6303 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6304 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6305 | |
| 6306 | // If the component type is not null (i.e. the object is indeed |
| 6307 | // an array), jump to label `check_non_primitive_component_type` |
| 6308 | // to further check that this component type is not a primitive |
| 6309 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6310 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6311 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6312 | // Otherwise, jump to the slow path to throw the exception. |
| 6313 | // |
| 6314 | // But before, move back the object's class into `temp` before |
| 6315 | // going into the slow path, as it has been overwritten in the |
| 6316 | // meantime. |
| 6317 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6318 | GenerateReferenceLoadTwoRegisters( |
| 6319 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6320 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6321 | |
| 6322 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6324 | __ j(kEqual, &done); |
| 6325 | // Same comment as above regarding `temp` and the slow path. |
| 6326 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6327 | GenerateReferenceLoadTwoRegisters( |
| 6328 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6329 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6330 | break; |
| 6331 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6332 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6333 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6334 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6335 | // We always go into the type check slow path for the unresolved |
| 6336 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | // |
| 6338 | // We cannot directly call the CheckCast runtime entry point |
| 6339 | // without resorting to a type checking slow path here (i.e. by |
| 6340 | // calling InvokeRuntime directly), as it would require to |
| 6341 | // assign fixed registers for the inputs of this HInstanceOf |
| 6342 | // instruction (following the runtime calling convention), which |
| 6343 | // might be cluttered by the potential first read barrier |
| 6344 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6345 | // |
| 6346 | // TODO: Introduce a new runtime entry point taking the object |
| 6347 | // to test (instead of its class) as argument, and let it deal |
| 6348 | // with the read barrier issues. This will let us refactor this |
| 6349 | // case of the `switch` code as it was previously (with a direct |
| 6350 | // call to the runtime not using a type checking slow path). |
| 6351 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6352 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6353 | break; |
| 6354 | } |
| 6355 | __ Bind(&done); |
| 6356 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6357 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6358 | } |
| 6359 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6360 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6361 | LocationSummary* locations = |
| 6362 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6363 | InvokeRuntimeCallingConvention calling_convention; |
| 6364 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6365 | } |
| 6366 | |
| 6367 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6368 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6369 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6370 | instruction, |
| 6371 | instruction->GetDexPc(), |
| 6372 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6373 | if (instruction->IsEnter()) { |
| 6374 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6375 | } else { |
| 6376 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6377 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6378 | } |
| 6379 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6380 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6381 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6382 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6383 | |
| 6384 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6385 | LocationSummary* locations = |
| 6386 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6387 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6388 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6389 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6390 | locations->SetInAt(1, Location::Any()); |
| 6391 | locations->SetOut(Location::SameAsFirstInput()); |
| 6392 | } |
| 6393 | |
| 6394 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6395 | HandleBitwiseOperation(instruction); |
| 6396 | } |
| 6397 | |
| 6398 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6399 | HandleBitwiseOperation(instruction); |
| 6400 | } |
| 6401 | |
| 6402 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6403 | HandleBitwiseOperation(instruction); |
| 6404 | } |
| 6405 | |
| 6406 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6407 | LocationSummary* locations = instruction->GetLocations(); |
| 6408 | Location first = locations->InAt(0); |
| 6409 | Location second = locations->InAt(1); |
| 6410 | DCHECK(first.Equals(locations->Out())); |
| 6411 | |
| 6412 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6413 | if (second.IsRegister()) { |
| 6414 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6415 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6416 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6417 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6418 | } else { |
| 6419 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6420 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6421 | } |
| 6422 | } else if (second.IsConstant()) { |
| 6423 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6424 | __ andl(first.AsRegister<Register>(), |
| 6425 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6426 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6427 | __ orl(first.AsRegister<Register>(), |
| 6428 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6429 | } else { |
| 6430 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6431 | __ xorl(first.AsRegister<Register>(), |
| 6432 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6433 | } |
| 6434 | } else { |
| 6435 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6436 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6437 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6438 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6439 | } else { |
| 6440 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6441 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6442 | } |
| 6443 | } |
| 6444 | } else { |
| 6445 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6446 | if (second.IsRegisterPair()) { |
| 6447 | if (instruction->IsAnd()) { |
| 6448 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6449 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6450 | } else if (instruction->IsOr()) { |
| 6451 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6452 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6453 | } else { |
| 6454 | DCHECK(instruction->IsXor()); |
| 6455 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6456 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6457 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6458 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6459 | if (instruction->IsAnd()) { |
| 6460 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6461 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6462 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6463 | } else if (instruction->IsOr()) { |
| 6464 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6465 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6466 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6467 | } else { |
| 6468 | DCHECK(instruction->IsXor()); |
| 6469 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6470 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6471 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6472 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6473 | } else { |
| 6474 | DCHECK(second.IsConstant()) << second; |
| 6475 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6476 | int32_t low_value = Low32Bits(value); |
| 6477 | int32_t high_value = High32Bits(value); |
| 6478 | Immediate low(low_value); |
| 6479 | Immediate high(high_value); |
| 6480 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6481 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6482 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6483 | if (low_value == 0) { |
| 6484 | __ xorl(first_low, first_low); |
| 6485 | } else if (low_value != -1) { |
| 6486 | __ andl(first_low, low); |
| 6487 | } |
| 6488 | if (high_value == 0) { |
| 6489 | __ xorl(first_high, first_high); |
| 6490 | } else if (high_value != -1) { |
| 6491 | __ andl(first_high, high); |
| 6492 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6493 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6494 | if (low_value != 0) { |
| 6495 | __ orl(first_low, low); |
| 6496 | } |
| 6497 | if (high_value != 0) { |
| 6498 | __ orl(first_high, high); |
| 6499 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6500 | } else { |
| 6501 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6502 | if (low_value != 0) { |
| 6503 | __ xorl(first_low, low); |
| 6504 | } |
| 6505 | if (high_value != 0) { |
| 6506 | __ xorl(first_high, high); |
| 6507 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6508 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6509 | } |
| 6510 | } |
| 6511 | } |
| 6512 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6513 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6514 | Location out, |
| 6515 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6516 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6517 | Register out_reg = out.AsRegister<Register>(); |
| 6518 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6519 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6520 | if (kUseBakerReadBarrier) { |
| 6521 | // Load with fast path based Baker's read barrier. |
| 6522 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6523 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6524 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6525 | } else { |
| 6526 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6527 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6528 | // in the following move operation, as we will need it for the |
| 6529 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6530 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6531 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6532 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6533 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6534 | } |
| 6535 | } else { |
| 6536 | // Plain load with no read barrier. |
| 6537 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6538 | __ movl(out_reg, Address(out_reg, offset)); |
| 6539 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6540 | } |
| 6541 | } |
| 6542 | |
| 6543 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6544 | Location out, |
| 6545 | Location obj, |
| 6546 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6547 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6548 | Register out_reg = out.AsRegister<Register>(); |
| 6549 | Register obj_reg = obj.AsRegister<Register>(); |
| 6550 | if (kEmitCompilerReadBarrier) { |
| 6551 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6552 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6553 | // Load with fast path based Baker's read barrier. |
| 6554 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6555 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6556 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6557 | } else { |
| 6558 | // Load with slow path based read barrier. |
| 6559 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6560 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6561 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6562 | } |
| 6563 | } else { |
| 6564 | // Plain load with no read barrier. |
| 6565 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6566 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6567 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6568 | } |
| 6569 | } |
| 6570 | |
| 6571 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6572 | Location root, |
| 6573 | Register obj, |
| 6574 | uint32_t offset) { |
| 6575 | Register root_reg = root.AsRegister<Register>(); |
| 6576 | if (kEmitCompilerReadBarrier) { |
| 6577 | if (kUseBakerReadBarrier) { |
| 6578 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6579 | // Baker's read barrier are used: |
| 6580 | // |
| 6581 | // root = obj.field; |
| 6582 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6583 | // root = ReadBarrier::Mark(root) |
| 6584 | // } |
| 6585 | |
| 6586 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6587 | __ movl(root_reg, Address(obj, offset)); |
| 6588 | static_assert( |
| 6589 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6590 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6591 | "have different sizes."); |
| 6592 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6593 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6594 | "have different sizes."); |
| 6595 | |
| 6596 | // Slow path used to mark the GC root `root`. |
| 6597 | SlowPathCode* slow_path = |
| 6598 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6599 | codegen_->AddSlowPath(slow_path); |
| 6600 | |
| 6601 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6602 | Immediate(0)); |
| 6603 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6604 | __ Bind(slow_path->GetExitLabel()); |
| 6605 | } else { |
| 6606 | // GC root loaded through a slow path for read barriers other |
| 6607 | // than Baker's. |
| 6608 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6609 | __ leal(root_reg, Address(obj, offset)); |
| 6610 | // /* mirror::Object* */ root = root->Read() |
| 6611 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6612 | } |
| 6613 | } else { |
| 6614 | // Plain GC root load with no read barrier. |
| 6615 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6616 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6617 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6618 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6623 | Location ref, |
| 6624 | Register obj, |
| 6625 | uint32_t offset, |
| 6626 | Location temp, |
| 6627 | bool needs_null_check) { |
| 6628 | DCHECK(kEmitCompilerReadBarrier); |
| 6629 | DCHECK(kUseBakerReadBarrier); |
| 6630 | |
| 6631 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6632 | Address src(obj, offset); |
| 6633 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6634 | } |
| 6635 | |
| 6636 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6637 | Location ref, |
| 6638 | Register obj, |
| 6639 | uint32_t data_offset, |
| 6640 | Location index, |
| 6641 | Location temp, |
| 6642 | bool needs_null_check) { |
| 6643 | DCHECK(kEmitCompilerReadBarrier); |
| 6644 | DCHECK(kUseBakerReadBarrier); |
| 6645 | |
| 6646 | // /* HeapReference<Object> */ ref = |
| 6647 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6648 | Address src = index.IsConstant() ? |
| 6649 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6650 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6651 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6652 | } |
| 6653 | |
| 6654 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6655 | Location ref, |
| 6656 | Register obj, |
| 6657 | const Address& src, |
| 6658 | Location temp, |
| 6659 | bool needs_null_check) { |
| 6660 | DCHECK(kEmitCompilerReadBarrier); |
| 6661 | DCHECK(kUseBakerReadBarrier); |
| 6662 | |
| 6663 | // In slow path based read barriers, the read barrier call is |
| 6664 | // inserted after the original load. However, in fast path based |
| 6665 | // Baker's read barriers, we need to perform the load of |
| 6666 | // mirror::Object::monitor_ *before* the original reference load. |
| 6667 | // This load-load ordering is required by the read barrier. |
| 6668 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6669 | // |
| 6670 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6671 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6672 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6673 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6674 | // if (is_gray) { |
| 6675 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6676 | // } |
| 6677 | // |
| 6678 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6679 | // slightly more complex as: |
| 6680 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6681 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6682 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6683 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6684 | // - it performs additional checks that we do not do here for |
| 6685 | // performance reasons. |
| 6686 | |
| 6687 | Register ref_reg = ref.AsRegister<Register>(); |
| 6688 | Register temp_reg = temp.AsRegister<Register>(); |
| 6689 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6690 | |
| 6691 | // /* int32_t */ monitor = obj->monitor_ |
| 6692 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6693 | if (needs_null_check) { |
| 6694 | MaybeRecordImplicitNullCheck(instruction); |
| 6695 | } |
| 6696 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6697 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6698 | "art::LockWord and int32_t have different sizes."); |
| 6699 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6700 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6701 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6702 | static_assert( |
| 6703 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6704 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6705 | |
| 6706 | // Load fence to prevent load-load reordering. |
| 6707 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6708 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6709 | |
| 6710 | // The actual reference load. |
| 6711 | // /* HeapReference<Object> */ ref = *src |
| 6712 | __ movl(ref_reg, src); |
| 6713 | |
| 6714 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6715 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6716 | |
| 6717 | // Slow path used to mark the object `ref` when it is gray. |
| 6718 | SlowPathCode* slow_path = |
| 6719 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6720 | AddSlowPath(slow_path); |
| 6721 | |
| 6722 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6723 | // ref = ReadBarrier::Mark(ref); |
| 6724 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6725 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6726 | __ Bind(slow_path->GetExitLabel()); |
| 6727 | } |
| 6728 | |
| 6729 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6730 | Location out, |
| 6731 | Location ref, |
| 6732 | Location obj, |
| 6733 | uint32_t offset, |
| 6734 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6735 | DCHECK(kEmitCompilerReadBarrier); |
| 6736 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6737 | // Insert a slow path based read barrier *after* the reference load. |
| 6738 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6739 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6740 | // reference will be carried out by the runtime within the slow |
| 6741 | // path. |
| 6742 | // |
| 6743 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6744 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6745 | // not used by the artReadBarrierSlow entry point. |
| 6746 | // |
| 6747 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6748 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6749 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6750 | AddSlowPath(slow_path); |
| 6751 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6752 | __ jmp(slow_path->GetEntryLabel()); |
| 6753 | __ Bind(slow_path->GetExitLabel()); |
| 6754 | } |
| 6755 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6756 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6757 | Location out, |
| 6758 | Location ref, |
| 6759 | Location obj, |
| 6760 | uint32_t offset, |
| 6761 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6762 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6763 | // Baker's read barriers shall be handled by the fast path |
| 6764 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6765 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6766 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6767 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6768 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6769 | } else if (kPoisonHeapReferences) { |
| 6770 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6771 | } |
| 6772 | } |
| 6773 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6774 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6775 | Location out, |
| 6776 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6777 | DCHECK(kEmitCompilerReadBarrier); |
| 6778 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6779 | // Insert a slow path based read barrier *after* the GC root load. |
| 6780 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6781 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6782 | // not need to do anything special for this here. |
| 6783 | SlowPathCode* slow_path = |
| 6784 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6785 | AddSlowPath(slow_path); |
| 6786 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6787 | __ jmp(slow_path->GetEntryLabel()); |
| 6788 | __ Bind(slow_path->GetExitLabel()); |
| 6789 | } |
| 6790 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6791 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6792 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6793 | LOG(FATAL) << "Unreachable"; |
| 6794 | } |
| 6795 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6796 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6797 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6798 | LOG(FATAL) << "Unreachable"; |
| 6799 | } |
| 6800 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6801 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6802 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6803 | LocationSummary* locations = |
| 6804 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6805 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6806 | } |
| 6807 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6808 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6809 | int32_t lower_bound, |
| 6810 | uint32_t num_entries, |
| 6811 | HBasicBlock* switch_block, |
| 6812 | HBasicBlock* default_block) { |
| 6813 | // Figure out the correct compare values and jump conditions. |
| 6814 | // Handle the first compare/branch as a special case because it might |
| 6815 | // jump to the default case. |
| 6816 | DCHECK_GT(num_entries, 2u); |
| 6817 | Condition first_condition; |
| 6818 | uint32_t index; |
| 6819 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6820 | if (lower_bound != 0) { |
| 6821 | first_condition = kLess; |
| 6822 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6823 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6824 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6825 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6826 | index = 1; |
| 6827 | } else { |
| 6828 | // Handle all the compare/jumps below. |
| 6829 | first_condition = kBelow; |
| 6830 | index = 0; |
| 6831 | } |
| 6832 | |
| 6833 | // Handle the rest of the compare/jumps. |
| 6834 | for (; index + 1 < num_entries; index += 2) { |
| 6835 | int32_t compare_to_value = lower_bound + index + 1; |
| 6836 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6837 | // Jump to successors[index] if value < case_value[index]. |
| 6838 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6839 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6840 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6841 | } |
| 6842 | |
| 6843 | if (index != num_entries) { |
| 6844 | // There are an odd number of entries. Handle the last one. |
| 6845 | DCHECK_EQ(index + 1, num_entries); |
| 6846 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6847 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6848 | } |
| 6849 | |
| 6850 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6851 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6852 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6853 | } |
| 6854 | } |
| 6855 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6856 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6857 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6858 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6859 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6860 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6861 | |
| 6862 | GenPackedSwitchWithCompares(value_reg, |
| 6863 | lower_bound, |
| 6864 | num_entries, |
| 6865 | switch_instr->GetBlock(), |
| 6866 | switch_instr->GetDefaultBlock()); |
| 6867 | } |
| 6868 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6869 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6870 | LocationSummary* locations = |
| 6871 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6872 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6873 | |
| 6874 | // Constant area pointer. |
| 6875 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6876 | |
| 6877 | // And the temporary we need. |
| 6878 | locations->AddTemp(Location::RequiresRegister()); |
| 6879 | } |
| 6880 | |
| 6881 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6882 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6883 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6884 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6885 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6886 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6887 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6888 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6889 | GenPackedSwitchWithCompares(value_reg, |
| 6890 | lower_bound, |
| 6891 | num_entries, |
| 6892 | switch_instr->GetBlock(), |
| 6893 | default_block); |
| 6894 | return; |
| 6895 | } |
| 6896 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6897 | // Optimizing has a jump area. |
| 6898 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6899 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6900 | |
| 6901 | // Remove the bias, if needed. |
| 6902 | if (lower_bound != 0) { |
| 6903 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6904 | value_reg = temp_reg; |
| 6905 | } |
| 6906 | |
| 6907 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6908 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6909 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6910 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6911 | |
| 6912 | // We are in the range of the table. |
| 6913 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6914 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6915 | |
| 6916 | // Compute the actual target address by adding in constant_area. |
| 6917 | __ addl(temp_reg, constant_area); |
| 6918 | |
| 6919 | // And jump. |
| 6920 | __ jmp(temp_reg); |
| 6921 | } |
| 6922 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6923 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6924 | HX86ComputeBaseMethodAddress* insn) { |
| 6925 | LocationSummary* locations = |
| 6926 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6927 | locations->SetOut(Location::RequiresRegister()); |
| 6928 | } |
| 6929 | |
| 6930 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6931 | HX86ComputeBaseMethodAddress* insn) { |
| 6932 | LocationSummary* locations = insn->GetLocations(); |
| 6933 | Register reg = locations->Out().AsRegister<Register>(); |
| 6934 | |
| 6935 | // Generate call to next instruction. |
| 6936 | Label next_instruction; |
| 6937 | __ call(&next_instruction); |
| 6938 | __ Bind(&next_instruction); |
| 6939 | |
| 6940 | // Remember this offset for later use with constant area. |
| 6941 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6942 | |
| 6943 | // Grab the return address off the stack. |
| 6944 | __ popl(reg); |
| 6945 | } |
| 6946 | |
| 6947 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6948 | HX86LoadFromConstantTable* insn) { |
| 6949 | LocationSummary* locations = |
| 6950 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6951 | |
| 6952 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6953 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6954 | |
| 6955 | // 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] | 6956 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6957 | return; |
| 6958 | } |
| 6959 | |
| 6960 | switch (insn->GetType()) { |
| 6961 | case Primitive::kPrimFloat: |
| 6962 | case Primitive::kPrimDouble: |
| 6963 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6964 | break; |
| 6965 | |
| 6966 | case Primitive::kPrimInt: |
| 6967 | locations->SetOut(Location::RequiresRegister()); |
| 6968 | break; |
| 6969 | |
| 6970 | default: |
| 6971 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6972 | } |
| 6973 | } |
| 6974 | |
| 6975 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 6976 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6977 | return; |
| 6978 | } |
| 6979 | |
| 6980 | LocationSummary* locations = insn->GetLocations(); |
| 6981 | Location out = locations->Out(); |
| 6982 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 6983 | HConstant *value = insn->GetConstant(); |
| 6984 | |
| 6985 | switch (insn->GetType()) { |
| 6986 | case Primitive::kPrimFloat: |
| 6987 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 6988 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 6989 | break; |
| 6990 | |
| 6991 | case Primitive::kPrimDouble: |
| 6992 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 6993 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 6994 | break; |
| 6995 | |
| 6996 | case Primitive::kPrimInt: |
| 6997 | __ movl(out.AsRegister<Register>(), |
| 6998 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 6999 | break; |
| 7000 | |
| 7001 | default: |
| 7002 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7003 | } |
| 7004 | } |
| 7005 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7006 | /** |
| 7007 | * Class to handle late fixup of offsets into constant area. |
| 7008 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7009 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7010 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7011 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7012 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7013 | |
| 7014 | protected: |
| 7015 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7016 | |
| 7017 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7018 | |
| 7019 | private: |
| 7020 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7021 | // Patch the correct offset for the instruction. The place to patch is the |
| 7022 | // last 4 bytes of the instruction. |
| 7023 | // The value to patch is the distance from the offset in the constant area |
| 7024 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7025 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7026 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7027 | |
| 7028 | // Patch in the right value. |
| 7029 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7030 | } |
| 7031 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7032 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7033 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7034 | }; |
| 7035 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7036 | /** |
| 7037 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7038 | * constant area. |
| 7039 | */ |
| 7040 | class JumpTableRIPFixup : public RIPFixup { |
| 7041 | public: |
| 7042 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7043 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7044 | |
| 7045 | void CreateJumpTable() { |
| 7046 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7047 | |
| 7048 | // Ensure that the reference to the jump table has the correct offset. |
| 7049 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7050 | SetOffset(offset_in_constant_table); |
| 7051 | |
| 7052 | // The label values in the jump table are computed relative to the |
| 7053 | // instruction addressing the constant area. |
| 7054 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7055 | |
| 7056 | // Populate the jump table with the correct values for the jump table. |
| 7057 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7058 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7059 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7060 | // The value that we want is the target offset - the position of the table. |
| 7061 | for (int32_t i = 0; i < num_entries; i++) { |
| 7062 | HBasicBlock* b = successors[i]; |
| 7063 | Label* l = codegen_->GetLabelOf(b); |
| 7064 | DCHECK(l->IsBound()); |
| 7065 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7066 | assembler->AppendInt32(offset_to_block); |
| 7067 | } |
| 7068 | } |
| 7069 | |
| 7070 | private: |
| 7071 | const HX86PackedSwitch* switch_instr_; |
| 7072 | }; |
| 7073 | |
| 7074 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7075 | // Generate the constant area if needed. |
| 7076 | X86Assembler* assembler = GetAssembler(); |
| 7077 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7078 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7079 | // byte values. |
| 7080 | assembler->Align(4, 0); |
| 7081 | constant_area_start_ = assembler->CodeSize(); |
| 7082 | |
| 7083 | // Populate any jump tables. |
| 7084 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7085 | jump_table->CreateJumpTable(); |
| 7086 | } |
| 7087 | |
| 7088 | // And now add the constant area to the generated code. |
| 7089 | assembler->AddConstantArea(); |
| 7090 | } |
| 7091 | |
| 7092 | // And finish up. |
| 7093 | CodeGenerator::Finalize(allocator); |
| 7094 | } |
| 7095 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7096 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7097 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7098 | return Address(reg, kDummy32BitOffset, fixup); |
| 7099 | } |
| 7100 | |
| 7101 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7102 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7103 | return Address(reg, kDummy32BitOffset, fixup); |
| 7104 | } |
| 7105 | |
| 7106 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7107 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7108 | return Address(reg, kDummy32BitOffset, fixup); |
| 7109 | } |
| 7110 | |
| 7111 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7112 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7113 | return Address(reg, kDummy32BitOffset, fixup); |
| 7114 | } |
| 7115 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7116 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7117 | Register reg, |
| 7118 | Register value) { |
| 7119 | // Create a fixup to be used to create and address the jump table. |
| 7120 | JumpTableRIPFixup* table_fixup = |
| 7121 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7122 | |
| 7123 | // We have to populate the jump tables. |
| 7124 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7125 | |
| 7126 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7127 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7128 | } |
| 7129 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7130 | // TODO: target as memory. |
| 7131 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7132 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7133 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7134 | return; |
| 7135 | } |
| 7136 | |
| 7137 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7138 | |
| 7139 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7140 | if (target.Equals(return_loc)) { |
| 7141 | return; |
| 7142 | } |
| 7143 | |
| 7144 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7145 | // with the else branch. |
| 7146 | if (type == Primitive::kPrimLong) { |
| 7147 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7148 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7149 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7150 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7151 | } else { |
| 7152 | // Let the parallel move resolver take care of all of this. |
| 7153 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7154 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7155 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7156 | } |
| 7157 | } |
| 7158 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7159 | #undef __ |
| 7160 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7161 | } // namespace x86 |
| 7162 | } // namespace art |