Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 29 | #include "pc_relative_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace x86 { |
| 42 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 47 | static constexpr int kC2ConditionMask = 0x400; |
| 48 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 49 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 50 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 54 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 58 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 61 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 62 | // Live registers will be restored in the catch block if caught. |
| 63 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 64 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 77 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 79 | }; |
| 80 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 81 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | public: |
| 83 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 84 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 85 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 86 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 88 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 89 | // Live registers will be restored in the catch block if caught. |
| 90 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 91 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 93 | instruction_, |
| 94 | instruction_->GetDexPc(), |
| 95 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 96 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 99 | bool IsFatal() const OVERRIDE { return true; } |
| 100 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 101 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | private: |
| 104 | HDivZeroCheck* const instruction_; |
| 105 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 106 | }; |
| 107 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 108 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 110 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 112 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | if (is_div_) { |
| 115 | __ negl(reg_); |
| 116 | } else { |
| 117 | __ movl(reg_, Immediate(0)); |
| 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
| 125 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | bool is_div_; |
| 127 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 130 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 132 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 134 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 135 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 136 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 137 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 138 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 139 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 140 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 141 | // Live registers will be restored in the catch block if caught. |
| 142 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 145 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 146 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 147 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 148 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 149 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 150 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 151 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 152 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 153 | instruction_, |
| 154 | instruction_->GetDexPc(), |
| 155 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 156 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 159 | bool IsFatal() const OVERRIDE { return true; } |
| 160 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 162 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 163 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 164 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 165 | |
| 166 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 167 | }; |
| 168 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 169 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 171 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 172 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 174 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 175 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 176 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 177 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 178 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 179 | instruction_, |
| 180 | instruction_->GetDexPc(), |
| 181 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 182 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 183 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 184 | if (successor_ == nullptr) { |
| 185 | __ jmp(GetReturnLabel()); |
| 186 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 187 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 188 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 191 | Label* GetReturnLabel() { |
| 192 | DCHECK(successor_ == nullptr); |
| 193 | return &return_label_; |
| 194 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 195 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 196 | HBasicBlock* GetSuccessor() const { |
| 197 | return successor_; |
| 198 | } |
| 199 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 200 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 201 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | private: |
| 203 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 204 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | Label return_label_; |
| 206 | |
| 207 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 208 | }; |
| 209 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 210 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 211 | public: |
| 212 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 213 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 214 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | LocationSummary* locations = instruction_->GetLocations(); |
| 216 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 217 | |
| 218 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 219 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 220 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 221 | |
| 222 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 223 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 224 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 225 | instruction_, |
| 226 | instruction_->GetDexPc(), |
| 227 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 228 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 229 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 230 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 231 | |
| 232 | __ jmp(GetExitLabel()); |
| 233 | } |
| 234 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 235 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 236 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 237 | private: |
| 238 | HLoadString* const instruction_; |
| 239 | |
| 240 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 241 | }; |
| 242 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 243 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | public: |
| 245 | LoadClassSlowPathX86(HLoadClass* cls, |
| 246 | HInstruction* at, |
| 247 | uint32_t dex_pc, |
| 248 | bool do_clinit) |
| 249 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 250 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 251 | } |
| 252 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 254 | LocationSummary* locations = at_->GetLocations(); |
| 255 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 256 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 257 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | |
| 259 | InvokeRuntimeCallingConvention calling_convention; |
| 260 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 261 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 262 | : QUICK_ENTRY_POINT(pInitializeType), |
| 263 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 264 | if (do_clinit_) { |
| 265 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 266 | } else { |
| 267 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 268 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | |
| 270 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 271 | Location out = locations->Out(); |
| 272 | if (out.IsValid()) { |
| 273 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 274 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 275 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 277 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 278 | __ jmp(GetExitLabel()); |
| 279 | } |
| 280 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 282 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | private: |
| 284 | // The class this slow path will load. |
| 285 | HLoadClass* const cls_; |
| 286 | |
| 287 | // The instruction where this slow path is happening. |
| 288 | // (Might be the load class or an initialization check). |
| 289 | HInstruction* const at_; |
| 290 | |
| 291 | // The dex PC of `at_`. |
| 292 | const uint32_t dex_pc_; |
| 293 | |
| 294 | // Whether to initialize the class. |
| 295 | const bool do_clinit_; |
| 296 | |
| 297 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 298 | }; |
| 299 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 300 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 302 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 303 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 305 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 307 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 308 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 309 | DCHECK(instruction_->IsCheckCast() |
| 310 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | |
| 312 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 313 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 314 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 315 | if (!is_fatal_) { |
| 316 | SaveLiveRegisters(codegen, locations); |
| 317 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 318 | |
| 319 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 320 | // move resolver. |
| 321 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 322 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 324 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 325 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 326 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 327 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 328 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 331 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 332 | instruction_, |
| 333 | instruction_->GetDexPc(), |
| 334 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 335 | CheckEntrypointTypes< |
| 336 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | } else { |
| 338 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 339 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 340 | instruction_, |
| 341 | instruction_->GetDexPc(), |
| 342 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 343 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | if (!is_fatal_) { |
| 347 | if (instruction_->IsInstanceOf()) { |
| 348 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 349 | } |
| 350 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 351 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 352 | __ jmp(GetExitLabel()); |
| 353 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 356 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 358 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 362 | |
| 363 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 364 | }; |
| 365 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 366 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 367 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 368 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 369 | : instruction_(instruction) {} |
| 370 | |
| 371 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 372 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 373 | __ Bind(GetEntryLabel()); |
| 374 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 375 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 376 | instruction_, |
| 377 | instruction_->GetDexPc(), |
| 378 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 379 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 382 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 383 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 384 | private: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 385 | HDeoptimize* const instruction_; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 386 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 387 | }; |
| 388 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 389 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 390 | public: |
| 391 | explicit ArraySetSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
| 392 | |
| 393 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 394 | LocationSummary* locations = instruction_->GetLocations(); |
| 395 | __ Bind(GetEntryLabel()); |
| 396 | SaveLiveRegisters(codegen, locations); |
| 397 | |
| 398 | InvokeRuntimeCallingConvention calling_convention; |
| 399 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 400 | parallel_move.AddMove( |
| 401 | locations->InAt(0), |
| 402 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 403 | Primitive::kPrimNot, |
| 404 | nullptr); |
| 405 | parallel_move.AddMove( |
| 406 | locations->InAt(1), |
| 407 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 408 | Primitive::kPrimInt, |
| 409 | nullptr); |
| 410 | parallel_move.AddMove( |
| 411 | locations->InAt(2), |
| 412 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 413 | Primitive::kPrimNot, |
| 414 | nullptr); |
| 415 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 416 | |
| 417 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 418 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 419 | instruction_, |
| 420 | instruction_->GetDexPc(), |
| 421 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 422 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 423 | RestoreLiveRegisters(codegen, locations); |
| 424 | __ jmp(GetExitLabel()); |
| 425 | } |
| 426 | |
| 427 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 428 | |
| 429 | private: |
| 430 | HInstruction* const instruction_; |
| 431 | |
| 432 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 433 | }; |
| 434 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 435 | // Slow path marking an object during a read barrier. |
| 436 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 437 | public: |
| 438 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
| 439 | : instruction_(instruction), out_(out), obj_(obj) { |
| 440 | DCHECK(kEmitCompilerReadBarrier); |
| 441 | } |
| 442 | |
| 443 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 444 | |
| 445 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 446 | LocationSummary* locations = instruction_->GetLocations(); |
| 447 | Register reg_out = out_.AsRegister<Register>(); |
| 448 | DCHECK(locations->CanCall()); |
| 449 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 450 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 451 | instruction_->IsStaticFieldGet() || |
| 452 | instruction_->IsArrayGet() || |
| 453 | instruction_->IsLoadClass() || |
| 454 | instruction_->IsLoadString() || |
| 455 | instruction_->IsInstanceOf() || |
| 456 | instruction_->IsCheckCast()) |
| 457 | << "Unexpected instruction in read barrier marking slow path: " |
| 458 | << instruction_->DebugName(); |
| 459 | |
| 460 | __ Bind(GetEntryLabel()); |
| 461 | SaveLiveRegisters(codegen, locations); |
| 462 | |
| 463 | InvokeRuntimeCallingConvention calling_convention; |
| 464 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 465 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 466 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 467 | instruction_, |
| 468 | instruction_->GetDexPc(), |
| 469 | this); |
| 470 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 471 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 472 | |
| 473 | RestoreLiveRegisters(codegen, locations); |
| 474 | __ jmp(GetExitLabel()); |
| 475 | } |
| 476 | |
| 477 | private: |
| 478 | HInstruction* const instruction_; |
| 479 | const Location out_; |
| 480 | const Location obj_; |
| 481 | |
| 482 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 483 | }; |
| 484 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 485 | // Slow path generating a read barrier for a heap reference. |
| 486 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 487 | public: |
| 488 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 489 | Location out, |
| 490 | Location ref, |
| 491 | Location obj, |
| 492 | uint32_t offset, |
| 493 | Location index) |
| 494 | : instruction_(instruction), |
| 495 | out_(out), |
| 496 | ref_(ref), |
| 497 | obj_(obj), |
| 498 | offset_(offset), |
| 499 | index_(index) { |
| 500 | DCHECK(kEmitCompilerReadBarrier); |
| 501 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 502 | // has been overwritten by (or after) the heap object reference load |
| 503 | // to be instrumented, e.g.: |
| 504 | // |
| 505 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 506 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 507 | // |
| 508 | // In that case, we have lost the information about the original |
| 509 | // object, and the emitted read barrier cannot work properly. |
| 510 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 511 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 512 | } |
| 513 | |
| 514 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 515 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 516 | LocationSummary* locations = instruction_->GetLocations(); |
| 517 | Register reg_out = out_.AsRegister<Register>(); |
| 518 | DCHECK(locations->CanCall()); |
| 519 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 520 | DCHECK(!instruction_->IsInvoke() || |
| 521 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 522 | instruction_->GetLocations()->Intrinsified())) |
| 523 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 524 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 525 | |
| 526 | __ Bind(GetEntryLabel()); |
| 527 | SaveLiveRegisters(codegen, locations); |
| 528 | |
| 529 | // We may have to change the index's value, but as `index_` is a |
| 530 | // constant member (like other "inputs" of this slow path), |
| 531 | // introduce a copy of it, `index`. |
| 532 | Location index = index_; |
| 533 | if (index_.IsValid()) { |
| 534 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 535 | if (instruction_->IsArrayGet()) { |
| 536 | // Compute the actual memory offset and store it in `index`. |
| 537 | Register index_reg = index_.AsRegister<Register>(); |
| 538 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 539 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 540 | // We are about to change the value of `index_reg` (see the |
| 541 | // calls to art::x86::X86Assembler::shll and |
| 542 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 543 | // not been saved by the previous call to |
| 544 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 545 | // callee-save register -- |
| 546 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 547 | // callee-save registers, as it has been designed with the |
| 548 | // assumption that callee-save registers are supposed to be |
| 549 | // handled by the called function. So, as a callee-save |
| 550 | // register, `index_reg` _would_ eventually be saved onto |
| 551 | // the stack, but it would be too late: we would have |
| 552 | // changed its value earlier. Therefore, we manually save |
| 553 | // it here into another freely available register, |
| 554 | // `free_reg`, chosen of course among the caller-save |
| 555 | // registers (as a callee-save `free_reg` register would |
| 556 | // exhibit the same problem). |
| 557 | // |
| 558 | // Note we could have requested a temporary register from |
| 559 | // the register allocator instead; but we prefer not to, as |
| 560 | // this is a slow path, and we know we can find a |
| 561 | // caller-save register that is available. |
| 562 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 563 | __ movl(free_reg, index_reg); |
| 564 | index_reg = free_reg; |
| 565 | index = Location::RegisterLocation(index_reg); |
| 566 | } else { |
| 567 | // The initial register stored in `index_` has already been |
| 568 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 569 | // (as it is not a callee-save register), so we can freely |
| 570 | // use it. |
| 571 | } |
| 572 | // Shifting the index value contained in `index_reg` by the scale |
| 573 | // factor (2) cannot overflow in practice, as the runtime is |
| 574 | // unable to allocate object arrays with a size larger than |
| 575 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 576 | __ shll(index_reg, Immediate(TIMES_4)); |
| 577 | static_assert( |
| 578 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 579 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 580 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 581 | } else { |
| 582 | DCHECK(instruction_->IsInvoke()); |
| 583 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 584 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 585 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 586 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 587 | DCHECK_EQ(offset_, 0U); |
| 588 | DCHECK(index_.IsRegisterPair()); |
| 589 | // UnsafeGet's offset location is a register pair, the low |
| 590 | // part contains the correct offset. |
| 591 | index = index_.ToLow(); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | // We're moving two or three locations to locations that could |
| 596 | // overlap, so we need a parallel move resolver. |
| 597 | InvokeRuntimeCallingConvention calling_convention; |
| 598 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 599 | parallel_move.AddMove(ref_, |
| 600 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 601 | Primitive::kPrimNot, |
| 602 | nullptr); |
| 603 | parallel_move.AddMove(obj_, |
| 604 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 605 | Primitive::kPrimNot, |
| 606 | nullptr); |
| 607 | if (index.IsValid()) { |
| 608 | parallel_move.AddMove(index, |
| 609 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 610 | Primitive::kPrimInt, |
| 611 | nullptr); |
| 612 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 613 | } else { |
| 614 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 615 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 616 | } |
| 617 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 618 | instruction_, |
| 619 | instruction_->GetDexPc(), |
| 620 | this); |
| 621 | CheckEntrypointTypes< |
| 622 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 623 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 624 | |
| 625 | RestoreLiveRegisters(codegen, locations); |
| 626 | __ jmp(GetExitLabel()); |
| 627 | } |
| 628 | |
| 629 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 630 | |
| 631 | private: |
| 632 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 633 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 634 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 635 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 636 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 637 | return static_cast<Register>(i); |
| 638 | } |
| 639 | } |
| 640 | // We shall never fail to find a free caller-save register, as |
| 641 | // there are more than two core caller-save registers on x86 |
| 642 | // (meaning it is possible to find one which is different from |
| 643 | // `ref` and `obj`). |
| 644 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 645 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 646 | UNREACHABLE(); |
| 647 | } |
| 648 | |
| 649 | HInstruction* const instruction_; |
| 650 | const Location out_; |
| 651 | const Location ref_; |
| 652 | const Location obj_; |
| 653 | const uint32_t offset_; |
| 654 | // An additional location containing an index to an array. |
| 655 | // Only used for HArrayGet and the UnsafeGetObject & |
| 656 | // UnsafeGetObjectVolatile intrinsics. |
| 657 | const Location index_; |
| 658 | |
| 659 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 660 | }; |
| 661 | |
| 662 | // Slow path generating a read barrier for a GC root. |
| 663 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 664 | public: |
| 665 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 666 | : instruction_(instruction), out_(out), root_(root) { |
| 667 | DCHECK(kEmitCompilerReadBarrier); |
| 668 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 669 | |
| 670 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 671 | LocationSummary* locations = instruction_->GetLocations(); |
| 672 | Register reg_out = out_.AsRegister<Register>(); |
| 673 | DCHECK(locations->CanCall()); |
| 674 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 675 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 676 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 677 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 678 | |
| 679 | __ Bind(GetEntryLabel()); |
| 680 | SaveLiveRegisters(codegen, locations); |
| 681 | |
| 682 | InvokeRuntimeCallingConvention calling_convention; |
| 683 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 684 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 685 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 686 | instruction_, |
| 687 | instruction_->GetDexPc(), |
| 688 | this); |
| 689 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 690 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 691 | |
| 692 | RestoreLiveRegisters(codegen, locations); |
| 693 | __ jmp(GetExitLabel()); |
| 694 | } |
| 695 | |
| 696 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 697 | |
| 698 | private: |
| 699 | HInstruction* const instruction_; |
| 700 | const Location out_; |
| 701 | const Location root_; |
| 702 | |
| 703 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 704 | }; |
| 705 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 706 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 707 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 708 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 709 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 710 | switch (cond) { |
| 711 | case kCondEQ: return kEqual; |
| 712 | case kCondNE: return kNotEqual; |
| 713 | case kCondLT: return kLess; |
| 714 | case kCondLE: return kLessEqual; |
| 715 | case kCondGT: return kGreater; |
| 716 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 717 | case kCondB: return kBelow; |
| 718 | case kCondBE: return kBelowEqual; |
| 719 | case kCondA: return kAbove; |
| 720 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 721 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 722 | LOG(FATAL) << "Unreachable"; |
| 723 | UNREACHABLE(); |
| 724 | } |
| 725 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 726 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 727 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 728 | switch (cond) { |
| 729 | case kCondEQ: return kEqual; |
| 730 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 731 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 732 | case kCondLT: return kBelow; |
| 733 | case kCondLE: return kBelowEqual; |
| 734 | case kCondGT: return kAbove; |
| 735 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 736 | // Unsigned remain unchanged. |
| 737 | case kCondB: return kBelow; |
| 738 | case kCondBE: return kBelowEqual; |
| 739 | case kCondA: return kAbove; |
| 740 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 741 | } |
| 742 | LOG(FATAL) << "Unreachable"; |
| 743 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 746 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 747 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 751 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 752 | } |
| 753 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 754 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 755 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 756 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 757 | } |
| 758 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 759 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 760 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 761 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 764 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 765 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 766 | return GetFloatingPointSpillSlotSize(); |
| 767 | } |
| 768 | |
| 769 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 770 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 771 | return GetFloatingPointSpillSlotSize(); |
| 772 | } |
| 773 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 774 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 775 | HInstruction* instruction, |
| 776 | uint32_t dex_pc, |
| 777 | SlowPathCode* slow_path) { |
| 778 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 779 | instruction, |
| 780 | dex_pc, |
| 781 | slow_path); |
| 782 | } |
| 783 | |
| 784 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 785 | HInstruction* instruction, |
| 786 | uint32_t dex_pc, |
| 787 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 788 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 789 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 790 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 791 | } |
| 792 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 793 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 794 | const X86InstructionSetFeatures& isa_features, |
| 795 | const CompilerOptions& compiler_options, |
| 796 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 797 | : CodeGenerator(graph, |
| 798 | kNumberOfCpuRegisters, |
| 799 | kNumberOfXmmRegisters, |
| 800 | kNumberOfRegisterPairs, |
| 801 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 802 | arraysize(kCoreCalleeSaves)) |
| 803 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 804 | 0, |
| 805 | compiler_options, |
| 806 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 807 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 808 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 809 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 810 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 811 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 812 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 813 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 814 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 815 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 816 | // Use a fake return address register to mimic Quick. |
| 817 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 818 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 819 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 820 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 821 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 822 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 823 | |
| 824 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 825 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 826 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 827 | UpdateBlockedPairRegisters(); |
| 828 | } |
| 829 | |
| 830 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 831 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 832 | X86ManagedRegister current = |
| 833 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 834 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 835 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 836 | blocked_register_pairs_[i] = true; |
| 837 | } |
| 838 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 839 | } |
| 840 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 841 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 842 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 843 | assembler_(codegen->GetAssembler()), |
| 844 | codegen_(codegen) {} |
| 845 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 846 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 847 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 848 | } |
| 849 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 850 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 851 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 852 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 853 | bool skip_overflow_check = |
| 854 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 855 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 856 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 857 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 858 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 859 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 860 | } |
| 861 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 862 | if (HasEmptyFrame()) { |
| 863 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 864 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 865 | |
| 866 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 867 | Register reg = kCoreCalleeSaves[i]; |
| 868 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 869 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 870 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 871 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 875 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 876 | __ subl(ESP, Immediate(adjust)); |
| 877 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 878 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 882 | __ cfi().RememberState(); |
| 883 | if (!HasEmptyFrame()) { |
| 884 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 885 | __ addl(ESP, Immediate(adjust)); |
| 886 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 887 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 888 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 889 | Register reg = kCoreCalleeSaves[i]; |
| 890 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 891 | __ popl(reg); |
| 892 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 893 | __ cfi().Restore(DWARFReg(reg)); |
| 894 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 895 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 896 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 897 | __ ret(); |
| 898 | __ cfi().RestoreState(); |
| 899 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 902 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 903 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 906 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 907 | switch (load->GetType()) { |
| 908 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 909 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 910 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 911 | |
| 912 | case Primitive::kPrimInt: |
| 913 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 914 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 915 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 916 | |
| 917 | case Primitive::kPrimBoolean: |
| 918 | case Primitive::kPrimByte: |
| 919 | case Primitive::kPrimChar: |
| 920 | case Primitive::kPrimShort: |
| 921 | case Primitive::kPrimVoid: |
| 922 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 923 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 927 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 930 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 931 | switch (type) { |
| 932 | case Primitive::kPrimBoolean: |
| 933 | case Primitive::kPrimByte: |
| 934 | case Primitive::kPrimChar: |
| 935 | case Primitive::kPrimShort: |
| 936 | case Primitive::kPrimInt: |
| 937 | case Primitive::kPrimNot: |
| 938 | return Location::RegisterLocation(EAX); |
| 939 | |
| 940 | case Primitive::kPrimLong: |
| 941 | return Location::RegisterPairLocation(EAX, EDX); |
| 942 | |
| 943 | case Primitive::kPrimVoid: |
| 944 | return Location::NoLocation(); |
| 945 | |
| 946 | case Primitive::kPrimDouble: |
| 947 | case Primitive::kPrimFloat: |
| 948 | return Location::FpuRegisterLocation(XMM0); |
| 949 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 950 | |
| 951 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 955 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 956 | } |
| 957 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 958 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 959 | switch (type) { |
| 960 | case Primitive::kPrimBoolean: |
| 961 | case Primitive::kPrimByte: |
| 962 | case Primitive::kPrimChar: |
| 963 | case Primitive::kPrimShort: |
| 964 | case Primitive::kPrimInt: |
| 965 | case Primitive::kPrimNot: { |
| 966 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 967 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 968 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 969 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 970 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 971 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 972 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 973 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 974 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 975 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 976 | uint32_t index = gp_index_; |
| 977 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 978 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 979 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 980 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 981 | calling_convention.GetRegisterPairAt(index)); |
| 982 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 983 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 984 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 989 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 990 | stack_index_++; |
| 991 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 992 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 993 | } else { |
| 994 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 999 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1000 | stack_index_ += 2; |
| 1001 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1002 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1003 | } else { |
| 1004 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1008 | case Primitive::kPrimVoid: |
| 1009 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1010 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1011 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1012 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1013 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1014 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1015 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1016 | if (source.Equals(destination)) { |
| 1017 | return; |
| 1018 | } |
| 1019 | if (destination.IsRegister()) { |
| 1020 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1021 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1022 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1023 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1024 | } else { |
| 1025 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1026 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1027 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1028 | } else if (destination.IsFpuRegister()) { |
| 1029 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1030 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1031 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1032 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1033 | } else { |
| 1034 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1035 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1036 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1037 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1038 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1039 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1040 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1041 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1042 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1043 | } else if (source.IsConstant()) { |
| 1044 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1045 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1046 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1047 | } else { |
| 1048 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1049 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1050 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1056 | if (source.Equals(destination)) { |
| 1057 | return; |
| 1058 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1059 | if (destination.IsRegisterPair()) { |
| 1060 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1061 | EmitParallelMoves( |
| 1062 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1063 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1064 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1065 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1066 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1067 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1068 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1069 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1070 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1071 | __ psrlq(src_reg, Immediate(32)); |
| 1072 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1073 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1074 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1075 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1076 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1077 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1078 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1079 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1080 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1081 | if (source.IsFpuRegister()) { |
| 1082 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1083 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1084 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1085 | } else if (source.IsRegisterPair()) { |
| 1086 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1087 | // Create stack space for 2 elements. |
| 1088 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1089 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1090 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1091 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1092 | // And remove the temporary stack space we allocated. |
| 1093 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1094 | } else { |
| 1095 | LOG(FATAL) << "Unimplemented"; |
| 1096 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1097 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1098 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1099 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1100 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1101 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1102 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1103 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1104 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1105 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1106 | } else if (source.IsConstant()) { |
| 1107 | HConstant* constant = source.GetConstant(); |
| 1108 | int64_t value; |
| 1109 | if (constant->IsLongConstant()) { |
| 1110 | value = constant->AsLongConstant()->GetValue(); |
| 1111 | } else { |
| 1112 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1113 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1114 | } |
| 1115 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1116 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1117 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1118 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1119 | EmitParallelMoves( |
| 1120 | Location::StackSlot(source.GetStackIndex()), |
| 1121 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1122 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1123 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1124 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1125 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1130 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1131 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1132 | if (instruction->IsCurrentMethod()) { |
| 1133 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1134 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1135 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1136 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1137 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1138 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1139 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1140 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1141 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1142 | } else if (location.IsStackSlot()) { |
| 1143 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 1144 | } else { |
| 1145 | DCHECK(location.IsConstant()); |
| 1146 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1147 | } |
| 1148 | } else if (const_to_move->IsLongConstant()) { |
| 1149 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1150 | if (location.IsRegisterPair()) { |
| 1151 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 1152 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 1153 | } else if (location.IsDoubleStackSlot()) { |
| 1154 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1155 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 1156 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1157 | } else { |
| 1158 | DCHECK(location.IsConstant()); |
| 1159 | DCHECK_EQ(location.GetConstant(), instruction); |
| 1160 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1161 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1162 | } else if (instruction->IsTemporary()) { |
| 1163 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1164 | if (temp_location.IsStackSlot()) { |
| 1165 | Move32(location, temp_location); |
| 1166 | } else { |
| 1167 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1168 | Move64(location, temp_location); |
| 1169 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1170 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1171 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1172 | switch (instruction->GetType()) { |
| 1173 | case Primitive::kPrimBoolean: |
| 1174 | case Primitive::kPrimByte: |
| 1175 | case Primitive::kPrimChar: |
| 1176 | case Primitive::kPrimShort: |
| 1177 | case Primitive::kPrimInt: |
| 1178 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1179 | case Primitive::kPrimFloat: |
| 1180 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1181 | break; |
| 1182 | |
| 1183 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1184 | case Primitive::kPrimDouble: |
| 1185 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1186 | break; |
| 1187 | |
| 1188 | default: |
| 1189 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 1190 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1191 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1192 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1193 | switch (instruction->GetType()) { |
| 1194 | case Primitive::kPrimBoolean: |
| 1195 | case Primitive::kPrimByte: |
| 1196 | case Primitive::kPrimChar: |
| 1197 | case Primitive::kPrimShort: |
| 1198 | case Primitive::kPrimInt: |
| 1199 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1200 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1201 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1205 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1206 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1210 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1215 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1216 | DCHECK(location.IsRegister()); |
| 1217 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1218 | } |
| 1219 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1220 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1221 | if (Primitive::Is64BitType(dst_type)) { |
| 1222 | Move64(dst, src); |
| 1223 | } else { |
| 1224 | Move32(dst, src); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1229 | if (location.IsRegister()) { |
| 1230 | locations->AddTemp(location); |
| 1231 | } else if (location.IsRegisterPair()) { |
| 1232 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1233 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1234 | } else { |
| 1235 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1236 | } |
| 1237 | } |
| 1238 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1239 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1240 | DCHECK(!successor->IsExitBlock()); |
| 1241 | |
| 1242 | HBasicBlock* block = got->GetBlock(); |
| 1243 | HInstruction* previous = got->GetPrevious(); |
| 1244 | |
| 1245 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1246 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1247 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1248 | return; |
| 1249 | } |
| 1250 | |
| 1251 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1252 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1253 | } |
| 1254 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1255 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1259 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1260 | got->SetLocations(nullptr); |
| 1261 | } |
| 1262 | |
| 1263 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1264 | HandleGoto(got, got->GetSuccessor()); |
| 1265 | } |
| 1266 | |
| 1267 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1268 | try_boundary->SetLocations(nullptr); |
| 1269 | } |
| 1270 | |
| 1271 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1272 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1273 | if (!successor->IsExitBlock()) { |
| 1274 | HandleGoto(try_boundary, successor); |
| 1275 | } |
| 1276 | } |
| 1277 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1278 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1279 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1282 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1285 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1286 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1287 | LabelType* true_label, |
| 1288 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1289 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1290 | __ j(kUnordered, true_label); |
| 1291 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1292 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1293 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1294 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1297 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1298 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1299 | LabelType* true_label, |
| 1300 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1301 | LocationSummary* locations = cond->GetLocations(); |
| 1302 | Location left = locations->InAt(0); |
| 1303 | Location right = locations->InAt(1); |
| 1304 | IfCondition if_cond = cond->GetCondition(); |
| 1305 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1306 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1307 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1308 | IfCondition true_high_cond = if_cond; |
| 1309 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1310 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | |
| 1312 | // Set the conditions for the test, remembering that == needs to be |
| 1313 | // decided using the low words. |
| 1314 | switch (if_cond) { |
| 1315 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1316 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1317 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1318 | break; |
| 1319 | case kCondLT: |
| 1320 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1321 | break; |
| 1322 | case kCondLE: |
| 1323 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | break; |
| 1325 | case kCondGT: |
| 1326 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1327 | break; |
| 1328 | case kCondGE: |
| 1329 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1330 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1331 | case kCondB: |
| 1332 | false_high_cond = kCondA; |
| 1333 | break; |
| 1334 | case kCondBE: |
| 1335 | true_high_cond = kCondB; |
| 1336 | break; |
| 1337 | case kCondA: |
| 1338 | false_high_cond = kCondB; |
| 1339 | break; |
| 1340 | case kCondAE: |
| 1341 | true_high_cond = kCondA; |
| 1342 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | if (right.IsConstant()) { |
| 1346 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1347 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1348 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1349 | |
| 1350 | if (val_high == 0) { |
| 1351 | __ testl(left_high, left_high); |
| 1352 | } else { |
| 1353 | __ cmpl(left_high, Immediate(val_high)); |
| 1354 | } |
| 1355 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1356 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1357 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1358 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1360 | __ j(X86Condition(true_high_cond), true_label); |
| 1361 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | } |
| 1363 | // Must be equal high, so compare the lows. |
| 1364 | if (val_low == 0) { |
| 1365 | __ testl(left_low, left_low); |
| 1366 | } else { |
| 1367 | __ cmpl(left_low, Immediate(val_low)); |
| 1368 | } |
| 1369 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1370 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1371 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | |
| 1373 | __ cmpl(left_high, right_high); |
| 1374 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1375 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1376 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1377 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1378 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1379 | __ j(X86Condition(true_high_cond), true_label); |
| 1380 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | } |
| 1382 | // Must be equal high, so compare the lows. |
| 1383 | __ cmpl(left_low, right_low); |
| 1384 | } |
| 1385 | // The last comparison might be unsigned. |
| 1386 | __ j(final_condition, true_label); |
| 1387 | } |
| 1388 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1389 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1390 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1391 | LabelType* true_target_in, |
| 1392 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1393 | // Generated branching requires both targets to be explicit. If either of the |
| 1394 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1395 | LabelType fallthrough_target; |
| 1396 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1397 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1398 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1399 | LocationSummary* locations = condition->GetLocations(); |
| 1400 | Location left = locations->InAt(0); |
| 1401 | Location right = locations->InAt(1); |
| 1402 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1403 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1404 | switch (type) { |
| 1405 | case Primitive::kPrimLong: |
| 1406 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1407 | break; |
| 1408 | case Primitive::kPrimFloat: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1409 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | GenerateFPJumps(condition, true_target, false_target); |
| 1411 | break; |
| 1412 | case Primitive::kPrimDouble: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1413 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1414 | GenerateFPJumps(condition, true_target, false_target); |
| 1415 | break; |
| 1416 | default: |
| 1417 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1418 | } |
| 1419 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1420 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | __ jmp(false_target); |
| 1422 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1423 | |
| 1424 | if (fallthrough_target.IsLinked()) { |
| 1425 | __ Bind(&fallthrough_target); |
| 1426 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1429 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1430 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1431 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1432 | // conditions if they are materialized due to the complex branching. |
| 1433 | return cond->IsCondition() && |
| 1434 | cond->GetNext() == branch && |
| 1435 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1436 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1437 | } |
| 1438 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1439 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1440 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1441 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1442 | LabelType* true_target, |
| 1443 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1444 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1445 | |
| 1446 | if (true_target == nullptr && false_target == nullptr) { |
| 1447 | // Nothing to do. The code always falls through. |
| 1448 | return; |
| 1449 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1450 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1451 | if (cond->AsIntConstant()->IsOne()) { |
| 1452 | if (true_target != nullptr) { |
| 1453 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1454 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1455 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1456 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1457 | if (false_target != nullptr) { |
| 1458 | __ jmp(false_target); |
| 1459 | } |
| 1460 | } |
| 1461 | return; |
| 1462 | } |
| 1463 | |
| 1464 | // The following code generates these patterns: |
| 1465 | // (1) true_target == nullptr && false_target != nullptr |
| 1466 | // - opposite condition true => branch to false_target |
| 1467 | // (2) true_target != nullptr && false_target == nullptr |
| 1468 | // - condition true => branch to true_target |
| 1469 | // (3) true_target != nullptr && false_target != nullptr |
| 1470 | // - condition true => branch to true_target |
| 1471 | // - branch to false_target |
| 1472 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1473 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1474 | if (true_target == nullptr) { |
| 1475 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1476 | } else { |
| 1477 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1478 | } |
| 1479 | } else { |
| 1480 | // Materialized condition, compare against 0. |
| 1481 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1482 | if (lhs.IsRegister()) { |
| 1483 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1484 | } else { |
| 1485 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1486 | } |
| 1487 | if (true_target == nullptr) { |
| 1488 | __ j(kEqual, false_target); |
| 1489 | } else { |
| 1490 | __ j(kNotEqual, true_target); |
| 1491 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1492 | } |
| 1493 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1494 | // Condition has not been materialized, use its inputs as the comparison and |
| 1495 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1496 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1497 | |
| 1498 | // If this is a long or FP comparison that has been folded into |
| 1499 | // the HCondition, generate the comparison directly. |
| 1500 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1501 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1502 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1503 | return; |
| 1504 | } |
| 1505 | |
| 1506 | Location lhs = condition->GetLocations()->InAt(0); |
| 1507 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1508 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1509 | if (rhs.IsRegister()) { |
| 1510 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1511 | } else if (rhs.IsConstant()) { |
| 1512 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1513 | if (constant == 0) { |
| 1514 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1515 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1516 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1517 | } |
| 1518 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1519 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1520 | } |
| 1521 | if (true_target == nullptr) { |
| 1522 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1523 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1524 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1525 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1526 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1527 | |
| 1528 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1529 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1530 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1531 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1535 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1536 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1537 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1538 | locations->SetInAt(0, Location::Any()); |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1543 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1544 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1545 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1546 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1547 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1548 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1549 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1553 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1554 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1555 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1556 | locations->SetInAt(0, Location::Any()); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1561 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1562 | GenerateTestAndBranch(deoptimize, |
| 1563 | /* condition_input_index */ 0, |
| 1564 | slow_path->GetEntryLabel(), |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1565 | /* false_target */ static_cast<Label*>(nullptr)); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1568 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1569 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1570 | } |
| 1571 | |
| 1572 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1573 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1574 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1575 | __ nop(); |
| 1576 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1577 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1578 | } |
| 1579 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1580 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1581 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1584 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1585 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1588 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1589 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1592 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1593 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1596 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1597 | LocationSummary* locations = |
| 1598 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1599 | switch (store->InputAt(1)->GetType()) { |
| 1600 | case Primitive::kPrimBoolean: |
| 1601 | case Primitive::kPrimByte: |
| 1602 | case Primitive::kPrimChar: |
| 1603 | case Primitive::kPrimShort: |
| 1604 | case Primitive::kPrimInt: |
| 1605 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1606 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1607 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1608 | break; |
| 1609 | |
| 1610 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1611 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1612 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1613 | break; |
| 1614 | |
| 1615 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1616 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1617 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1620 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1623 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1624 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1625 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1626 | // Handle the long/FP comparisons made in instruction simplification. |
| 1627 | switch (cond->InputAt(0)->GetType()) { |
| 1628 | case Primitive::kPrimLong: { |
| 1629 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1630 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 1631 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1632 | locations->SetOut(Location::RequiresRegister()); |
| 1633 | } |
| 1634 | break; |
| 1635 | } |
| 1636 | case Primitive::kPrimFloat: |
| 1637 | case Primitive::kPrimDouble: { |
| 1638 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1639 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 1640 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1641 | locations->SetOut(Location::RequiresRegister()); |
| 1642 | } |
| 1643 | break; |
| 1644 | } |
| 1645 | default: |
| 1646 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1647 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 1648 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1649 | // We need a byte register. |
| 1650 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1651 | } |
| 1652 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1653 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1656 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 1657 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1658 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1659 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1660 | |
| 1661 | LocationSummary* locations = cond->GetLocations(); |
| 1662 | Location lhs = locations->InAt(0); |
| 1663 | Location rhs = locations->InAt(1); |
| 1664 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1665 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1666 | |
| 1667 | switch (cond->InputAt(0)->GetType()) { |
| 1668 | default: { |
| 1669 | // Integer case. |
| 1670 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1671 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1672 | __ xorl(reg, reg); |
| 1673 | |
| 1674 | if (rhs.IsRegister()) { |
| 1675 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1676 | } else if (rhs.IsConstant()) { |
| 1677 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1678 | if (constant == 0) { |
| 1679 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1680 | } else { |
| 1681 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1682 | } |
| 1683 | } else { |
| 1684 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1685 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1686 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1687 | return; |
| 1688 | } |
| 1689 | case Primitive::kPrimLong: |
| 1690 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1691 | break; |
| 1692 | case Primitive::kPrimFloat: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1693 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1694 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1695 | break; |
| 1696 | case Primitive::kPrimDouble: |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 1697 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1698 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1699 | break; |
| 1700 | } |
| 1701 | |
| 1702 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1703 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1705 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1706 | __ Bind(&false_label); |
| 1707 | __ xorl(reg, reg); |
| 1708 | __ jmp(&done_label); |
| 1709 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1710 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1711 | __ Bind(&true_label); |
| 1712 | __ movl(reg, Immediate(1)); |
| 1713 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1717 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1721 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1725 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1729 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1733 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1737 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1741 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1745 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1749 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1753 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1757 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1761 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1764 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1765 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1769 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1773 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1777 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1781 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1785 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1789 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1793 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1796 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1797 | LocationSummary* locations = |
| 1798 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1799 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1802 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1803 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1806 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1807 | LocationSummary* locations = |
| 1808 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1809 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1810 | } |
| 1811 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1812 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1813 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1816 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1817 | LocationSummary* locations = |
| 1818 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1819 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1822 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1823 | // Will be generated at use site. |
| 1824 | } |
| 1825 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1826 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1827 | LocationSummary* locations = |
| 1828 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1829 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1830 | } |
| 1831 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1832 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1833 | // Will be generated at use site. |
| 1834 | } |
| 1835 | |
| 1836 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1837 | LocationSummary* locations = |
| 1838 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1839 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1840 | } |
| 1841 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1842 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1843 | // Will be generated at use site. |
| 1844 | } |
| 1845 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1846 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1847 | memory_barrier->SetLocations(nullptr); |
| 1848 | } |
| 1849 | |
| 1850 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1851 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1852 | } |
| 1853 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1854 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1855 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1858 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1859 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1862 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1863 | LocationSummary* locations = |
| 1864 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1865 | switch (ret->InputAt(0)->GetType()) { |
| 1866 | case Primitive::kPrimBoolean: |
| 1867 | case Primitive::kPrimByte: |
| 1868 | case Primitive::kPrimChar: |
| 1869 | case Primitive::kPrimShort: |
| 1870 | case Primitive::kPrimInt: |
| 1871 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1872 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1873 | break; |
| 1874 | |
| 1875 | case Primitive::kPrimLong: |
| 1876 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1877 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1878 | break; |
| 1879 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1880 | case Primitive::kPrimFloat: |
| 1881 | case Primitive::kPrimDouble: |
| 1882 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1883 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1884 | break; |
| 1885 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1886 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1887 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1888 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1889 | } |
| 1890 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1891 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1892 | if (kIsDebugBuild) { |
| 1893 | switch (ret->InputAt(0)->GetType()) { |
| 1894 | case Primitive::kPrimBoolean: |
| 1895 | case Primitive::kPrimByte: |
| 1896 | case Primitive::kPrimChar: |
| 1897 | case Primitive::kPrimShort: |
| 1898 | case Primitive::kPrimInt: |
| 1899 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1900 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1901 | break; |
| 1902 | |
| 1903 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1904 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1905 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1906 | break; |
| 1907 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1908 | case Primitive::kPrimFloat: |
| 1909 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1910 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1911 | break; |
| 1912 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1913 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1914 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1915 | } |
| 1916 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1917 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1920 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1921 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1922 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1923 | // the method_idx. |
| 1924 | HandleInvoke(invoke); |
| 1925 | } |
| 1926 | |
| 1927 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1928 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1929 | } |
| 1930 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1931 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1932 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1933 | // art::PrepareForRegisterAllocation. |
| 1934 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1935 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1936 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1937 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1938 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1939 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1940 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1941 | return; |
| 1942 | } |
| 1943 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1944 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1945 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1946 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1947 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1948 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1949 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1952 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1953 | if (invoke->GetLocations()->Intrinsified()) { |
| 1954 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1955 | intrinsic.Dispatch(invoke); |
| 1956 | return true; |
| 1957 | } |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1961 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1962 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1963 | // art::PrepareForRegisterAllocation. |
| 1964 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1965 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1966 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1967 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1968 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1969 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1970 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1971 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1972 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1973 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1977 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1978 | if (intrinsic.TryDispatch(invoke)) { |
| 1979 | return; |
| 1980 | } |
| 1981 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1982 | HandleInvoke(invoke); |
| 1983 | } |
| 1984 | |
| 1985 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1986 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1987 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1990 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1991 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1992 | return; |
| 1993 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1994 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1995 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1996 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1997 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2000 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2001 | // This call to HandleInvoke allocates a temporary (core) register |
| 2002 | // which is also used to transfer the hidden argument from FP to |
| 2003 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2004 | HandleInvoke(invoke); |
| 2005 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2006 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2010 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2011 | LocationSummary* locations = invoke->GetLocations(); |
| 2012 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2013 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2014 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2015 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2016 | Location receiver = locations->InAt(0); |
| 2017 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2018 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2019 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2020 | // won't be modified thereafter, before the `call` instruction. |
| 2021 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2022 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2023 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2024 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2025 | if (receiver.IsStackSlot()) { |
| 2026 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2027 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2028 | __ movl(temp, Address(temp, class_offset)); |
| 2029 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2030 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2031 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2032 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2033 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2034 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2035 | // emit a read barrier for the previous class reference load. |
| 2036 | // However this is not required in practice, as this is an |
| 2037 | // intermediate/temporary reference and because the current |
| 2038 | // concurrent copying collector keeps the from-space memory |
| 2039 | // intact/accessible until the end of the marking phase (the |
| 2040 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2041 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2042 | // temp = temp->GetImtEntryAt(method_offset); |
| 2043 | __ movl(temp, Address(temp, method_offset)); |
| 2044 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2045 | __ call(Address(temp, |
| 2046 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2047 | |
| 2048 | DCHECK(!codegen_->IsLeafMethod()); |
| 2049 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2050 | } |
| 2051 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2052 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2053 | LocationSummary* locations = |
| 2054 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2055 | switch (neg->GetResultType()) { |
| 2056 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2057 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2058 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2059 | locations->SetOut(Location::SameAsFirstInput()); |
| 2060 | break; |
| 2061 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2062 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2063 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2064 | locations->SetOut(Location::SameAsFirstInput()); |
| 2065 | locations->AddTemp(Location::RequiresRegister()); |
| 2066 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2067 | break; |
| 2068 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2069 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2070 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2071 | locations->SetOut(Location::SameAsFirstInput()); |
| 2072 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2073 | break; |
| 2074 | |
| 2075 | default: |
| 2076 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2081 | LocationSummary* locations = neg->GetLocations(); |
| 2082 | Location out = locations->Out(); |
| 2083 | Location in = locations->InAt(0); |
| 2084 | switch (neg->GetResultType()) { |
| 2085 | case Primitive::kPrimInt: |
| 2086 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2087 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2088 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2089 | break; |
| 2090 | |
| 2091 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2092 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2093 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2094 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2095 | // Negation is similar to subtraction from zero. The least |
| 2096 | // significant byte triggers a borrow when it is different from |
| 2097 | // zero; to take it into account, add 1 to the most significant |
| 2098 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2099 | // operation. |
| 2100 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2101 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2102 | break; |
| 2103 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2104 | case Primitive::kPrimFloat: { |
| 2105 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2106 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2107 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2108 | // Implement float negation with an exclusive or with value |
| 2109 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2110 | // single-precision floating-point number). |
| 2111 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2112 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2113 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2114 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2115 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2116 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2117 | case Primitive::kPrimDouble: { |
| 2118 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2119 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2120 | // Implement double negation with an exclusive or with value |
| 2121 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2122 | // a double-precision floating-point number). |
| 2123 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2124 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2125 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2126 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2127 | |
| 2128 | default: |
| 2129 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2130 | } |
| 2131 | } |
| 2132 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2133 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2134 | Primitive::Type result_type = conversion->GetResultType(); |
| 2135 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2136 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2137 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2138 | // The float-to-long and double-to-long type conversions rely on a |
| 2139 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2140 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2141 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2142 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2143 | ? LocationSummary::kCall |
| 2144 | : LocationSummary::kNoCall; |
| 2145 | LocationSummary* locations = |
| 2146 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2147 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2148 | // The Java language does not allow treating boolean as an integral type but |
| 2149 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2150 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2151 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2152 | case Primitive::kPrimByte: |
| 2153 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2154 | case Primitive::kPrimBoolean: |
| 2155 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2156 | case Primitive::kPrimShort: |
| 2157 | case Primitive::kPrimInt: |
| 2158 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2159 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2160 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2161 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2162 | // the validation of the linear scan implementation |
| 2163 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2164 | break; |
| 2165 | |
| 2166 | default: |
| 2167 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2168 | << " to " << result_type; |
| 2169 | } |
| 2170 | break; |
| 2171 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2172 | case Primitive::kPrimShort: |
| 2173 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2174 | case Primitive::kPrimBoolean: |
| 2175 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2176 | case Primitive::kPrimByte: |
| 2177 | case Primitive::kPrimInt: |
| 2178 | case Primitive::kPrimChar: |
| 2179 | // Processing a Dex `int-to-short' instruction. |
| 2180 | locations->SetInAt(0, Location::Any()); |
| 2181 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2182 | break; |
| 2183 | |
| 2184 | default: |
| 2185 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2186 | << " to " << result_type; |
| 2187 | } |
| 2188 | break; |
| 2189 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2190 | case Primitive::kPrimInt: |
| 2191 | switch (input_type) { |
| 2192 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2193 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2194 | locations->SetInAt(0, Location::Any()); |
| 2195 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2196 | break; |
| 2197 | |
| 2198 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2199 | // Processing a Dex `float-to-int' instruction. |
| 2200 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2201 | locations->SetOut(Location::RequiresRegister()); |
| 2202 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2203 | break; |
| 2204 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2205 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2206 | // Processing a Dex `double-to-int' instruction. |
| 2207 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2208 | locations->SetOut(Location::RequiresRegister()); |
| 2209 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | |
| 2212 | default: |
| 2213 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2214 | << " to " << result_type; |
| 2215 | } |
| 2216 | break; |
| 2217 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2218 | case Primitive::kPrimLong: |
| 2219 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2220 | case Primitive::kPrimBoolean: |
| 2221 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2222 | case Primitive::kPrimByte: |
| 2223 | case Primitive::kPrimShort: |
| 2224 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2225 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2226 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2227 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2228 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2229 | break; |
| 2230 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2231 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2233 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2234 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2235 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2236 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2237 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2238 | // The runtime helper puts the result in EAX, EDX. |
| 2239 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2240 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2241 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2242 | |
| 2243 | default: |
| 2244 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2245 | << " to " << result_type; |
| 2246 | } |
| 2247 | break; |
| 2248 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2249 | case Primitive::kPrimChar: |
| 2250 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2251 | case Primitive::kPrimBoolean: |
| 2252 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2253 | case Primitive::kPrimByte: |
| 2254 | case Primitive::kPrimShort: |
| 2255 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2256 | // Processing a Dex `int-to-char' instruction. |
| 2257 | locations->SetInAt(0, Location::Any()); |
| 2258 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2259 | break; |
| 2260 | |
| 2261 | default: |
| 2262 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2263 | << " to " << result_type; |
| 2264 | } |
| 2265 | break; |
| 2266 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2267 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2268 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2269 | case Primitive::kPrimBoolean: |
| 2270 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2271 | case Primitive::kPrimByte: |
| 2272 | case Primitive::kPrimShort: |
| 2273 | case Primitive::kPrimInt: |
| 2274 | case Primitive::kPrimChar: |
| 2275 | // Processing a Dex `int-to-float' instruction. |
| 2276 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2277 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2278 | break; |
| 2279 | |
| 2280 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2281 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2282 | locations->SetInAt(0, Location::Any()); |
| 2283 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2286 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2287 | // Processing a Dex `double-to-float' instruction. |
| 2288 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2289 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2290 | break; |
| 2291 | |
| 2292 | default: |
| 2293 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2294 | << " to " << result_type; |
| 2295 | }; |
| 2296 | break; |
| 2297 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2298 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2299 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2300 | case Primitive::kPrimBoolean: |
| 2301 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2302 | case Primitive::kPrimByte: |
| 2303 | case Primitive::kPrimShort: |
| 2304 | case Primitive::kPrimInt: |
| 2305 | case Primitive::kPrimChar: |
| 2306 | // Processing a Dex `int-to-double' instruction. |
| 2307 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2308 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2309 | break; |
| 2310 | |
| 2311 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2312 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2313 | locations->SetInAt(0, Location::Any()); |
| 2314 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2315 | break; |
| 2316 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2317 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2318 | // Processing a Dex `float-to-double' instruction. |
| 2319 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2320 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2321 | break; |
| 2322 | |
| 2323 | default: |
| 2324 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2325 | << " to " << result_type; |
| 2326 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2327 | break; |
| 2328 | |
| 2329 | default: |
| 2330 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2331 | << " to " << result_type; |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2336 | LocationSummary* locations = conversion->GetLocations(); |
| 2337 | Location out = locations->Out(); |
| 2338 | Location in = locations->InAt(0); |
| 2339 | Primitive::Type result_type = conversion->GetResultType(); |
| 2340 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2341 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2342 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimByte: |
| 2344 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimBoolean: |
| 2346 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2347 | case Primitive::kPrimShort: |
| 2348 | case Primitive::kPrimInt: |
| 2349 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2350 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2351 | if (in.IsRegister()) { |
| 2352 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2353 | } else { |
| 2354 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2355 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2356 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2357 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | |
| 2360 | default: |
| 2361 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2362 | << " to " << result_type; |
| 2363 | } |
| 2364 | break; |
| 2365 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2366 | case Primitive::kPrimShort: |
| 2367 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2368 | case Primitive::kPrimBoolean: |
| 2369 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2370 | case Primitive::kPrimByte: |
| 2371 | case Primitive::kPrimInt: |
| 2372 | case Primitive::kPrimChar: |
| 2373 | // Processing a Dex `int-to-short' instruction. |
| 2374 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2375 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2376 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2377 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2378 | } else { |
| 2379 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2380 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2381 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2382 | } |
| 2383 | break; |
| 2384 | |
| 2385 | default: |
| 2386 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2387 | << " to " << result_type; |
| 2388 | } |
| 2389 | break; |
| 2390 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2391 | case Primitive::kPrimInt: |
| 2392 | switch (input_type) { |
| 2393 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2394 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2395 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2396 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2397 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2398 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2399 | } else { |
| 2400 | DCHECK(in.IsConstant()); |
| 2401 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2402 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2403 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2404 | } |
| 2405 | break; |
| 2406 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2407 | case Primitive::kPrimFloat: { |
| 2408 | // Processing a Dex `float-to-int' instruction. |
| 2409 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2410 | Register output = out.AsRegister<Register>(); |
| 2411 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2412 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2413 | |
| 2414 | __ movl(output, Immediate(kPrimIntMax)); |
| 2415 | // temp = int-to-float(output) |
| 2416 | __ cvtsi2ss(temp, output); |
| 2417 | // if input >= temp goto done |
| 2418 | __ comiss(input, temp); |
| 2419 | __ j(kAboveEqual, &done); |
| 2420 | // if input == NaN goto nan |
| 2421 | __ j(kUnordered, &nan); |
| 2422 | // output = float-to-int-truncate(input) |
| 2423 | __ cvttss2si(output, input); |
| 2424 | __ jmp(&done); |
| 2425 | __ Bind(&nan); |
| 2426 | // output = 0 |
| 2427 | __ xorl(output, output); |
| 2428 | __ Bind(&done); |
| 2429 | break; |
| 2430 | } |
| 2431 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2432 | case Primitive::kPrimDouble: { |
| 2433 | // Processing a Dex `double-to-int' instruction. |
| 2434 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2435 | Register output = out.AsRegister<Register>(); |
| 2436 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2437 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2438 | |
| 2439 | __ movl(output, Immediate(kPrimIntMax)); |
| 2440 | // temp = int-to-double(output) |
| 2441 | __ cvtsi2sd(temp, output); |
| 2442 | // if input >= temp goto done |
| 2443 | __ comisd(input, temp); |
| 2444 | __ j(kAboveEqual, &done); |
| 2445 | // if input == NaN goto nan |
| 2446 | __ j(kUnordered, &nan); |
| 2447 | // output = double-to-int-truncate(input) |
| 2448 | __ cvttsd2si(output, input); |
| 2449 | __ jmp(&done); |
| 2450 | __ Bind(&nan); |
| 2451 | // output = 0 |
| 2452 | __ xorl(output, output); |
| 2453 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2454 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2455 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2456 | |
| 2457 | default: |
| 2458 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2459 | << " to " << result_type; |
| 2460 | } |
| 2461 | break; |
| 2462 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2463 | case Primitive::kPrimLong: |
| 2464 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimBoolean: |
| 2466 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2467 | case Primitive::kPrimByte: |
| 2468 | case Primitive::kPrimShort: |
| 2469 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2471 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2472 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2473 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2474 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2475 | __ cdq(); |
| 2476 | break; |
| 2477 | |
| 2478 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2479 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2480 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2481 | conversion, |
| 2482 | conversion->GetDexPc(), |
| 2483 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2484 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2485 | break; |
| 2486 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2487 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2488 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2489 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2490 | conversion, |
| 2491 | conversion->GetDexPc(), |
| 2492 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2493 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2494 | break; |
| 2495 | |
| 2496 | default: |
| 2497 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2498 | << " to " << result_type; |
| 2499 | } |
| 2500 | break; |
| 2501 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2502 | case Primitive::kPrimChar: |
| 2503 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2504 | case Primitive::kPrimBoolean: |
| 2505 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2506 | case Primitive::kPrimByte: |
| 2507 | case Primitive::kPrimShort: |
| 2508 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2509 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2510 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2511 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2512 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2513 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2514 | } else { |
| 2515 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2516 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2517 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2518 | } |
| 2519 | break; |
| 2520 | |
| 2521 | default: |
| 2522 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2523 | << " to " << result_type; |
| 2524 | } |
| 2525 | break; |
| 2526 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2527 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2528 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2529 | case Primitive::kPrimBoolean: |
| 2530 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2531 | case Primitive::kPrimByte: |
| 2532 | case Primitive::kPrimShort: |
| 2533 | case Primitive::kPrimInt: |
| 2534 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2535 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2536 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2537 | break; |
| 2538 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2539 | case Primitive::kPrimLong: { |
| 2540 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2541 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2542 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2543 | // Create stack space for the call to |
| 2544 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2545 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2546 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2547 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2548 | __ subl(ESP, Immediate(adjustment)); |
| 2549 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2550 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2551 | // Load the value to the FP stack, using temporaries if needed. |
| 2552 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2553 | |
| 2554 | if (out.IsStackSlot()) { |
| 2555 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2556 | } else { |
| 2557 | __ fstps(Address(ESP, 0)); |
| 2558 | Location stack_temp = Location::StackSlot(0); |
| 2559 | codegen_->Move32(out, stack_temp); |
| 2560 | } |
| 2561 | |
| 2562 | // Remove the temporary stack space we allocated. |
| 2563 | if (adjustment != 0) { |
| 2564 | __ addl(ESP, Immediate(adjustment)); |
| 2565 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2566 | break; |
| 2567 | } |
| 2568 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2570 | // Processing a Dex `double-to-float' instruction. |
| 2571 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2572 | break; |
| 2573 | |
| 2574 | default: |
| 2575 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2576 | << " to " << result_type; |
| 2577 | }; |
| 2578 | break; |
| 2579 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2580 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2581 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2582 | case Primitive::kPrimBoolean: |
| 2583 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2584 | case Primitive::kPrimByte: |
| 2585 | case Primitive::kPrimShort: |
| 2586 | case Primitive::kPrimInt: |
| 2587 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2588 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2589 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2590 | break; |
| 2591 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimLong: { |
| 2593 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2594 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2595 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2596 | // Create stack space for the call to |
| 2597 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2598 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2599 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2600 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2601 | __ subl(ESP, Immediate(adjustment)); |
| 2602 | } |
| 2603 | |
| 2604 | // Load the value to the FP stack, using temporaries if needed. |
| 2605 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2606 | |
| 2607 | if (out.IsDoubleStackSlot()) { |
| 2608 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2609 | } else { |
| 2610 | __ fstpl(Address(ESP, 0)); |
| 2611 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2612 | codegen_->Move64(out, stack_temp); |
| 2613 | } |
| 2614 | |
| 2615 | // Remove the temporary stack space we allocated. |
| 2616 | if (adjustment != 0) { |
| 2617 | __ addl(ESP, Immediate(adjustment)); |
| 2618 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2619 | break; |
| 2620 | } |
| 2621 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2622 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2623 | // Processing a Dex `float-to-double' instruction. |
| 2624 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2625 | break; |
| 2626 | |
| 2627 | default: |
| 2628 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2629 | << " to " << result_type; |
| 2630 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2631 | break; |
| 2632 | |
| 2633 | default: |
| 2634 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2635 | << " to " << result_type; |
| 2636 | } |
| 2637 | } |
| 2638 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2639 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2640 | LocationSummary* locations = |
| 2641 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2642 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2643 | case Primitive::kPrimInt: { |
| 2644 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2645 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2646 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2647 | break; |
| 2648 | } |
| 2649 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2650 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2651 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2652 | locations->SetInAt(1, Location::Any()); |
| 2653 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2654 | break; |
| 2655 | } |
| 2656 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2657 | case Primitive::kPrimFloat: |
| 2658 | case Primitive::kPrimDouble: { |
| 2659 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2660 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2661 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
| 2662 | } else { |
| 2663 | locations->SetInAt(1, Location::Any()); |
| 2664 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2665 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2666 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2667 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2668 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2669 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2670 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2671 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2672 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2676 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2677 | Location first = locations->InAt(0); |
| 2678 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2679 | Location out = locations->Out(); |
| 2680 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2681 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2682 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2683 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2684 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2685 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2686 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2687 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2688 | } else { |
| 2689 | __ leal(out.AsRegister<Register>(), Address( |
| 2690 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2691 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2692 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2693 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2694 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2695 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2696 | } else { |
| 2697 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2698 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2699 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2700 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2701 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2702 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2703 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2707 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2708 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2709 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2710 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2711 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2712 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2713 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2714 | } else { |
| 2715 | DCHECK(second.IsConstant()) << second; |
| 2716 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2717 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2718 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2719 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2720 | break; |
| 2721 | } |
| 2722 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2723 | case Primitive::kPrimFloat: { |
| 2724 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2725 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2726 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2727 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2728 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2729 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2730 | codegen_->LiteralFloatAddress( |
| 2731 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2732 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2733 | } else { |
| 2734 | DCHECK(second.IsStackSlot()); |
| 2735 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2736 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2737 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | case Primitive::kPrimDouble: { |
| 2741 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2742 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2743 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2744 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2745 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2746 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2747 | codegen_->LiteralDoubleAddress( |
| 2748 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2749 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2750 | } else { |
| 2751 | DCHECK(second.IsDoubleStackSlot()); |
| 2752 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2753 | } |
| 2754 | break; |
| 2755 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2756 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2757 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2758 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2759 | } |
| 2760 | } |
| 2761 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2762 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2763 | LocationSummary* locations = |
| 2764 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2765 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2766 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2767 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2768 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2769 | locations->SetInAt(1, Location::Any()); |
| 2770 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2771 | break; |
| 2772 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2773 | case Primitive::kPrimFloat: |
| 2774 | case Primitive::kPrimDouble: { |
| 2775 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2776 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2777 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
| 2778 | } else { |
| 2779 | locations->SetInAt(1, Location::Any()); |
| 2780 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2781 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2782 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2783 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2784 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2785 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2786 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2787 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2791 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2792 | Location first = locations->InAt(0); |
| 2793 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2794 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2795 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2796 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2797 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2798 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2799 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2800 | __ subl(first.AsRegister<Register>(), |
| 2801 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2802 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2803 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2804 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2805 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2809 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2810 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2811 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2812 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2813 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2814 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2815 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2816 | } else { |
| 2817 | DCHECK(second.IsConstant()) << second; |
| 2818 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2819 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2820 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2821 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2822 | break; |
| 2823 | } |
| 2824 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2825 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2826 | if (second.IsFpuRegister()) { |
| 2827 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2828 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2829 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2830 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2831 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2832 | codegen_->LiteralFloatAddress( |
| 2833 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2834 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2835 | } else { |
| 2836 | DCHECK(second.IsStackSlot()); |
| 2837 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2838 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2839 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2843 | if (second.IsFpuRegister()) { |
| 2844 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2845 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2846 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2847 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2848 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2849 | codegen_->LiteralDoubleAddress( |
| 2850 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2851 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2852 | } else { |
| 2853 | DCHECK(second.IsDoubleStackSlot()); |
| 2854 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2855 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2856 | break; |
| 2857 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2858 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2859 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2860 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2864 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2865 | LocationSummary* locations = |
| 2866 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2867 | switch (mul->GetResultType()) { |
| 2868 | case Primitive::kPrimInt: |
| 2869 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2870 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2871 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2872 | // Can use 3 operand multiply. |
| 2873 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2874 | } else { |
| 2875 | locations->SetOut(Location::SameAsFirstInput()); |
| 2876 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2877 | break; |
| 2878 | case Primitive::kPrimLong: { |
| 2879 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2880 | locations->SetInAt(1, Location::Any()); |
| 2881 | locations->SetOut(Location::SameAsFirstInput()); |
| 2882 | // Needed for imul on 32bits with 64bits output. |
| 2883 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2884 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2885 | break; |
| 2886 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2887 | case Primitive::kPrimFloat: |
| 2888 | case Primitive::kPrimDouble: { |
| 2889 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 2890 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2891 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
| 2892 | } else { |
| 2893 | locations->SetInAt(1, Location::Any()); |
| 2894 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2895 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2896 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2897 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2898 | |
| 2899 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2900 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2905 | LocationSummary* locations = mul->GetLocations(); |
| 2906 | Location first = locations->InAt(0); |
| 2907 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2908 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2909 | |
| 2910 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2911 | case Primitive::kPrimInt: |
| 2912 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2913 | // problems where the output may not be the same as the first operand. |
| 2914 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2915 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2916 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2917 | } else if (second.IsRegister()) { |
| 2918 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2919 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2920 | } else { |
| 2921 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2922 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2923 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2924 | } |
| 2925 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2926 | |
| 2927 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2928 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2929 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2930 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2931 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2932 | |
| 2933 | DCHECK_EQ(EAX, eax); |
| 2934 | DCHECK_EQ(EDX, edx); |
| 2935 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2936 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2937 | // output: in1 |
| 2938 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2939 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2940 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2941 | if (second.IsConstant()) { |
| 2942 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2943 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2944 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2945 | int32_t low_value = Low32Bits(value); |
| 2946 | int32_t high_value = High32Bits(value); |
| 2947 | Immediate low(low_value); |
| 2948 | Immediate high(high_value); |
| 2949 | |
| 2950 | __ movl(eax, high); |
| 2951 | // eax <- in1.lo * in2.hi |
| 2952 | __ imull(eax, in1_lo); |
| 2953 | // in1.hi <- in1.hi * in2.lo |
| 2954 | __ imull(in1_hi, low); |
| 2955 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2956 | __ addl(in1_hi, eax); |
| 2957 | // move in2_lo to eax to prepare for double precision |
| 2958 | __ movl(eax, low); |
| 2959 | // edx:eax <- in1.lo * in2.lo |
| 2960 | __ mull(in1_lo); |
| 2961 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2962 | __ addl(in1_hi, edx); |
| 2963 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2964 | __ movl(in1_lo, eax); |
| 2965 | } else if (second.IsRegisterPair()) { |
| 2966 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2967 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2968 | |
| 2969 | __ movl(eax, in2_hi); |
| 2970 | // eax <- in1.lo * in2.hi |
| 2971 | __ imull(eax, in1_lo); |
| 2972 | // in1.hi <- in1.hi * in2.lo |
| 2973 | __ imull(in1_hi, in2_lo); |
| 2974 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2975 | __ addl(in1_hi, eax); |
| 2976 | // move in1_lo to eax to prepare for double precision |
| 2977 | __ movl(eax, in1_lo); |
| 2978 | // edx:eax <- in1.lo * in2.lo |
| 2979 | __ mull(in2_lo); |
| 2980 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2981 | __ addl(in1_hi, edx); |
| 2982 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2983 | __ movl(in1_lo, eax); |
| 2984 | } else { |
| 2985 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2986 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2987 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2988 | |
| 2989 | __ movl(eax, in2_hi); |
| 2990 | // eax <- in1.lo * in2.hi |
| 2991 | __ imull(eax, in1_lo); |
| 2992 | // in1.hi <- in1.hi * in2.lo |
| 2993 | __ imull(in1_hi, in2_lo); |
| 2994 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2995 | __ addl(in1_hi, eax); |
| 2996 | // move in1_lo to eax to prepare for double precision |
| 2997 | __ movl(eax, in1_lo); |
| 2998 | // edx:eax <- in1.lo * in2.lo |
| 2999 | __ mull(in2_lo); |
| 3000 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3001 | __ addl(in1_hi, edx); |
| 3002 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3003 | __ movl(in1_lo, eax); |
| 3004 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3005 | |
| 3006 | break; |
| 3007 | } |
| 3008 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3009 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3010 | DCHECK(first.Equals(locations->Out())); |
| 3011 | if (second.IsFpuRegister()) { |
| 3012 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3013 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3014 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 3015 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3016 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3017 | codegen_->LiteralFloatAddress( |
| 3018 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3019 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3020 | } else { |
| 3021 | DCHECK(second.IsStackSlot()); |
| 3022 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3023 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3024 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3028 | DCHECK(first.Equals(locations->Out())); |
| 3029 | if (second.IsFpuRegister()) { |
| 3030 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3031 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3032 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 3033 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3034 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3035 | codegen_->LiteralDoubleAddress( |
| 3036 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3037 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3038 | } else { |
| 3039 | DCHECK(second.IsDoubleStackSlot()); |
| 3040 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3041 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3042 | break; |
| 3043 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3044 | |
| 3045 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3046 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3047 | } |
| 3048 | } |
| 3049 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3050 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3051 | uint32_t temp_offset, |
| 3052 | uint32_t stack_adjustment, |
| 3053 | bool is_fp, |
| 3054 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3055 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3056 | DCHECK(!is_wide); |
| 3057 | if (is_fp) { |
| 3058 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3059 | } else { |
| 3060 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3061 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3062 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3063 | DCHECK(is_wide); |
| 3064 | if (is_fp) { |
| 3065 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3066 | } else { |
| 3067 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3068 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3069 | } else { |
| 3070 | // 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] | 3071 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3072 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3073 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3074 | if (is_fp) { |
| 3075 | __ flds(Address(ESP, temp_offset)); |
| 3076 | } else { |
| 3077 | __ filds(Address(ESP, temp_offset)); |
| 3078 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3079 | } else { |
| 3080 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3081 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3082 | if (is_fp) { |
| 3083 | __ fldl(Address(ESP, temp_offset)); |
| 3084 | } else { |
| 3085 | __ fildl(Address(ESP, temp_offset)); |
| 3086 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3087 | } |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3092 | Primitive::Type type = rem->GetResultType(); |
| 3093 | bool is_float = type == Primitive::kPrimFloat; |
| 3094 | size_t elem_size = Primitive::ComponentSize(type); |
| 3095 | LocationSummary* locations = rem->GetLocations(); |
| 3096 | Location first = locations->InAt(0); |
| 3097 | Location second = locations->InAt(1); |
| 3098 | Location out = locations->Out(); |
| 3099 | |
| 3100 | // Create stack space for 2 elements. |
| 3101 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3102 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3103 | |
| 3104 | // 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] | 3105 | const bool is_wide = !is_float; |
| 3106 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3107 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3108 | |
| 3109 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3110 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3111 | __ Bind(&retry); |
| 3112 | __ fprem(); |
| 3113 | |
| 3114 | // Move FP status to AX. |
| 3115 | __ fstsw(); |
| 3116 | |
| 3117 | // And see if the argument reduction is complete. This is signaled by the |
| 3118 | // C2 FPU flag bit set to 0. |
| 3119 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3120 | __ j(kNotEqual, &retry); |
| 3121 | |
| 3122 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3123 | // Store FP top of stack to real stack. |
| 3124 | if (is_float) { |
| 3125 | __ fsts(Address(ESP, 0)); |
| 3126 | } else { |
| 3127 | __ fstl(Address(ESP, 0)); |
| 3128 | } |
| 3129 | |
| 3130 | // Pop the 2 items from the FP stack. |
| 3131 | __ fucompp(); |
| 3132 | |
| 3133 | // Load the value from the stack into an XMM register. |
| 3134 | DCHECK(out.IsFpuRegister()) << out; |
| 3135 | if (is_float) { |
| 3136 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3137 | } else { |
| 3138 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3139 | } |
| 3140 | |
| 3141 | // And remove the temporary stack space we allocated. |
| 3142 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3143 | } |
| 3144 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3145 | |
| 3146 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3147 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3148 | |
| 3149 | LocationSummary* locations = instruction->GetLocations(); |
| 3150 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3151 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3152 | |
| 3153 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3154 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3155 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3156 | |
| 3157 | DCHECK(imm == 1 || imm == -1); |
| 3158 | |
| 3159 | if (instruction->IsRem()) { |
| 3160 | __ xorl(out_register, out_register); |
| 3161 | } else { |
| 3162 | __ movl(out_register, input_register); |
| 3163 | if (imm == -1) { |
| 3164 | __ negl(out_register); |
| 3165 | } |
| 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3170 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3171 | LocationSummary* locations = instruction->GetLocations(); |
| 3172 | |
| 3173 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3174 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3175 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3176 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3177 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3178 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3179 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3180 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3181 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3182 | __ testl(input_register, input_register); |
| 3183 | __ cmovl(kGreaterEqual, num, input_register); |
| 3184 | int shift = CTZ(imm); |
| 3185 | __ sarl(num, Immediate(shift)); |
| 3186 | |
| 3187 | if (imm < 0) { |
| 3188 | __ negl(num); |
| 3189 | } |
| 3190 | |
| 3191 | __ movl(out_register, num); |
| 3192 | } |
| 3193 | |
| 3194 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3195 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3196 | |
| 3197 | LocationSummary* locations = instruction->GetLocations(); |
| 3198 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3199 | |
| 3200 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3201 | Register out = locations->Out().AsRegister<Register>(); |
| 3202 | Register num; |
| 3203 | Register edx; |
| 3204 | |
| 3205 | if (instruction->IsDiv()) { |
| 3206 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3207 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3208 | } else { |
| 3209 | edx = locations->Out().AsRegister<Register>(); |
| 3210 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3211 | } |
| 3212 | |
| 3213 | DCHECK_EQ(EAX, eax); |
| 3214 | DCHECK_EQ(EDX, edx); |
| 3215 | if (instruction->IsDiv()) { |
| 3216 | DCHECK_EQ(EAX, out); |
| 3217 | } else { |
| 3218 | DCHECK_EQ(EDX, out); |
| 3219 | } |
| 3220 | |
| 3221 | int64_t magic; |
| 3222 | int shift; |
| 3223 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3224 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3225 | NearLabel ndiv; |
| 3226 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3227 | // If numerator is 0, the result is 0, no computation needed. |
| 3228 | __ testl(eax, eax); |
| 3229 | __ j(kNotEqual, &ndiv); |
| 3230 | |
| 3231 | __ xorl(out, out); |
| 3232 | __ jmp(&end); |
| 3233 | |
| 3234 | __ Bind(&ndiv); |
| 3235 | |
| 3236 | // Save the numerator. |
| 3237 | __ movl(num, eax); |
| 3238 | |
| 3239 | // EAX = magic |
| 3240 | __ movl(eax, Immediate(magic)); |
| 3241 | |
| 3242 | // EDX:EAX = magic * numerator |
| 3243 | __ imull(num); |
| 3244 | |
| 3245 | if (imm > 0 && magic < 0) { |
| 3246 | // EDX += num |
| 3247 | __ addl(edx, num); |
| 3248 | } else if (imm < 0 && magic > 0) { |
| 3249 | __ subl(edx, num); |
| 3250 | } |
| 3251 | |
| 3252 | // Shift if needed. |
| 3253 | if (shift != 0) { |
| 3254 | __ sarl(edx, Immediate(shift)); |
| 3255 | } |
| 3256 | |
| 3257 | // EDX += 1 if EDX < 0 |
| 3258 | __ movl(eax, edx); |
| 3259 | __ shrl(edx, Immediate(31)); |
| 3260 | __ addl(edx, eax); |
| 3261 | |
| 3262 | if (instruction->IsRem()) { |
| 3263 | __ movl(eax, num); |
| 3264 | __ imull(edx, Immediate(imm)); |
| 3265 | __ subl(eax, edx); |
| 3266 | __ movl(edx, eax); |
| 3267 | } else { |
| 3268 | __ movl(eax, edx); |
| 3269 | } |
| 3270 | __ Bind(&end); |
| 3271 | } |
| 3272 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3273 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3274 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3275 | |
| 3276 | LocationSummary* locations = instruction->GetLocations(); |
| 3277 | Location out = locations->Out(); |
| 3278 | Location first = locations->InAt(0); |
| 3279 | Location second = locations->InAt(1); |
| 3280 | bool is_div = instruction->IsDiv(); |
| 3281 | |
| 3282 | switch (instruction->GetResultType()) { |
| 3283 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3284 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3285 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3286 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3287 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3288 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3289 | |
| 3290 | if (imm == 0) { |
| 3291 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3292 | } else if (imm == 1 || imm == -1) { |
| 3293 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3294 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3295 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3296 | } else { |
| 3297 | DCHECK(imm <= -2 || imm >= 2); |
| 3298 | GenerateDivRemWithAnyConstant(instruction); |
| 3299 | } |
| 3300 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3301 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3302 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3303 | is_div); |
| 3304 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3305 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3306 | Register second_reg = second.AsRegister<Register>(); |
| 3307 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3308 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3309 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3310 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3311 | __ cmpl(second_reg, Immediate(-1)); |
| 3312 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3313 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3314 | // edx:eax <- sign-extended of eax |
| 3315 | __ cdq(); |
| 3316 | // eax = quotient, edx = remainder |
| 3317 | __ idivl(second_reg); |
| 3318 | __ Bind(slow_path->GetExitLabel()); |
| 3319 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3320 | break; |
| 3321 | } |
| 3322 | |
| 3323 | case Primitive::kPrimLong: { |
| 3324 | InvokeRuntimeCallingConvention calling_convention; |
| 3325 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3326 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3327 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3328 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3329 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3330 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3331 | |
| 3332 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3333 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3334 | instruction, |
| 3335 | instruction->GetDexPc(), |
| 3336 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3337 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3338 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3339 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3340 | instruction, |
| 3341 | instruction->GetDexPc(), |
| 3342 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3343 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3344 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3345 | break; |
| 3346 | } |
| 3347 | |
| 3348 | default: |
| 3349 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3350 | } |
| 3351 | } |
| 3352 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3353 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3354 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3355 | ? LocationSummary::kCall |
| 3356 | : LocationSummary::kNoCall; |
| 3357 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3358 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3359 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3360 | case Primitive::kPrimInt: { |
| 3361 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3362 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3363 | locations->SetOut(Location::SameAsFirstInput()); |
| 3364 | // Intel uses edx:eax as the dividend. |
| 3365 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3366 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3367 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3368 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3369 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3370 | locations->AddTemp(Location::RequiresRegister()); |
| 3371 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3372 | break; |
| 3373 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3374 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3375 | InvokeRuntimeCallingConvention calling_convention; |
| 3376 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3377 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3378 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3379 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3380 | // Runtime helper puts the result in EAX, EDX. |
| 3381 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3382 | break; |
| 3383 | } |
| 3384 | case Primitive::kPrimFloat: |
| 3385 | case Primitive::kPrimDouble: { |
| 3386 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 3387 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3388 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
| 3389 | } else { |
| 3390 | locations->SetInAt(1, Location::Any()); |
| 3391 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3392 | locations->SetOut(Location::SameAsFirstInput()); |
| 3393 | break; |
| 3394 | } |
| 3395 | |
| 3396 | default: |
| 3397 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3402 | LocationSummary* locations = div->GetLocations(); |
| 3403 | Location first = locations->InAt(0); |
| 3404 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3405 | |
| 3406 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3407 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3408 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3409 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3410 | break; |
| 3411 | } |
| 3412 | |
| 3413 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3414 | if (second.IsFpuRegister()) { |
| 3415 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3416 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3417 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 3418 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3419 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3420 | codegen_->LiteralFloatAddress( |
| 3421 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3422 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3423 | } else { |
| 3424 | DCHECK(second.IsStackSlot()); |
| 3425 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3426 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3427 | break; |
| 3428 | } |
| 3429 | |
| 3430 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3431 | if (second.IsFpuRegister()) { |
| 3432 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3433 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3434 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 3435 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3436 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3437 | codegen_->LiteralDoubleAddress( |
| 3438 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3439 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3440 | } else { |
| 3441 | DCHECK(second.IsDoubleStackSlot()); |
| 3442 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3443 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3444 | break; |
| 3445 | } |
| 3446 | |
| 3447 | default: |
| 3448 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3449 | } |
| 3450 | } |
| 3451 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3452 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3453 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3454 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3455 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3456 | ? LocationSummary::kCall |
| 3457 | : LocationSummary::kNoCall; |
| 3458 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3459 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3460 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3461 | case Primitive::kPrimInt: { |
| 3462 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3463 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3464 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3465 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3466 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3467 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3468 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3469 | locations->AddTemp(Location::RequiresRegister()); |
| 3470 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| 3473 | case Primitive::kPrimLong: { |
| 3474 | InvokeRuntimeCallingConvention calling_convention; |
| 3475 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3476 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3477 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3478 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3479 | // Runtime helper puts the result in EAX, EDX. |
| 3480 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3481 | break; |
| 3482 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3483 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3484 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3485 | locations->SetInAt(0, Location::Any()); |
| 3486 | locations->SetInAt(1, Location::Any()); |
| 3487 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3488 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3489 | break; |
| 3490 | } |
| 3491 | |
| 3492 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3493 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3498 | Primitive::Type type = rem->GetResultType(); |
| 3499 | switch (type) { |
| 3500 | case Primitive::kPrimInt: |
| 3501 | case Primitive::kPrimLong: { |
| 3502 | GenerateDivRemIntegral(rem); |
| 3503 | break; |
| 3504 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3505 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3506 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3507 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3508 | break; |
| 3509 | } |
| 3510 | default: |
| 3511 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3512 | } |
| 3513 | } |
| 3514 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3515 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3516 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3517 | ? LocationSummary::kCallOnSlowPath |
| 3518 | : LocationSummary::kNoCall; |
| 3519 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3520 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3521 | case Primitive::kPrimByte: |
| 3522 | case Primitive::kPrimChar: |
| 3523 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3524 | case Primitive::kPrimInt: { |
| 3525 | locations->SetInAt(0, Location::Any()); |
| 3526 | break; |
| 3527 | } |
| 3528 | case Primitive::kPrimLong: { |
| 3529 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3530 | if (!instruction->IsConstant()) { |
| 3531 | locations->AddTemp(Location::RequiresRegister()); |
| 3532 | } |
| 3533 | break; |
| 3534 | } |
| 3535 | default: |
| 3536 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3537 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3538 | if (instruction->HasUses()) { |
| 3539 | locations->SetOut(Location::SameAsFirstInput()); |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3544 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3545 | codegen_->AddSlowPath(slow_path); |
| 3546 | |
| 3547 | LocationSummary* locations = instruction->GetLocations(); |
| 3548 | Location value = locations->InAt(0); |
| 3549 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3550 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3551 | case Primitive::kPrimByte: |
| 3552 | case Primitive::kPrimChar: |
| 3553 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3554 | case Primitive::kPrimInt: { |
| 3555 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3556 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3557 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3558 | } else if (value.IsStackSlot()) { |
| 3559 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3560 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3561 | } else { |
| 3562 | DCHECK(value.IsConstant()) << value; |
| 3563 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3564 | __ jmp(slow_path->GetEntryLabel()); |
| 3565 | } |
| 3566 | } |
| 3567 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3568 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3569 | case Primitive::kPrimLong: { |
| 3570 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3571 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3572 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3573 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3574 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3575 | } else { |
| 3576 | DCHECK(value.IsConstant()) << value; |
| 3577 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3578 | __ jmp(slow_path->GetEntryLabel()); |
| 3579 | } |
| 3580 | } |
| 3581 | break; |
| 3582 | } |
| 3583 | default: |
| 3584 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3585 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3586 | } |
| 3587 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3588 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3589 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3590 | |
| 3591 | LocationSummary* locations = |
| 3592 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3593 | |
| 3594 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3595 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3596 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3597 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3598 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3599 | // The shift count needs to be in CL or a constant. |
| 3600 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3601 | locations->SetOut(Location::SameAsFirstInput()); |
| 3602 | break; |
| 3603 | } |
| 3604 | default: |
| 3605 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3610 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3611 | |
| 3612 | LocationSummary* locations = op->GetLocations(); |
| 3613 | Location first = locations->InAt(0); |
| 3614 | Location second = locations->InAt(1); |
| 3615 | DCHECK(first.Equals(locations->Out())); |
| 3616 | |
| 3617 | switch (op->GetResultType()) { |
| 3618 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3619 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3620 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3621 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3622 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3623 | DCHECK_EQ(ECX, second_reg); |
| 3624 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3625 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3626 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3627 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3628 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3629 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3630 | } |
| 3631 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3632 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3633 | if (shift == 0) { |
| 3634 | return; |
| 3635 | } |
| 3636 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3637 | if (op->IsShl()) { |
| 3638 | __ shll(first_reg, imm); |
| 3639 | } else if (op->IsShr()) { |
| 3640 | __ sarl(first_reg, imm); |
| 3641 | } else { |
| 3642 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3643 | } |
| 3644 | } |
| 3645 | break; |
| 3646 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3647 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3648 | if (second.IsRegister()) { |
| 3649 | Register second_reg = second.AsRegister<Register>(); |
| 3650 | DCHECK_EQ(ECX, second_reg); |
| 3651 | if (op->IsShl()) { |
| 3652 | GenerateShlLong(first, second_reg); |
| 3653 | } else if (op->IsShr()) { |
| 3654 | GenerateShrLong(first, second_reg); |
| 3655 | } else { |
| 3656 | GenerateUShrLong(first, second_reg); |
| 3657 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3658 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3659 | // Shift by a constant. |
| 3660 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3661 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3662 | if (shift != 0) { |
| 3663 | if (op->IsShl()) { |
| 3664 | GenerateShlLong(first, shift); |
| 3665 | } else if (op->IsShr()) { |
| 3666 | GenerateShrLong(first, shift); |
| 3667 | } else { |
| 3668 | GenerateUShrLong(first, shift); |
| 3669 | } |
| 3670 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3671 | } |
| 3672 | break; |
| 3673 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3674 | default: |
| 3675 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3676 | } |
| 3677 | } |
| 3678 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3679 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3680 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3681 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3682 | if (shift == 1) { |
| 3683 | // This is just an addition. |
| 3684 | __ addl(low, low); |
| 3685 | __ adcl(high, high); |
| 3686 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3687 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3688 | codegen_->EmitParallelMoves( |
| 3689 | loc.ToLow(), |
| 3690 | loc.ToHigh(), |
| 3691 | Primitive::kPrimInt, |
| 3692 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3693 | loc.ToLow(), |
| 3694 | Primitive::kPrimInt); |
| 3695 | } else if (shift > 32) { |
| 3696 | // Low part becomes 0. High part is low part << (shift-32). |
| 3697 | __ movl(high, low); |
| 3698 | __ shll(high, Immediate(shift - 32)); |
| 3699 | __ xorl(low, low); |
| 3700 | } else { |
| 3701 | // Between 1 and 31. |
| 3702 | __ shld(high, low, Immediate(shift)); |
| 3703 | __ shll(low, Immediate(shift)); |
| 3704 | } |
| 3705 | } |
| 3706 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3707 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3708 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3709 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3710 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3711 | __ testl(shifter, Immediate(32)); |
| 3712 | __ j(kEqual, &done); |
| 3713 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3714 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3715 | __ Bind(&done); |
| 3716 | } |
| 3717 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3718 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3719 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3720 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3721 | if (shift == 32) { |
| 3722 | // Need to copy the sign. |
| 3723 | DCHECK_NE(low, high); |
| 3724 | __ movl(low, high); |
| 3725 | __ sarl(high, Immediate(31)); |
| 3726 | } else if (shift > 32) { |
| 3727 | DCHECK_NE(low, high); |
| 3728 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3729 | __ movl(low, high); |
| 3730 | __ sarl(high, Immediate(31)); |
| 3731 | __ sarl(low, Immediate(shift - 32)); |
| 3732 | } else { |
| 3733 | // Between 1 and 31. |
| 3734 | __ shrd(low, high, Immediate(shift)); |
| 3735 | __ sarl(high, Immediate(shift)); |
| 3736 | } |
| 3737 | } |
| 3738 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3739 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3740 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3741 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3742 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3743 | __ testl(shifter, Immediate(32)); |
| 3744 | __ j(kEqual, &done); |
| 3745 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3746 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3747 | __ Bind(&done); |
| 3748 | } |
| 3749 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3750 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3751 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3752 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3753 | if (shift == 32) { |
| 3754 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3755 | codegen_->EmitParallelMoves( |
| 3756 | loc.ToHigh(), |
| 3757 | loc.ToLow(), |
| 3758 | Primitive::kPrimInt, |
| 3759 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3760 | loc.ToHigh(), |
| 3761 | Primitive::kPrimInt); |
| 3762 | } else if (shift > 32) { |
| 3763 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3764 | __ movl(low, high); |
| 3765 | __ shrl(low, Immediate(shift - 32)); |
| 3766 | __ xorl(high, high); |
| 3767 | } else { |
| 3768 | // Between 1 and 31. |
| 3769 | __ shrd(low, high, Immediate(shift)); |
| 3770 | __ shrl(high, Immediate(shift)); |
| 3771 | } |
| 3772 | } |
| 3773 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3774 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3775 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3776 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3777 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3778 | __ testl(shifter, Immediate(32)); |
| 3779 | __ j(kEqual, &done); |
| 3780 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3781 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3782 | __ Bind(&done); |
| 3783 | } |
| 3784 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3785 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3786 | LocationSummary* locations = |
| 3787 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3788 | |
| 3789 | switch (ror->GetResultType()) { |
| 3790 | case Primitive::kPrimLong: |
| 3791 | // Add the temporary needed. |
| 3792 | locations->AddTemp(Location::RequiresRegister()); |
| 3793 | FALLTHROUGH_INTENDED; |
| 3794 | case Primitive::kPrimInt: |
| 3795 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3796 | // The shift count needs to be in CL (unless it is a constant). |
| 3797 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3798 | locations->SetOut(Location::SameAsFirstInput()); |
| 3799 | break; |
| 3800 | default: |
| 3801 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3802 | UNREACHABLE(); |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3807 | LocationSummary* locations = ror->GetLocations(); |
| 3808 | Location first = locations->InAt(0); |
| 3809 | Location second = locations->InAt(1); |
| 3810 | |
| 3811 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3812 | Register first_reg = first.AsRegister<Register>(); |
| 3813 | if (second.IsRegister()) { |
| 3814 | Register second_reg = second.AsRegister<Register>(); |
| 3815 | __ rorl(first_reg, second_reg); |
| 3816 | } else { |
| 3817 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3818 | __ rorl(first_reg, imm); |
| 3819 | } |
| 3820 | return; |
| 3821 | } |
| 3822 | |
| 3823 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3824 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3825 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3826 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3827 | if (second.IsRegister()) { |
| 3828 | Register second_reg = second.AsRegister<Register>(); |
| 3829 | DCHECK_EQ(second_reg, ECX); |
| 3830 | __ movl(temp_reg, first_reg_hi); |
| 3831 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3832 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3833 | __ movl(temp_reg, first_reg_hi); |
| 3834 | __ testl(second_reg, Immediate(32)); |
| 3835 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3836 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3837 | } else { |
| 3838 | int32_t shift_amt = |
| 3839 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3840 | if (shift_amt == 0) { |
| 3841 | // Already fine. |
| 3842 | return; |
| 3843 | } |
| 3844 | if (shift_amt == 32) { |
| 3845 | // Just swap. |
| 3846 | __ movl(temp_reg, first_reg_lo); |
| 3847 | __ movl(first_reg_lo, first_reg_hi); |
| 3848 | __ movl(first_reg_hi, temp_reg); |
| 3849 | return; |
| 3850 | } |
| 3851 | |
| 3852 | Immediate imm(shift_amt); |
| 3853 | // Save the constents of the low value. |
| 3854 | __ movl(temp_reg, first_reg_lo); |
| 3855 | |
| 3856 | // Shift right into low, feeding bits from high. |
| 3857 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3858 | |
| 3859 | // Shift right into high, feeding bits from the original low. |
| 3860 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3861 | |
| 3862 | // Swap if needed. |
| 3863 | if (shift_amt > 32) { |
| 3864 | __ movl(temp_reg, first_reg_lo); |
| 3865 | __ movl(first_reg_lo, first_reg_hi); |
| 3866 | __ movl(first_reg_hi, temp_reg); |
| 3867 | } |
| 3868 | } |
| 3869 | } |
| 3870 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3871 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3872 | HandleShift(shl); |
| 3873 | } |
| 3874 | |
| 3875 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3876 | HandleShift(shl); |
| 3877 | } |
| 3878 | |
| 3879 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3880 | HandleShift(shr); |
| 3881 | } |
| 3882 | |
| 3883 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3884 | HandleShift(shr); |
| 3885 | } |
| 3886 | |
| 3887 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3888 | HandleShift(ushr); |
| 3889 | } |
| 3890 | |
| 3891 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3892 | HandleShift(ushr); |
| 3893 | } |
| 3894 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3895 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3896 | LocationSummary* locations = |
| 3897 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3898 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3899 | if (instruction->IsStringAlloc()) { |
| 3900 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3901 | } else { |
| 3902 | InvokeRuntimeCallingConvention calling_convention; |
| 3903 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3904 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3905 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3909 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3910 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3911 | if (instruction->IsStringAlloc()) { |
| 3912 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3913 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3914 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3915 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3916 | __ call(Address(temp, code_offset.Int32Value())); |
| 3917 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3918 | } else { |
| 3919 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3920 | instruction, |
| 3921 | instruction->GetDexPc(), |
| 3922 | nullptr); |
| 3923 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3924 | DCHECK(!codegen_->IsLeafMethod()); |
| 3925 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3926 | } |
| 3927 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3928 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3929 | LocationSummary* locations = |
| 3930 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3931 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3932 | InvokeRuntimeCallingConvention calling_convention; |
| 3933 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3934 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3935 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3936 | } |
| 3937 | |
| 3938 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3939 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3940 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3941 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3942 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3943 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3944 | instruction, |
| 3945 | instruction->GetDexPc(), |
| 3946 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3947 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3948 | DCHECK(!codegen_->IsLeafMethod()); |
| 3949 | } |
| 3950 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3951 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3952 | LocationSummary* locations = |
| 3953 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3954 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3955 | if (location.IsStackSlot()) { |
| 3956 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3957 | } else if (location.IsDoubleStackSlot()) { |
| 3958 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3959 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3960 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3961 | } |
| 3962 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3963 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3964 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3965 | } |
| 3966 | |
| 3967 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3968 | LocationSummary* locations = |
| 3969 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3970 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3971 | } |
| 3972 | |
| 3973 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3974 | } |
| 3975 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3976 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3977 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3978 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3979 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3980 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3981 | } |
| 3982 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3983 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3984 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3985 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3986 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3987 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3988 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3989 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3990 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3991 | break; |
| 3992 | |
| 3993 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3994 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3995 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3996 | break; |
| 3997 | |
| 3998 | default: |
| 3999 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4000 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4001 | } |
| 4002 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4003 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4004 | LocationSummary* locations = |
| 4005 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4007 | locations->SetOut(Location::SameAsFirstInput()); |
| 4008 | } |
| 4009 | |
| 4010 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4011 | LocationSummary* locations = bool_not->GetLocations(); |
| 4012 | Location in = locations->InAt(0); |
| 4013 | Location out = locations->Out(); |
| 4014 | DCHECK(in.Equals(out)); |
| 4015 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4016 | } |
| 4017 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4018 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4019 | LocationSummary* locations = |
| 4020 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4021 | switch (compare->InputAt(0)->GetType()) { |
| 4022 | case Primitive::kPrimLong: { |
| 4023 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4024 | locations->SetInAt(1, Location::Any()); |
| 4025 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4026 | break; |
| 4027 | } |
| 4028 | case Primitive::kPrimFloat: |
| 4029 | case Primitive::kPrimDouble: { |
| 4030 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 4031 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4032 | locations->SetOut(Location::RequiresRegister()); |
| 4033 | break; |
| 4034 | } |
| 4035 | default: |
| 4036 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4037 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4038 | } |
| 4039 | |
| 4040 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4041 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4042 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4043 | Location left = locations->InAt(0); |
| 4044 | Location right = locations->InAt(1); |
| 4045 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4046 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4047 | switch (compare->InputAt(0)->GetType()) { |
| 4048 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4049 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4050 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4051 | int32_t val_low = 0; |
| 4052 | int32_t val_high = 0; |
| 4053 | bool right_is_const = false; |
| 4054 | |
| 4055 | if (right.IsConstant()) { |
| 4056 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4057 | right_is_const = true; |
| 4058 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4059 | val_low = Low32Bits(val); |
| 4060 | val_high = High32Bits(val); |
| 4061 | } |
| 4062 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4063 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4064 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4065 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4066 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4067 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4068 | DCHECK(right_is_const) << right; |
| 4069 | if (val_high == 0) { |
| 4070 | __ testl(left_high, left_high); |
| 4071 | } else { |
| 4072 | __ cmpl(left_high, Immediate(val_high)); |
| 4073 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4074 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4075 | __ j(kLess, &less); // Signed compare. |
| 4076 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4077 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4078 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4079 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4080 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4081 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4082 | DCHECK(right_is_const) << right; |
| 4083 | if (val_low == 0) { |
| 4084 | __ testl(left_low, left_low); |
| 4085 | } else { |
| 4086 | __ cmpl(left_low, Immediate(val_low)); |
| 4087 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4088 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4089 | break; |
| 4090 | } |
| 4091 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 4092 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4093 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4094 | break; |
| 4095 | } |
| 4096 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | cf8d1bb | 2016-01-25 09:43:30 +0000 | [diff] [blame] | 4097 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4098 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4099 | break; |
| 4100 | } |
| 4101 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4102 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4103 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4104 | __ movl(out, Immediate(0)); |
| 4105 | __ j(kEqual, &done); |
| 4106 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4107 | |
| 4108 | __ Bind(&greater); |
| 4109 | __ movl(out, Immediate(1)); |
| 4110 | __ jmp(&done); |
| 4111 | |
| 4112 | __ Bind(&less); |
| 4113 | __ movl(out, Immediate(-1)); |
| 4114 | |
| 4115 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4118 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4119 | LocationSummary* locations = |
| 4120 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4121 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4122 | locations->SetInAt(i, Location::Any()); |
| 4123 | } |
| 4124 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4127 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4128 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4129 | } |
| 4130 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4131 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4132 | /* |
| 4133 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4134 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4135 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4136 | */ |
| 4137 | switch (kind) { |
| 4138 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4139 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4140 | break; |
| 4141 | } |
| 4142 | case MemBarrierKind::kAnyStore: |
| 4143 | case MemBarrierKind::kLoadAny: |
| 4144 | case MemBarrierKind::kStoreStore: { |
| 4145 | // nop |
| 4146 | break; |
| 4147 | } |
| 4148 | default: |
| 4149 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4150 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4151 | } |
| 4152 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4153 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4154 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4155 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4156 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4157 | |
| 4158 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4159 | // is incompatible with it. |
| 4160 | if (GetGraph()->HasIrreducibleLoops() && |
| 4161 | (dispatch_info.method_load_kind == |
| 4162 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4163 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4164 | } |
| 4165 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4166 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4167 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4168 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4169 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4170 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4171 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4172 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4173 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4174 | 0u |
| 4175 | }; |
| 4176 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4177 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4178 | } |
| 4179 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4180 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4181 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4182 | Register temp) { |
| 4183 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4184 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4185 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4186 | return location.AsRegister<Register>(); |
| 4187 | } |
| 4188 | // For intrinsics we allow any location, so it may be on the stack. |
| 4189 | if (!location.IsRegister()) { |
| 4190 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4191 | return temp; |
| 4192 | } |
| 4193 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4194 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4195 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4196 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4197 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4198 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4199 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4200 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4201 | __ movl(temp, Address(ESP, stack_offset)); |
| 4202 | return temp; |
| 4203 | } |
| 4204 | return location.AsRegister<Register>(); |
| 4205 | } |
| 4206 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4207 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4208 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4209 | switch (invoke->GetMethodLoadKind()) { |
| 4210 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4211 | // temp = thread->string_init_entrypoint |
| 4212 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4213 | break; |
| 4214 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4215 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4216 | break; |
| 4217 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4218 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4219 | break; |
| 4220 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4221 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4222 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4223 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4224 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4225 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4226 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4227 | temp.AsRegister<Register>()); |
| 4228 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4229 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4230 | // Add the patch entry and bind its label at the end of the instruction. |
| 4231 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4232 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4233 | break; |
| 4234 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4235 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4236 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4237 | Register method_reg; |
| 4238 | Register reg = temp.AsRegister<Register>(); |
| 4239 | if (current_method.IsRegister()) { |
| 4240 | method_reg = current_method.AsRegister<Register>(); |
| 4241 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4242 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4243 | DCHECK(!current_method.IsValid()); |
| 4244 | method_reg = reg; |
| 4245 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4246 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4247 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4248 | __ movl(reg, Address(method_reg, |
| 4249 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4250 | // temp = temp[index_in_cache] |
| 4251 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4252 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4253 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4254 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | switch (invoke->GetCodePtrLocation()) { |
| 4258 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4259 | __ call(GetFrameEntryLabel()); |
| 4260 | break; |
| 4261 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4262 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4263 | Label* label = &relative_call_patches_.back().label; |
| 4264 | __ call(label); // Bind to the patch label, override at link time. |
| 4265 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4266 | break; |
| 4267 | } |
| 4268 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4269 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4270 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4271 | LOG(FATAL) << "Unsupported"; |
| 4272 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4273 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4274 | // (callee_method + offset_of_quick_compiled_code)() |
| 4275 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4276 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4277 | kX86WordSize).Int32Value())); |
| 4278 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4279 | } |
| 4280 | |
| 4281 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4282 | } |
| 4283 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4284 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4285 | Register temp = temp_in.AsRegister<Register>(); |
| 4286 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4287 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4288 | |
| 4289 | // Use the calling convention instead of the location of the receiver, as |
| 4290 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4291 | // slow path, the arguments have been moved to the right place, so here we are |
| 4292 | // guaranteed that the receiver is the first register of the calling convention. |
| 4293 | InvokeDexCallingConvention calling_convention; |
| 4294 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4295 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4296 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4297 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4298 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4299 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4300 | // emit a read barrier for the previous class reference load. |
| 4301 | // However this is not required in practice, as this is an |
| 4302 | // intermediate/temporary reference and because the current |
| 4303 | // concurrent copying collector keeps the from-space memory |
| 4304 | // intact/accessible until the end of the marking phase (the |
| 4305 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4306 | __ MaybeUnpoisonHeapReference(temp); |
| 4307 | // temp = temp->GetMethodAt(method_offset); |
| 4308 | __ movl(temp, Address(temp, method_offset)); |
| 4309 | // call temp->GetEntryPoint(); |
| 4310 | __ call(Address( |
| 4311 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4312 | } |
| 4313 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4314 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4315 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4316 | size_t size = |
| 4317 | method_patches_.size() + |
| 4318 | relative_call_patches_.size() + |
| 4319 | pc_relative_dex_cache_patches_.size(); |
| 4320 | linker_patches->reserve(size); |
| 4321 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4322 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4323 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4324 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4325 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4326 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4327 | info.target_method.dex_file, |
| 4328 | info.target_method.dex_method_index)); |
| 4329 | } |
| 4330 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4331 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4332 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4333 | info.target_method.dex_file, |
| 4334 | info.target_method.dex_method_index)); |
| 4335 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4336 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4337 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4338 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4339 | &info.target_dex_file, |
| 4340 | GetMethodAddressOffset(), |
| 4341 | info.element_offset)); |
| 4342 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4343 | } |
| 4344 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4345 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4346 | Register card, |
| 4347 | Register object, |
| 4348 | Register value, |
| 4349 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4350 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4351 | if (value_can_be_null) { |
| 4352 | __ testl(value, value); |
| 4353 | __ j(kEqual, &is_null); |
| 4354 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4355 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4356 | __ movl(temp, object); |
| 4357 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4358 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4359 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4360 | if (value_can_be_null) { |
| 4361 | __ Bind(&is_null); |
| 4362 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4363 | } |
| 4364 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4365 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4366 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4367 | |
| 4368 | bool object_field_get_with_read_barrier = |
| 4369 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4370 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4371 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4372 | kEmitCompilerReadBarrier ? |
| 4373 | LocationSummary::kCallOnSlowPath : |
| 4374 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4375 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4376 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4377 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4378 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4379 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4380 | // The output overlaps in case of long: we don't want the low move |
| 4381 | // to overwrite the object's location. Likewise, in the case of |
| 4382 | // an object field get with read barriers enabled, we do not want |
| 4383 | // the move to overwrite the object's location, as we need it to emit |
| 4384 | // the read barrier. |
| 4385 | locations->SetOut( |
| 4386 | Location::RequiresRegister(), |
| 4387 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4388 | Location::kOutputOverlap : |
| 4389 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4390 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4391 | |
| 4392 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4393 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4394 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4395 | // load the temp into the XMM and then copy the XMM into the |
| 4396 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4397 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4398 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4399 | // We need a temporary register for the read barrier marking slow |
| 4400 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4401 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4402 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4403 | } |
| 4404 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4405 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4406 | const FieldInfo& field_info) { |
| 4407 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4408 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4409 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4410 | Location base_loc = locations->InAt(0); |
| 4411 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4412 | Location out = locations->Out(); |
| 4413 | bool is_volatile = field_info.IsVolatile(); |
| 4414 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4415 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4416 | |
| 4417 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4418 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4419 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4420 | break; |
| 4421 | } |
| 4422 | |
| 4423 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4424 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4425 | break; |
| 4426 | } |
| 4427 | |
| 4428 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4429 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4430 | break; |
| 4431 | } |
| 4432 | |
| 4433 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4434 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4435 | break; |
| 4436 | } |
| 4437 | |
| 4438 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4439 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4440 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4441 | |
| 4442 | case Primitive::kPrimNot: { |
| 4443 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4444 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4445 | Location temp_loc = locations->GetTemp(0); |
| 4446 | // Note that a potential implicit null check is handled in this |
| 4447 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4448 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4449 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4450 | if (is_volatile) { |
| 4451 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4452 | } |
| 4453 | } else { |
| 4454 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4455 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4456 | if (is_volatile) { |
| 4457 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4458 | } |
| 4459 | // If read barriers are enabled, emit read barriers other than |
| 4460 | // Baker's using a slow path (and also unpoison the loaded |
| 4461 | // reference, if heap poisoning is enabled). |
| 4462 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4463 | } |
| 4464 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4468 | if (is_volatile) { |
| 4469 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4470 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4471 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4472 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4473 | __ psrlq(temp, Immediate(32)); |
| 4474 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4475 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4476 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4477 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4478 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4479 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4480 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4481 | break; |
| 4482 | } |
| 4483 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4484 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4485 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4486 | break; |
| 4487 | } |
| 4488 | |
| 4489 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4490 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4491 | break; |
| 4492 | } |
| 4493 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4494 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4495 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4496 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4497 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4498 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4499 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4500 | // Potential implicit null checks, in the case of reference or |
| 4501 | // long fields, are handled in the previous switch statement. |
| 4502 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4503 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4504 | } |
| 4505 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4506 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4507 | if (field_type == Primitive::kPrimNot) { |
| 4508 | // Memory barriers, in the case of references, are also handled |
| 4509 | // in the previous switch statement. |
| 4510 | } else { |
| 4511 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4512 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4513 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4517 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4518 | |
| 4519 | LocationSummary* locations = |
| 4520 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4521 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4522 | bool is_volatile = field_info.IsVolatile(); |
| 4523 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4524 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4525 | || (field_type == Primitive::kPrimByte); |
| 4526 | |
| 4527 | // The register allocator does not support multiple |
| 4528 | // inputs that die at entry with one in a specific register. |
| 4529 | if (is_byte_type) { |
| 4530 | // Ensure the value is in a byte register. |
| 4531 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4532 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4533 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4534 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4535 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4536 | } else { |
| 4537 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4538 | } |
| 4539 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4540 | // 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] | 4541 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4542 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4543 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4544 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4545 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4546 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4547 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4548 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4549 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4550 | } else { |
| 4551 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4552 | |
| 4553 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4554 | // Temporary registers for the write barrier. |
| 4555 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4556 | // Ensure the card is in a byte register. |
| 4557 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4558 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | } |
| 4560 | } |
| 4561 | |
| 4562 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4563 | const FieldInfo& field_info, |
| 4564 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4566 | |
| 4567 | LocationSummary* locations = instruction->GetLocations(); |
| 4568 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4569 | Location value = locations->InAt(1); |
| 4570 | bool is_volatile = field_info.IsVolatile(); |
| 4571 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4572 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4573 | bool needs_write_barrier = |
| 4574 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4575 | |
| 4576 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4577 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4580 | bool maybe_record_implicit_null_check_done = false; |
| 4581 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4582 | switch (field_type) { |
| 4583 | case Primitive::kPrimBoolean: |
| 4584 | case Primitive::kPrimByte: { |
| 4585 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4586 | break; |
| 4587 | } |
| 4588 | |
| 4589 | case Primitive::kPrimShort: |
| 4590 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4591 | if (value.IsConstant()) { |
| 4592 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4593 | __ movw(Address(base, offset), Immediate(v)); |
| 4594 | } else { |
| 4595 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4596 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4597 | break; |
| 4598 | } |
| 4599 | |
| 4600 | case Primitive::kPrimInt: |
| 4601 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4602 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4603 | // Note that in the case where `value` is a null reference, |
| 4604 | // we do not enter this block, as the reference does not |
| 4605 | // need poisoning. |
| 4606 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4607 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4608 | __ movl(temp, value.AsRegister<Register>()); |
| 4609 | __ PoisonHeapReference(temp); |
| 4610 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4611 | } else if (value.IsConstant()) { |
| 4612 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4613 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4614 | } else { |
| 4615 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4616 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | break; |
| 4618 | } |
| 4619 | |
| 4620 | case Primitive::kPrimLong: { |
| 4621 | if (is_volatile) { |
| 4622 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4623 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4624 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4625 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4626 | __ punpckldq(temp1, temp2); |
| 4627 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4628 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4629 | } else if (value.IsConstant()) { |
| 4630 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4631 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4632 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4633 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4634 | } else { |
| 4635 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4636 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4637 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4638 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4639 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4640 | break; |
| 4641 | } |
| 4642 | |
| 4643 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4644 | if (value.IsConstant()) { |
| 4645 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4646 | __ movl(Address(base, offset), Immediate(v)); |
| 4647 | } else { |
| 4648 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4649 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4650 | break; |
| 4651 | } |
| 4652 | |
| 4653 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4654 | if (value.IsConstant()) { |
| 4655 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4656 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4657 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4658 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4659 | maybe_record_implicit_null_check_done = true; |
| 4660 | } else { |
| 4661 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4662 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4663 | break; |
| 4664 | } |
| 4665 | |
| 4666 | case Primitive::kPrimVoid: |
| 4667 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4668 | UNREACHABLE(); |
| 4669 | } |
| 4670 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4671 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4672 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4673 | } |
| 4674 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4675 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4676 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4677 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4678 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4679 | } |
| 4680 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4681 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4682 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4683 | } |
| 4684 | } |
| 4685 | |
| 4686 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4687 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4688 | } |
| 4689 | |
| 4690 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4691 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4692 | } |
| 4693 | |
| 4694 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4695 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4696 | } |
| 4697 | |
| 4698 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4699 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4703 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4704 | } |
| 4705 | |
| 4706 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4707 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4711 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4712 | } |
| 4713 | |
| 4714 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4715 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4716 | } |
| 4717 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4718 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4719 | HUnresolvedInstanceFieldGet* instruction) { |
| 4720 | FieldAccessCallingConventionX86 calling_convention; |
| 4721 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4722 | instruction, instruction->GetFieldType(), calling_convention); |
| 4723 | } |
| 4724 | |
| 4725 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4726 | HUnresolvedInstanceFieldGet* instruction) { |
| 4727 | FieldAccessCallingConventionX86 calling_convention; |
| 4728 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4729 | instruction->GetFieldType(), |
| 4730 | instruction->GetFieldIndex(), |
| 4731 | instruction->GetDexPc(), |
| 4732 | calling_convention); |
| 4733 | } |
| 4734 | |
| 4735 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4736 | HUnresolvedInstanceFieldSet* instruction) { |
| 4737 | FieldAccessCallingConventionX86 calling_convention; |
| 4738 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4739 | instruction, instruction->GetFieldType(), calling_convention); |
| 4740 | } |
| 4741 | |
| 4742 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4743 | HUnresolvedInstanceFieldSet* instruction) { |
| 4744 | FieldAccessCallingConventionX86 calling_convention; |
| 4745 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4746 | instruction->GetFieldType(), |
| 4747 | instruction->GetFieldIndex(), |
| 4748 | instruction->GetDexPc(), |
| 4749 | calling_convention); |
| 4750 | } |
| 4751 | |
| 4752 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4753 | HUnresolvedStaticFieldGet* instruction) { |
| 4754 | FieldAccessCallingConventionX86 calling_convention; |
| 4755 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4756 | instruction, instruction->GetFieldType(), calling_convention); |
| 4757 | } |
| 4758 | |
| 4759 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4760 | HUnresolvedStaticFieldGet* instruction) { |
| 4761 | FieldAccessCallingConventionX86 calling_convention; |
| 4762 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4763 | instruction->GetFieldType(), |
| 4764 | instruction->GetFieldIndex(), |
| 4765 | instruction->GetDexPc(), |
| 4766 | calling_convention); |
| 4767 | } |
| 4768 | |
| 4769 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4770 | HUnresolvedStaticFieldSet* instruction) { |
| 4771 | FieldAccessCallingConventionX86 calling_convention; |
| 4772 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4773 | instruction, instruction->GetFieldType(), calling_convention); |
| 4774 | } |
| 4775 | |
| 4776 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4777 | HUnresolvedStaticFieldSet* instruction) { |
| 4778 | FieldAccessCallingConventionX86 calling_convention; |
| 4779 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4780 | instruction->GetFieldType(), |
| 4781 | instruction->GetFieldIndex(), |
| 4782 | instruction->GetDexPc(), |
| 4783 | calling_convention); |
| 4784 | } |
| 4785 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4786 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4787 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4788 | ? LocationSummary::kCallOnSlowPath |
| 4789 | : LocationSummary::kNoCall; |
| 4790 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4791 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4792 | ? Location::RequiresRegister() |
| 4793 | : Location::Any(); |
| 4794 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4795 | if (instruction->HasUses()) { |
| 4796 | locations->SetOut(Location::SameAsFirstInput()); |
| 4797 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4798 | } |
| 4799 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4800 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4801 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4802 | return; |
| 4803 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4804 | LocationSummary* locations = instruction->GetLocations(); |
| 4805 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4806 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4807 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4808 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4809 | } |
| 4810 | |
| 4811 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4812 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4813 | codegen_->AddSlowPath(slow_path); |
| 4814 | |
| 4815 | LocationSummary* locations = instruction->GetLocations(); |
| 4816 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4817 | |
| 4818 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4819 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4820 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4821 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4822 | } else { |
| 4823 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4824 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4825 | __ jmp(slow_path->GetEntryLabel()); |
| 4826 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4827 | } |
| 4828 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4829 | } |
| 4830 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4831 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4832 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4833 | GenerateImplicitNullCheck(instruction); |
| 4834 | } else { |
| 4835 | GenerateExplicitNullCheck(instruction); |
| 4836 | } |
| 4837 | } |
| 4838 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4839 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4840 | bool object_array_get_with_read_barrier = |
| 4841 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4842 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4843 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4844 | object_array_get_with_read_barrier ? |
| 4845 | LocationSummary::kCallOnSlowPath : |
| 4846 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4848 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4849 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4850 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4851 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4852 | // The output overlaps in case of long: we don't want the low move |
| 4853 | // to overwrite the array's location. Likewise, in the case of an |
| 4854 | // object array get with read barriers enabled, we do not want the |
| 4855 | // move to overwrite the array's location, as we need it to emit |
| 4856 | // the read barrier. |
| 4857 | locations->SetOut( |
| 4858 | Location::RequiresRegister(), |
| 4859 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4860 | Location::kOutputOverlap : |
| 4861 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4862 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4863 | // We need a temporary register for the read barrier marking slow |
| 4864 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4865 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4866 | locations->AddTemp(Location::RequiresRegister()); |
| 4867 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4871 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4872 | Location obj_loc = locations->InAt(0); |
| 4873 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4874 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4875 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4876 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4877 | Primitive::Type type = instruction->GetType(); |
| 4878 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4879 | case Primitive::kPrimBoolean: { |
| 4880 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4881 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4882 | if (index.IsConstant()) { |
| 4883 | __ movzxb(out, Address(obj, |
| 4884 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4885 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4886 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4887 | } |
| 4888 | break; |
| 4889 | } |
| 4890 | |
| 4891 | case Primitive::kPrimByte: { |
| 4892 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4893 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4894 | if (index.IsConstant()) { |
| 4895 | __ movsxb(out, Address(obj, |
| 4896 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4897 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4898 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4899 | } |
| 4900 | break; |
| 4901 | } |
| 4902 | |
| 4903 | case Primitive::kPrimShort: { |
| 4904 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4905 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4906 | if (index.IsConstant()) { |
| 4907 | __ movsxw(out, Address(obj, |
| 4908 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4909 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4910 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4911 | } |
| 4912 | break; |
| 4913 | } |
| 4914 | |
| 4915 | case Primitive::kPrimChar: { |
| 4916 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4917 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4918 | if (index.IsConstant()) { |
| 4919 | __ movzxw(out, Address(obj, |
| 4920 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4921 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4922 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4923 | } |
| 4924 | break; |
| 4925 | } |
| 4926 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4927 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4928 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4929 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4930 | if (index.IsConstant()) { |
| 4931 | __ movl(out, Address(obj, |
| 4932 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4933 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4934 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4935 | } |
| 4936 | break; |
| 4937 | } |
| 4938 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4939 | case Primitive::kPrimNot: { |
| 4940 | static_assert( |
| 4941 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4942 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4943 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4944 | // /* HeapReference<Object> */ out = |
| 4945 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4946 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4947 | Location temp = locations->GetTemp(0); |
| 4948 | // Note that a potential implicit null check is handled in this |
| 4949 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4950 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4951 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4952 | } else { |
| 4953 | Register out = out_loc.AsRegister<Register>(); |
| 4954 | if (index.IsConstant()) { |
| 4955 | uint32_t offset = |
| 4956 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4957 | __ movl(out, Address(obj, offset)); |
| 4958 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4959 | // If read barriers are enabled, emit read barriers other than |
| 4960 | // Baker's using a slow path (and also unpoison the loaded |
| 4961 | // reference, if heap poisoning is enabled). |
| 4962 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4963 | } else { |
| 4964 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4965 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4966 | // If read barriers are enabled, emit read barriers other than |
| 4967 | // Baker's using a slow path (and also unpoison the loaded |
| 4968 | // reference, if heap poisoning is enabled). |
| 4969 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4970 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4971 | } |
| 4972 | } |
| 4973 | break; |
| 4974 | } |
| 4975 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4976 | case Primitive::kPrimLong: { |
| 4977 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4978 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4979 | if (index.IsConstant()) { |
| 4980 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4981 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4983 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4984 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4985 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4986 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4987 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4988 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4989 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4990 | } |
| 4991 | break; |
| 4992 | } |
| 4993 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4994 | case Primitive::kPrimFloat: { |
| 4995 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4996 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4997 | if (index.IsConstant()) { |
| 4998 | __ movss(out, Address(obj, |
| 4999 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5000 | } else { |
| 5001 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5002 | } |
| 5003 | break; |
| 5004 | } |
| 5005 | |
| 5006 | case Primitive::kPrimDouble: { |
| 5007 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5008 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5009 | if (index.IsConstant()) { |
| 5010 | __ movsd(out, Address(obj, |
| 5011 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5012 | } else { |
| 5013 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5014 | } |
| 5015 | break; |
| 5016 | } |
| 5017 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5018 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5019 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5020 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5021 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5022 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5023 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5024 | // Potential implicit null checks, in the case of reference or |
| 5025 | // long arrays, are handled in the previous switch statement. |
| 5026 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5028 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5032 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5033 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5034 | bool needs_write_barrier = |
| 5035 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5036 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5037 | bool object_array_set_with_read_barrier = |
| 5038 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5039 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5040 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5041 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5042 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5043 | LocationSummary::kCallOnSlowPath : |
| 5044 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5045 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5046 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5047 | || (value_type == Primitive::kPrimByte); |
| 5048 | // We need the inputs to be different than the output in case of long operation. |
| 5049 | // In case of a byte operation, the register allocator does not support multiple |
| 5050 | // inputs that die at entry with one in a specific register. |
| 5051 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5052 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5053 | if (is_byte_type) { |
| 5054 | // Ensure the value is in a byte register. |
| 5055 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5056 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5057 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5058 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5059 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5060 | } |
| 5061 | if (needs_write_barrier) { |
| 5062 | // Temporary registers for the write barrier. |
| 5063 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5064 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5065 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5070 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5071 | Location array_loc = locations->InAt(0); |
| 5072 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5073 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5074 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5075 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5076 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5077 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5078 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5079 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5080 | bool needs_write_barrier = |
| 5081 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5082 | |
| 5083 | switch (value_type) { |
| 5084 | case Primitive::kPrimBoolean: |
| 5085 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5086 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5087 | Address address = index.IsConstant() |
| 5088 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5089 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5090 | if (value.IsRegister()) { |
| 5091 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5093 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5094 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5095 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5096 | break; |
| 5097 | } |
| 5098 | |
| 5099 | case Primitive::kPrimShort: |
| 5100 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5101 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5102 | Address address = index.IsConstant() |
| 5103 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5104 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5105 | if (value.IsRegister()) { |
| 5106 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5107 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5108 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5109 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5110 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | break; |
| 5112 | } |
| 5113 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5114 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5115 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5116 | Address address = index.IsConstant() |
| 5117 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5118 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5119 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5120 | if (!value.IsRegister()) { |
| 5121 | // Just setting null. |
| 5122 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5123 | DCHECK(value.IsConstant()) << value; |
| 5124 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5126 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5127 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5128 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5129 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5130 | |
| 5131 | DCHECK(needs_write_barrier); |
| 5132 | Register register_value = value.AsRegister<Register>(); |
| 5133 | NearLabel done, not_null, do_put; |
| 5134 | SlowPathCode* slow_path = nullptr; |
| 5135 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5136 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5137 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5138 | codegen_->AddSlowPath(slow_path); |
| 5139 | if (instruction->GetValueCanBeNull()) { |
| 5140 | __ testl(register_value, register_value); |
| 5141 | __ j(kNotEqual, ¬_null); |
| 5142 | __ movl(address, Immediate(0)); |
| 5143 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5144 | __ jmp(&done); |
| 5145 | __ Bind(¬_null); |
| 5146 | } |
| 5147 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5148 | if (kEmitCompilerReadBarrier) { |
| 5149 | // When read barriers are enabled, the type checking |
| 5150 | // instrumentation requires two read barriers: |
| 5151 | // |
| 5152 | // __ movl(temp2, temp); |
| 5153 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5154 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5155 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5156 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5157 | // |
| 5158 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5159 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5160 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5161 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5162 | // |
| 5163 | // __ cmpl(temp, temp2); |
| 5164 | // |
| 5165 | // However, the second read barrier may trash `temp`, as it |
| 5166 | // is a temporary register, and as such would not be saved |
| 5167 | // along with live registers before calling the runtime (nor |
| 5168 | // restored afterwards). So in this case, we bail out and |
| 5169 | // delegate the work to the array set slow path. |
| 5170 | // |
| 5171 | // TODO: Extend the register allocator to support a new |
| 5172 | // "(locally) live temp" location so as to avoid always |
| 5173 | // going into the slow path when read barriers are enabled. |
| 5174 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5175 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5176 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5177 | __ movl(temp, Address(array, class_offset)); |
| 5178 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5179 | __ MaybeUnpoisonHeapReference(temp); |
| 5180 | |
| 5181 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5182 | __ movl(temp, Address(temp, component_offset)); |
| 5183 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5184 | // nor the object reference in `register_value->klass`, as |
| 5185 | // we are comparing two poisoned references. |
| 5186 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5187 | |
| 5188 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5189 | __ j(kEqual, &do_put); |
| 5190 | // If heap poisoning is enabled, the `temp` reference has |
| 5191 | // not been unpoisoned yet; unpoison it now. |
| 5192 | __ MaybeUnpoisonHeapReference(temp); |
| 5193 | |
| 5194 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5195 | __ movl(temp, Address(temp, super_offset)); |
| 5196 | // If heap poisoning is enabled, no need to unpoison |
| 5197 | // `temp`, as we are comparing against null below. |
| 5198 | __ testl(temp, temp); |
| 5199 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5200 | __ Bind(&do_put); |
| 5201 | } else { |
| 5202 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5203 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | if (kPoisonHeapReferences) { |
| 5208 | __ movl(temp, register_value); |
| 5209 | __ PoisonHeapReference(temp); |
| 5210 | __ movl(address, temp); |
| 5211 | } else { |
| 5212 | __ movl(address, register_value); |
| 5213 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5214 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5215 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5216 | } |
| 5217 | |
| 5218 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5219 | codegen_->MarkGCCard( |
| 5220 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5221 | __ Bind(&done); |
| 5222 | |
| 5223 | if (slow_path != nullptr) { |
| 5224 | __ Bind(slow_path->GetExitLabel()); |
| 5225 | } |
| 5226 | |
| 5227 | break; |
| 5228 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5229 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5230 | case Primitive::kPrimInt: { |
| 5231 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5232 | Address address = index.IsConstant() |
| 5233 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5234 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5235 | if (value.IsRegister()) { |
| 5236 | __ movl(address, value.AsRegister<Register>()); |
| 5237 | } else { |
| 5238 | DCHECK(value.IsConstant()) << value; |
| 5239 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5240 | __ movl(address, Immediate(v)); |
| 5241 | } |
| 5242 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | break; |
| 5244 | } |
| 5245 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5246 | case Primitive::kPrimLong: { |
| 5247 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5248 | if (index.IsConstant()) { |
| 5249 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5250 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5251 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5252 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5253 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5254 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5255 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5256 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5257 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5258 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5259 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5260 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5261 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5262 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5263 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5264 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5265 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5266 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5267 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5268 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5269 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5270 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5271 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5272 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5273 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5274 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5275 | Immediate(High32Bits(val))); |
| 5276 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5277 | } |
| 5278 | break; |
| 5279 | } |
| 5280 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5281 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5282 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5283 | Address address = index.IsConstant() |
| 5284 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5285 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5286 | if (value.IsFpuRegister()) { |
| 5287 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5288 | } else { |
| 5289 | DCHECK(value.IsConstant()); |
| 5290 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5291 | __ movl(address, Immediate(v)); |
| 5292 | } |
| 5293 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5294 | break; |
| 5295 | } |
| 5296 | |
| 5297 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5298 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5299 | Address address = index.IsConstant() |
| 5300 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5301 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5302 | if (value.IsFpuRegister()) { |
| 5303 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5304 | } else { |
| 5305 | DCHECK(value.IsConstant()); |
| 5306 | Address address_hi = index.IsConstant() ? |
| 5307 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5308 | offset + kX86WordSize) : |
| 5309 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5310 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5311 | __ movl(address, Immediate(Low32Bits(v))); |
| 5312 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5313 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5314 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5315 | break; |
| 5316 | } |
| 5317 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5318 | case Primitive::kPrimVoid: |
| 5319 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5320 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5321 | } |
| 5322 | } |
| 5323 | |
| 5324 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5325 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5326 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5327 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5331 | LocationSummary* locations = instruction->GetLocations(); |
| 5332 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5333 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5334 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5336 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5340 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5341 | ? LocationSummary::kCallOnSlowPath |
| 5342 | : LocationSummary::kNoCall; |
| 5343 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5344 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5345 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5346 | if (instruction->HasUses()) { |
| 5347 | locations->SetOut(Location::SameAsFirstInput()); |
| 5348 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5352 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5353 | Location index_loc = locations->InAt(0); |
| 5354 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5355 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5356 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5357 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5358 | if (length_loc.IsConstant()) { |
| 5359 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5360 | if (index_loc.IsConstant()) { |
| 5361 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5362 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5363 | if (index < 0 || index >= length) { |
| 5364 | codegen_->AddSlowPath(slow_path); |
| 5365 | __ jmp(slow_path->GetEntryLabel()); |
| 5366 | } else { |
| 5367 | // Some optimization after BCE may have generated this, and we should not |
| 5368 | // generate a bounds check if it is a valid range. |
| 5369 | } |
| 5370 | return; |
| 5371 | } |
| 5372 | |
| 5373 | // We have to reverse the jump condition because the length is the constant. |
| 5374 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5375 | __ cmpl(index_reg, Immediate(length)); |
| 5376 | codegen_->AddSlowPath(slow_path); |
| 5377 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5378 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5379 | Register length = length_loc.AsRegister<Register>(); |
| 5380 | if (index_loc.IsConstant()) { |
| 5381 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5382 | __ cmpl(length, Immediate(value)); |
| 5383 | } else { |
| 5384 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5385 | } |
| 5386 | codegen_->AddSlowPath(slow_path); |
| 5387 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5388 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5389 | } |
| 5390 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5391 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5392 | temp->SetLocations(nullptr); |
| 5393 | } |
| 5394 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5395 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5396 | // Nothing to do, this is driven by the code generator. |
| 5397 | } |
| 5398 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5399 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5400 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5404 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5405 | } |
| 5406 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5407 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5408 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5409 | } |
| 5410 | |
| 5411 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5412 | HBasicBlock* block = instruction->GetBlock(); |
| 5413 | if (block->GetLoopInformation() != nullptr) { |
| 5414 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5415 | // The back edge will generate the suspend check. |
| 5416 | return; |
| 5417 | } |
| 5418 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5419 | // The goto will generate the suspend check. |
| 5420 | return; |
| 5421 | } |
| 5422 | GenerateSuspendCheck(instruction, nullptr); |
| 5423 | } |
| 5424 | |
| 5425 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5426 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5427 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5428 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5429 | if (slow_path == nullptr) { |
| 5430 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5431 | instruction->SetSlowPath(slow_path); |
| 5432 | codegen_->AddSlowPath(slow_path); |
| 5433 | if (successor != nullptr) { |
| 5434 | DCHECK(successor->IsLoopHeader()); |
| 5435 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5436 | } |
| 5437 | } else { |
| 5438 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5439 | } |
| 5440 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5441 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5442 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5443 | if (successor == nullptr) { |
| 5444 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5445 | __ Bind(slow_path->GetReturnLabel()); |
| 5446 | } else { |
| 5447 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5448 | __ jmp(slow_path->GetEntryLabel()); |
| 5449 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5450 | } |
| 5451 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5452 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5453 | return codegen_->GetAssembler(); |
| 5454 | } |
| 5455 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5456 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5457 | ScratchRegisterScope ensure_scratch( |
| 5458 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5459 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5460 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5461 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5462 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5466 | ScratchRegisterScope ensure_scratch( |
| 5467 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5468 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5469 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5470 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5471 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5472 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5473 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5477 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5478 | Location source = move->GetSource(); |
| 5479 | Location destination = move->GetDestination(); |
| 5480 | |
| 5481 | if (source.IsRegister()) { |
| 5482 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5483 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5484 | } else { |
| 5485 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5486 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5487 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5488 | } else if (source.IsFpuRegister()) { |
| 5489 | if (destination.IsFpuRegister()) { |
| 5490 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5491 | } else if (destination.IsStackSlot()) { |
| 5492 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5493 | } else { |
| 5494 | DCHECK(destination.IsDoubleStackSlot()); |
| 5495 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5496 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5497 | } else if (source.IsStackSlot()) { |
| 5498 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5499 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5500 | } else if (destination.IsFpuRegister()) { |
| 5501 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5502 | } else { |
| 5503 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5504 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5505 | } |
| 5506 | } else if (source.IsDoubleStackSlot()) { |
| 5507 | if (destination.IsFpuRegister()) { |
| 5508 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5509 | } else { |
| 5510 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5511 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5512 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5513 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5514 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5515 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5516 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5517 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5518 | if (value == 0) { |
| 5519 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5520 | } else { |
| 5521 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5522 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5523 | } else { |
| 5524 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5525 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5526 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5527 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5528 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5529 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5530 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5531 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5532 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5533 | if (value == 0) { |
| 5534 | // Easy handling of 0.0. |
| 5535 | __ xorps(dest, dest); |
| 5536 | } else { |
| 5537 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5538 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5539 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5540 | __ movl(temp, Immediate(value)); |
| 5541 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5542 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5543 | } else { |
| 5544 | DCHECK(destination.IsStackSlot()) << destination; |
| 5545 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5546 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5547 | } else if (constant->IsLongConstant()) { |
| 5548 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5549 | int32_t low_value = Low32Bits(value); |
| 5550 | int32_t high_value = High32Bits(value); |
| 5551 | Immediate low(low_value); |
| 5552 | Immediate high(high_value); |
| 5553 | if (destination.IsDoubleStackSlot()) { |
| 5554 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5555 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5556 | } else { |
| 5557 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5558 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5559 | } |
| 5560 | } else { |
| 5561 | DCHECK(constant->IsDoubleConstant()); |
| 5562 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5563 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5564 | int32_t low_value = Low32Bits(value); |
| 5565 | int32_t high_value = High32Bits(value); |
| 5566 | Immediate low(low_value); |
| 5567 | Immediate high(high_value); |
| 5568 | if (destination.IsFpuRegister()) { |
| 5569 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5570 | if (value == 0) { |
| 5571 | // Easy handling of 0.0. |
| 5572 | __ xorpd(dest, dest); |
| 5573 | } else { |
| 5574 | __ pushl(high); |
| 5575 | __ pushl(low); |
| 5576 | __ movsd(dest, Address(ESP, 0)); |
| 5577 | __ addl(ESP, Immediate(8)); |
| 5578 | } |
| 5579 | } else { |
| 5580 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5581 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5582 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5583 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5584 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5585 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5586 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5590 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5591 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5592 | ScratchRegisterScope ensure_scratch( |
| 5593 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5594 | |
| 5595 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5596 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5597 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5598 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5599 | } |
| 5600 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5601 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5602 | ScratchRegisterScope ensure_scratch( |
| 5603 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5604 | |
| 5605 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5606 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5607 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5608 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5609 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5610 | } |
| 5611 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5612 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5613 | ScratchRegisterScope ensure_scratch1( |
| 5614 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5615 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5616 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5617 | ScratchRegisterScope ensure_scratch2( |
| 5618 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5619 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5620 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5621 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5622 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5623 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5624 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5625 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5629 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5630 | Location source = move->GetSource(); |
| 5631 | Location destination = move->GetDestination(); |
| 5632 | |
| 5633 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5634 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5635 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5636 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5637 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5638 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5639 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5640 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5641 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5642 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5643 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5644 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5645 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5646 | // Use XOR Swap algorithm to avoid a temporary. |
| 5647 | DCHECK_NE(source.reg(), destination.reg()); |
| 5648 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5649 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5650 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5651 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5652 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5653 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5654 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5655 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5656 | // Take advantage of the 16 bytes in the XMM register. |
| 5657 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5658 | Address stack(ESP, destination.GetStackIndex()); |
| 5659 | // Load the double into the high doubleword. |
| 5660 | __ movhpd(reg, stack); |
| 5661 | |
| 5662 | // Store the low double into the destination. |
| 5663 | __ movsd(stack, reg); |
| 5664 | |
| 5665 | // Move the high double to the low double. |
| 5666 | __ psrldq(reg, Immediate(8)); |
| 5667 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5668 | // Take advantage of the 16 bytes in the XMM register. |
| 5669 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5670 | Address stack(ESP, source.GetStackIndex()); |
| 5671 | // Load the double into the high doubleword. |
| 5672 | __ movhpd(reg, stack); |
| 5673 | |
| 5674 | // Store the low double into the destination. |
| 5675 | __ movsd(stack, reg); |
| 5676 | |
| 5677 | // Move the high double to the low double. |
| 5678 | __ psrldq(reg, Immediate(8)); |
| 5679 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5680 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5681 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5682 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5683 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5688 | __ pushl(static_cast<Register>(reg)); |
| 5689 | } |
| 5690 | |
| 5691 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5692 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5693 | } |
| 5694 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5695 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5696 | InvokeRuntimeCallingConvention calling_convention; |
| 5697 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5698 | cls, |
| 5699 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5700 | Location::RegisterLocation(EAX), |
| 5701 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5705 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5706 | if (cls->NeedsAccessCheck()) { |
| 5707 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5708 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5709 | cls, |
| 5710 | cls->GetDexPc(), |
| 5711 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5712 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5713 | return; |
| 5714 | } |
| 5715 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5716 | Location out_loc = locations->Out(); |
| 5717 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5718 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5719 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5720 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5721 | DCHECK(!cls->CanCallRuntime()); |
| 5722 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5723 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5724 | GenerateGcRootFieldLoad( |
| 5725 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5726 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5727 | // /* GcRoot<mirror::Class>[] */ out = |
| 5728 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5729 | __ movl(out, Address(current_method, |
| 5730 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5731 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5732 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5733 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5734 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5735 | DCHECK(cls->CanCallRuntime()); |
| 5736 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5737 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5738 | codegen_->AddSlowPath(slow_path); |
| 5739 | |
| 5740 | if (!cls->IsInDexCache()) { |
| 5741 | __ testl(out, out); |
| 5742 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5743 | } |
| 5744 | |
| 5745 | if (cls->MustGenerateClinitCheck()) { |
| 5746 | GenerateClassInitializationCheck(slow_path, out); |
| 5747 | } else { |
| 5748 | __ Bind(slow_path->GetExitLabel()); |
| 5749 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5750 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5755 | LocationSummary* locations = |
| 5756 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5757 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5758 | if (check->HasUses()) { |
| 5759 | locations->SetOut(Location::SameAsFirstInput()); |
| 5760 | } |
| 5761 | } |
| 5762 | |
| 5763 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5764 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5765 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5766 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5767 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5768 | GenerateClassInitializationCheck(slow_path, |
| 5769 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5770 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5771 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5772 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5773 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5774 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5775 | Immediate(mirror::Class::kStatusInitialized)); |
| 5776 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5777 | __ Bind(slow_path->GetExitLabel()); |
| 5778 | // No need for memory fence, thanks to the X86 memory model. |
| 5779 | } |
| 5780 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5781 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5782 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5783 | ? LocationSummary::kCallOnSlowPath |
| 5784 | : LocationSummary::kNoCall; |
| 5785 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5786 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5787 | locations->SetOut(Location::RequiresRegister()); |
| 5788 | } |
| 5789 | |
| 5790 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5791 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5792 | Location out_loc = locations->Out(); |
| 5793 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5794 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5795 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5796 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5797 | GenerateGcRootFieldLoad( |
| 5798 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5799 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5800 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5801 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5802 | GenerateGcRootFieldLoad( |
| 5803 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5804 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5805 | if (!load->IsInDexCache()) { |
| 5806 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5807 | codegen_->AddSlowPath(slow_path); |
| 5808 | __ testl(out, out); |
| 5809 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5810 | __ Bind(slow_path->GetExitLabel()); |
| 5811 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5812 | } |
| 5813 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5814 | static Address GetExceptionTlsAddress() { |
| 5815 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5816 | } |
| 5817 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5818 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5819 | LocationSummary* locations = |
| 5820 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5821 | locations->SetOut(Location::RequiresRegister()); |
| 5822 | } |
| 5823 | |
| 5824 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5825 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5826 | } |
| 5827 | |
| 5828 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5829 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5830 | } |
| 5831 | |
| 5832 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5833 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5837 | LocationSummary* locations = |
| 5838 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5839 | InvokeRuntimeCallingConvention calling_convention; |
| 5840 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5841 | } |
| 5842 | |
| 5843 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5844 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5845 | instruction, |
| 5846 | instruction->GetDexPc(), |
| 5847 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5848 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5851 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5852 | return kEmitCompilerReadBarrier && |
| 5853 | (kUseBakerReadBarrier || |
| 5854 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5855 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5856 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5857 | } |
| 5858 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5859 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5860 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5861 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5862 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5863 | case TypeCheckKind::kExactCheck: |
| 5864 | case TypeCheckKind::kAbstractClassCheck: |
| 5865 | case TypeCheckKind::kClassHierarchyCheck: |
| 5866 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5867 | call_kind = |
| 5868 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5869 | break; |
| 5870 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5871 | case TypeCheckKind::kUnresolvedCheck: |
| 5872 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5873 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5874 | break; |
| 5875 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5876 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5877 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5878 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5879 | locations->SetInAt(1, Location::Any()); |
| 5880 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5881 | locations->SetOut(Location::RequiresRegister()); |
| 5882 | // When read barriers are enabled, we need a temporary register for |
| 5883 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5884 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5885 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5886 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5889 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5890 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5891 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5892 | Location obj_loc = locations->InAt(0); |
| 5893 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5894 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5895 | Location out_loc = locations->Out(); |
| 5896 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5897 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5898 | locations->GetTemp(0) : |
| 5899 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5900 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5901 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5902 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5903 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5904 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5905 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5906 | |
| 5907 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5908 | // Avoid null check if we know obj is not null. |
| 5909 | if (instruction->MustDoNullCheck()) { |
| 5910 | __ testl(obj, obj); |
| 5911 | __ j(kEqual, &zero); |
| 5912 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5913 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5914 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5915 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5916 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5917 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5918 | case TypeCheckKind::kExactCheck: { |
| 5919 | if (cls.IsRegister()) { |
| 5920 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5921 | } else { |
| 5922 | DCHECK(cls.IsStackSlot()) << cls; |
| 5923 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5924 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5925 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5926 | // Classes must be equal for the instanceof to succeed. |
| 5927 | __ j(kNotEqual, &zero); |
| 5928 | __ movl(out, Immediate(1)); |
| 5929 | __ jmp(&done); |
| 5930 | break; |
| 5931 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5932 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5933 | case TypeCheckKind::kAbstractClassCheck: { |
| 5934 | // If the class is abstract, we eagerly fetch the super class of the |
| 5935 | // object to avoid doing a comparison we know will fail. |
| 5936 | NearLabel loop; |
| 5937 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5938 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5939 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5940 | __ testl(out, out); |
| 5941 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5942 | __ j(kEqual, &done); |
| 5943 | if (cls.IsRegister()) { |
| 5944 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5945 | } else { |
| 5946 | DCHECK(cls.IsStackSlot()) << cls; |
| 5947 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5948 | } |
| 5949 | __ j(kNotEqual, &loop); |
| 5950 | __ movl(out, Immediate(1)); |
| 5951 | if (zero.IsLinked()) { |
| 5952 | __ jmp(&done); |
| 5953 | } |
| 5954 | break; |
| 5955 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5956 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5958 | // Walk over the class hierarchy to find a match. |
| 5959 | NearLabel loop, success; |
| 5960 | __ Bind(&loop); |
| 5961 | if (cls.IsRegister()) { |
| 5962 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5963 | } else { |
| 5964 | DCHECK(cls.IsStackSlot()) << cls; |
| 5965 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5966 | } |
| 5967 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5968 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5969 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5970 | __ testl(out, out); |
| 5971 | __ j(kNotEqual, &loop); |
| 5972 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5973 | __ jmp(&done); |
| 5974 | __ Bind(&success); |
| 5975 | __ movl(out, Immediate(1)); |
| 5976 | if (zero.IsLinked()) { |
| 5977 | __ jmp(&done); |
| 5978 | } |
| 5979 | break; |
| 5980 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5981 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5982 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5983 | // Do an exact check. |
| 5984 | NearLabel exact_check; |
| 5985 | if (cls.IsRegister()) { |
| 5986 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5987 | } else { |
| 5988 | DCHECK(cls.IsStackSlot()) << cls; |
| 5989 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5990 | } |
| 5991 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5992 | // 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] | 5993 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 5994 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5995 | __ testl(out, out); |
| 5996 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5997 | __ j(kEqual, &done); |
| 5998 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5999 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6000 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6001 | __ movl(out, Immediate(1)); |
| 6002 | __ jmp(&done); |
| 6003 | break; |
| 6004 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6005 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6006 | case TypeCheckKind::kArrayCheck: { |
| 6007 | if (cls.IsRegister()) { |
| 6008 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6009 | } else { |
| 6010 | DCHECK(cls.IsStackSlot()) << cls; |
| 6011 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6012 | } |
| 6013 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6014 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6015 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6016 | codegen_->AddSlowPath(slow_path); |
| 6017 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6018 | __ movl(out, Immediate(1)); |
| 6019 | if (zero.IsLinked()) { |
| 6020 | __ jmp(&done); |
| 6021 | } |
| 6022 | break; |
| 6023 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6024 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6025 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6026 | case TypeCheckKind::kInterfaceCheck: { |
| 6027 | // 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] | 6028 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6029 | // cases. |
| 6030 | // |
| 6031 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6032 | // entry point without resorting to a type checking slow path |
| 6033 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6034 | // require to assign fixed registers for the inputs of this |
| 6035 | // HInstanceOf instruction (following the runtime calling |
| 6036 | // convention), which might be cluttered by the potential first |
| 6037 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6038 | // |
| 6039 | // TODO: Introduce a new runtime entry point taking the object |
| 6040 | // to test (instead of its class) as argument, and let it deal |
| 6041 | // with the read barrier issues. This will let us refactor this |
| 6042 | // case of the `switch` code as it was previously (with a direct |
| 6043 | // call to the runtime not using a type checking slow path). |
| 6044 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6045 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6046 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6047 | /* is_fatal */ false); |
| 6048 | codegen_->AddSlowPath(slow_path); |
| 6049 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | if (zero.IsLinked()) { |
| 6051 | __ jmp(&done); |
| 6052 | } |
| 6053 | break; |
| 6054 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6055 | } |
| 6056 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6057 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6058 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6059 | __ xorl(out, out); |
| 6060 | } |
| 6061 | |
| 6062 | if (done.IsLinked()) { |
| 6063 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6064 | } |
| 6065 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6066 | if (slow_path != nullptr) { |
| 6067 | __ Bind(slow_path->GetExitLabel()); |
| 6068 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6069 | } |
| 6070 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6071 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6072 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6073 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6074 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6075 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6076 | case TypeCheckKind::kExactCheck: |
| 6077 | case TypeCheckKind::kAbstractClassCheck: |
| 6078 | case TypeCheckKind::kClassHierarchyCheck: |
| 6079 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6080 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6081 | LocationSummary::kCallOnSlowPath : |
| 6082 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6083 | break; |
| 6084 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6085 | case TypeCheckKind::kUnresolvedCheck: |
| 6086 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6087 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6088 | break; |
| 6089 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6090 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6091 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6092 | locations->SetInAt(1, Location::Any()); |
| 6093 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6094 | locations->AddTemp(Location::RequiresRegister()); |
| 6095 | // When read barriers are enabled, we need an additional temporary |
| 6096 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6097 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6098 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6099 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6103 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6104 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6105 | Location obj_loc = locations->InAt(0); |
| 6106 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6107 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6108 | Location temp_loc = locations->GetTemp(0); |
| 6109 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6110 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6111 | locations->GetTemp(1) : |
| 6112 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6113 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6114 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6115 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6116 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6117 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6118 | bool is_type_check_slow_path_fatal = |
| 6119 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6120 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6121 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6122 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6123 | !instruction->CanThrowIntoCatchBlock(); |
| 6124 | SlowPathCode* type_check_slow_path = |
| 6125 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6126 | is_type_check_slow_path_fatal); |
| 6127 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6128 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6129 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6130 | // Avoid null check if we know obj is not null. |
| 6131 | if (instruction->MustDoNullCheck()) { |
| 6132 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6133 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6134 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6135 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6136 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6137 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6138 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6139 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6140 | case TypeCheckKind::kExactCheck: |
| 6141 | case TypeCheckKind::kArrayCheck: { |
| 6142 | if (cls.IsRegister()) { |
| 6143 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6144 | } else { |
| 6145 | DCHECK(cls.IsStackSlot()) << cls; |
| 6146 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6147 | } |
| 6148 | // Jump to slow path for throwing the exception or doing a |
| 6149 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6150 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6151 | break; |
| 6152 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6153 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6154 | case TypeCheckKind::kAbstractClassCheck: { |
| 6155 | // If the class is abstract, we eagerly fetch the super class of the |
| 6156 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6157 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6159 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6160 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6161 | |
| 6162 | // If the class reference currently in `temp` is not null, jump |
| 6163 | // to the `compare_classes` label to compare it with the checked |
| 6164 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6165 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6166 | __ j(kNotEqual, &compare_classes); |
| 6167 | // Otherwise, jump to the slow path to throw the exception. |
| 6168 | // |
| 6169 | // But before, move back the object's class into `temp` before |
| 6170 | // going into the slow path, as it has been overwritten in the |
| 6171 | // meantime. |
| 6172 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6173 | GenerateReferenceLoadTwoRegisters( |
| 6174 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6175 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6176 | |
| 6177 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6178 | if (cls.IsRegister()) { |
| 6179 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6180 | } else { |
| 6181 | DCHECK(cls.IsStackSlot()) << cls; |
| 6182 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6183 | } |
| 6184 | __ j(kNotEqual, &loop); |
| 6185 | break; |
| 6186 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6187 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6188 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6189 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6190 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6191 | __ Bind(&loop); |
| 6192 | if (cls.IsRegister()) { |
| 6193 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6194 | } else { |
| 6195 | DCHECK(cls.IsStackSlot()) << cls; |
| 6196 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6197 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6198 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6199 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6200 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6201 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6202 | |
| 6203 | // If the class reference currently in `temp` is not null, jump |
| 6204 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6205 | __ testl(temp, temp); |
| 6206 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6207 | // Otherwise, jump to the slow path to throw the exception. |
| 6208 | // |
| 6209 | // But before, move back the object's class into `temp` before |
| 6210 | // going into the slow path, as it has been overwritten in the |
| 6211 | // meantime. |
| 6212 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6213 | GenerateReferenceLoadTwoRegisters( |
| 6214 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6215 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6216 | break; |
| 6217 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6218 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6219 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6220 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6221 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6222 | if (cls.IsRegister()) { |
| 6223 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6224 | } else { |
| 6225 | DCHECK(cls.IsStackSlot()) << cls; |
| 6226 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6227 | } |
| 6228 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6229 | |
| 6230 | // 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] | 6231 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6232 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6233 | |
| 6234 | // If the component type is not null (i.e. the object is indeed |
| 6235 | // an array), jump to label `check_non_primitive_component_type` |
| 6236 | // to further check that this component type is not a primitive |
| 6237 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6238 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6239 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6240 | // Otherwise, jump to the slow path to throw the exception. |
| 6241 | // |
| 6242 | // But before, move back the object's class into `temp` before |
| 6243 | // going into the slow path, as it has been overwritten in the |
| 6244 | // meantime. |
| 6245 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6246 | GenerateReferenceLoadTwoRegisters( |
| 6247 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6248 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6249 | |
| 6250 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6251 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6252 | __ j(kEqual, &done); |
| 6253 | // Same comment as above regarding `temp` and the slow path. |
| 6254 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6255 | GenerateReferenceLoadTwoRegisters( |
| 6256 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6257 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6258 | break; |
| 6259 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6260 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6261 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6262 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6263 | // We always go into the type check slow path for the unresolved |
| 6264 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6265 | // |
| 6266 | // We cannot directly call the CheckCast runtime entry point |
| 6267 | // without resorting to a type checking slow path here (i.e. by |
| 6268 | // calling InvokeRuntime directly), as it would require to |
| 6269 | // assign fixed registers for the inputs of this HInstanceOf |
| 6270 | // instruction (following the runtime calling convention), which |
| 6271 | // might be cluttered by the potential first read barrier |
| 6272 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6273 | // |
| 6274 | // TODO: Introduce a new runtime entry point taking the object |
| 6275 | // to test (instead of its class) as argument, and let it deal |
| 6276 | // with the read barrier issues. This will let us refactor this |
| 6277 | // case of the `switch` code as it was previously (with a direct |
| 6278 | // call to the runtime not using a type checking slow path). |
| 6279 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6280 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6281 | break; |
| 6282 | } |
| 6283 | __ Bind(&done); |
| 6284 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6285 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6288 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6289 | LocationSummary* locations = |
| 6290 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6291 | InvokeRuntimeCallingConvention calling_convention; |
| 6292 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6293 | } |
| 6294 | |
| 6295 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6296 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6297 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6298 | instruction, |
| 6299 | instruction->GetDexPc(), |
| 6300 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6301 | if (instruction->IsEnter()) { |
| 6302 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6303 | } else { |
| 6304 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6305 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6306 | } |
| 6307 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6308 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6309 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6310 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6311 | |
| 6312 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6313 | LocationSummary* locations = |
| 6314 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6315 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6316 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6318 | locations->SetInAt(1, Location::Any()); |
| 6319 | locations->SetOut(Location::SameAsFirstInput()); |
| 6320 | } |
| 6321 | |
| 6322 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6323 | HandleBitwiseOperation(instruction); |
| 6324 | } |
| 6325 | |
| 6326 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6327 | HandleBitwiseOperation(instruction); |
| 6328 | } |
| 6329 | |
| 6330 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6331 | HandleBitwiseOperation(instruction); |
| 6332 | } |
| 6333 | |
| 6334 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6335 | LocationSummary* locations = instruction->GetLocations(); |
| 6336 | Location first = locations->InAt(0); |
| 6337 | Location second = locations->InAt(1); |
| 6338 | DCHECK(first.Equals(locations->Out())); |
| 6339 | |
| 6340 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6341 | if (second.IsRegister()) { |
| 6342 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6343 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6344 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6345 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6346 | } else { |
| 6347 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6348 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6349 | } |
| 6350 | } else if (second.IsConstant()) { |
| 6351 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6352 | __ andl(first.AsRegister<Register>(), |
| 6353 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6354 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6355 | __ orl(first.AsRegister<Register>(), |
| 6356 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6357 | } else { |
| 6358 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6359 | __ xorl(first.AsRegister<Register>(), |
| 6360 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6361 | } |
| 6362 | } else { |
| 6363 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6364 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6365 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6366 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6367 | } else { |
| 6368 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6369 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6370 | } |
| 6371 | } |
| 6372 | } else { |
| 6373 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6374 | if (second.IsRegisterPair()) { |
| 6375 | if (instruction->IsAnd()) { |
| 6376 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6377 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6378 | } else if (instruction->IsOr()) { |
| 6379 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6380 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6381 | } else { |
| 6382 | DCHECK(instruction->IsXor()); |
| 6383 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6384 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6385 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6386 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6387 | if (instruction->IsAnd()) { |
| 6388 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6389 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6390 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6391 | } else if (instruction->IsOr()) { |
| 6392 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6393 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6394 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6395 | } else { |
| 6396 | DCHECK(instruction->IsXor()); |
| 6397 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6398 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6399 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6400 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6401 | } else { |
| 6402 | DCHECK(second.IsConstant()) << second; |
| 6403 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6404 | int32_t low_value = Low32Bits(value); |
| 6405 | int32_t high_value = High32Bits(value); |
| 6406 | Immediate low(low_value); |
| 6407 | Immediate high(high_value); |
| 6408 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6409 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6410 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6411 | if (low_value == 0) { |
| 6412 | __ xorl(first_low, first_low); |
| 6413 | } else if (low_value != -1) { |
| 6414 | __ andl(first_low, low); |
| 6415 | } |
| 6416 | if (high_value == 0) { |
| 6417 | __ xorl(first_high, first_high); |
| 6418 | } else if (high_value != -1) { |
| 6419 | __ andl(first_high, high); |
| 6420 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6421 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6422 | if (low_value != 0) { |
| 6423 | __ orl(first_low, low); |
| 6424 | } |
| 6425 | if (high_value != 0) { |
| 6426 | __ orl(first_high, high); |
| 6427 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6428 | } else { |
| 6429 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6430 | if (low_value != 0) { |
| 6431 | __ xorl(first_low, low); |
| 6432 | } |
| 6433 | if (high_value != 0) { |
| 6434 | __ xorl(first_high, high); |
| 6435 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6436 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6437 | } |
| 6438 | } |
| 6439 | } |
| 6440 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6441 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6442 | Location out, |
| 6443 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6444 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6445 | Register out_reg = out.AsRegister<Register>(); |
| 6446 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6447 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6448 | if (kUseBakerReadBarrier) { |
| 6449 | // Load with fast path based Baker's read barrier. |
| 6450 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6451 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6452 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6453 | } else { |
| 6454 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6455 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6456 | // in the following move operation, as we will need it for the |
| 6457 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6458 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6459 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6460 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6461 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6462 | } |
| 6463 | } else { |
| 6464 | // Plain load with no read barrier. |
| 6465 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6466 | __ movl(out_reg, Address(out_reg, offset)); |
| 6467 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6472 | Location out, |
| 6473 | Location obj, |
| 6474 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6475 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6476 | Register out_reg = out.AsRegister<Register>(); |
| 6477 | Register obj_reg = obj.AsRegister<Register>(); |
| 6478 | if (kEmitCompilerReadBarrier) { |
| 6479 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6480 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6481 | // Load with fast path based Baker's read barrier. |
| 6482 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6483 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6484 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6485 | } else { |
| 6486 | // Load with slow path based read barrier. |
| 6487 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6488 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6489 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6490 | } |
| 6491 | } else { |
| 6492 | // Plain load with no read barrier. |
| 6493 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6494 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6495 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6500 | Location root, |
| 6501 | Register obj, |
| 6502 | uint32_t offset) { |
| 6503 | Register root_reg = root.AsRegister<Register>(); |
| 6504 | if (kEmitCompilerReadBarrier) { |
| 6505 | if (kUseBakerReadBarrier) { |
| 6506 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6507 | // Baker's read barrier are used: |
| 6508 | // |
| 6509 | // root = obj.field; |
| 6510 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6511 | // root = ReadBarrier::Mark(root) |
| 6512 | // } |
| 6513 | |
| 6514 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6515 | __ movl(root_reg, Address(obj, offset)); |
| 6516 | static_assert( |
| 6517 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6518 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6519 | "have different sizes."); |
| 6520 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6521 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6522 | "have different sizes."); |
| 6523 | |
| 6524 | // Slow path used to mark the GC root `root`. |
| 6525 | SlowPathCode* slow_path = |
| 6526 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6527 | codegen_->AddSlowPath(slow_path); |
| 6528 | |
| 6529 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6530 | Immediate(0)); |
| 6531 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6532 | __ Bind(slow_path->GetExitLabel()); |
| 6533 | } else { |
| 6534 | // GC root loaded through a slow path for read barriers other |
| 6535 | // than Baker's. |
| 6536 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6537 | __ leal(root_reg, Address(obj, offset)); |
| 6538 | // /* mirror::Object* */ root = root->Read() |
| 6539 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6540 | } |
| 6541 | } else { |
| 6542 | // Plain GC root load with no read barrier. |
| 6543 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6544 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6545 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6546 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6547 | } |
| 6548 | } |
| 6549 | |
| 6550 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6551 | Location ref, |
| 6552 | Register obj, |
| 6553 | uint32_t offset, |
| 6554 | Location temp, |
| 6555 | bool needs_null_check) { |
| 6556 | DCHECK(kEmitCompilerReadBarrier); |
| 6557 | DCHECK(kUseBakerReadBarrier); |
| 6558 | |
| 6559 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6560 | Address src(obj, offset); |
| 6561 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6562 | } |
| 6563 | |
| 6564 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6565 | Location ref, |
| 6566 | Register obj, |
| 6567 | uint32_t data_offset, |
| 6568 | Location index, |
| 6569 | Location temp, |
| 6570 | bool needs_null_check) { |
| 6571 | DCHECK(kEmitCompilerReadBarrier); |
| 6572 | DCHECK(kUseBakerReadBarrier); |
| 6573 | |
| 6574 | // /* HeapReference<Object> */ ref = |
| 6575 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6576 | Address src = index.IsConstant() ? |
| 6577 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6578 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6579 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6580 | } |
| 6581 | |
| 6582 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6583 | Location ref, |
| 6584 | Register obj, |
| 6585 | const Address& src, |
| 6586 | Location temp, |
| 6587 | bool needs_null_check) { |
| 6588 | DCHECK(kEmitCompilerReadBarrier); |
| 6589 | DCHECK(kUseBakerReadBarrier); |
| 6590 | |
| 6591 | // In slow path based read barriers, the read barrier call is |
| 6592 | // inserted after the original load. However, in fast path based |
| 6593 | // Baker's read barriers, we need to perform the load of |
| 6594 | // mirror::Object::monitor_ *before* the original reference load. |
| 6595 | // This load-load ordering is required by the read barrier. |
| 6596 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6597 | // |
| 6598 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6599 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6600 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6601 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6602 | // if (is_gray) { |
| 6603 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6604 | // } |
| 6605 | // |
| 6606 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6607 | // slightly more complex as: |
| 6608 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6609 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6610 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6611 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6612 | // - it performs additional checks that we do not do here for |
| 6613 | // performance reasons. |
| 6614 | |
| 6615 | Register ref_reg = ref.AsRegister<Register>(); |
| 6616 | Register temp_reg = temp.AsRegister<Register>(); |
| 6617 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6618 | |
| 6619 | // /* int32_t */ monitor = obj->monitor_ |
| 6620 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6621 | if (needs_null_check) { |
| 6622 | MaybeRecordImplicitNullCheck(instruction); |
| 6623 | } |
| 6624 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6625 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6626 | "art::LockWord and int32_t have different sizes."); |
| 6627 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6628 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6629 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6630 | static_assert( |
| 6631 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6632 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6633 | |
| 6634 | // Load fence to prevent load-load reordering. |
| 6635 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6636 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6637 | |
| 6638 | // The actual reference load. |
| 6639 | // /* HeapReference<Object> */ ref = *src |
| 6640 | __ movl(ref_reg, src); |
| 6641 | |
| 6642 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6643 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6644 | |
| 6645 | // Slow path used to mark the object `ref` when it is gray. |
| 6646 | SlowPathCode* slow_path = |
| 6647 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6648 | AddSlowPath(slow_path); |
| 6649 | |
| 6650 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6651 | // ref = ReadBarrier::Mark(ref); |
| 6652 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6653 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6654 | __ Bind(slow_path->GetExitLabel()); |
| 6655 | } |
| 6656 | |
| 6657 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6658 | Location out, |
| 6659 | Location ref, |
| 6660 | Location obj, |
| 6661 | uint32_t offset, |
| 6662 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6663 | DCHECK(kEmitCompilerReadBarrier); |
| 6664 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6665 | // Insert a slow path based read barrier *after* the reference load. |
| 6666 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6667 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6668 | // reference will be carried out by the runtime within the slow |
| 6669 | // path. |
| 6670 | // |
| 6671 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6672 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6673 | // not used by the artReadBarrierSlow entry point. |
| 6674 | // |
| 6675 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6676 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6677 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6678 | AddSlowPath(slow_path); |
| 6679 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6680 | __ jmp(slow_path->GetEntryLabel()); |
| 6681 | __ Bind(slow_path->GetExitLabel()); |
| 6682 | } |
| 6683 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6684 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6685 | Location out, |
| 6686 | Location ref, |
| 6687 | Location obj, |
| 6688 | uint32_t offset, |
| 6689 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6690 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6691 | // Baker's read barriers shall be handled by the fast path |
| 6692 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6693 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6694 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6695 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6696 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6697 | } else if (kPoisonHeapReferences) { |
| 6698 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6699 | } |
| 6700 | } |
| 6701 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6702 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6703 | Location out, |
| 6704 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | DCHECK(kEmitCompilerReadBarrier); |
| 6706 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6707 | // Insert a slow path based read barrier *after* the GC root load. |
| 6708 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6709 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6710 | // not need to do anything special for this here. |
| 6711 | SlowPathCode* slow_path = |
| 6712 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6713 | AddSlowPath(slow_path); |
| 6714 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6715 | __ jmp(slow_path->GetEntryLabel()); |
| 6716 | __ Bind(slow_path->GetExitLabel()); |
| 6717 | } |
| 6718 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6719 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6720 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6721 | LOG(FATAL) << "Unreachable"; |
| 6722 | } |
| 6723 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6724 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6725 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6726 | LOG(FATAL) << "Unreachable"; |
| 6727 | } |
| 6728 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6729 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6730 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6731 | LocationSummary* locations = |
| 6732 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6733 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6734 | } |
| 6735 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6736 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6737 | int32_t lower_bound, |
| 6738 | uint32_t num_entries, |
| 6739 | HBasicBlock* switch_block, |
| 6740 | HBasicBlock* default_block) { |
| 6741 | // Figure out the correct compare values and jump conditions. |
| 6742 | // Handle the first compare/branch as a special case because it might |
| 6743 | // jump to the default case. |
| 6744 | DCHECK_GT(num_entries, 2u); |
| 6745 | Condition first_condition; |
| 6746 | uint32_t index; |
| 6747 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6748 | if (lower_bound != 0) { |
| 6749 | first_condition = kLess; |
| 6750 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6751 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6752 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6753 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6754 | index = 1; |
| 6755 | } else { |
| 6756 | // Handle all the compare/jumps below. |
| 6757 | first_condition = kBelow; |
| 6758 | index = 0; |
| 6759 | } |
| 6760 | |
| 6761 | // Handle the rest of the compare/jumps. |
| 6762 | for (; index + 1 < num_entries; index += 2) { |
| 6763 | int32_t compare_to_value = lower_bound + index + 1; |
| 6764 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6765 | // Jump to successors[index] if value < case_value[index]. |
| 6766 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6767 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6768 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6769 | } |
| 6770 | |
| 6771 | if (index != num_entries) { |
| 6772 | // There are an odd number of entries. Handle the last one. |
| 6773 | DCHECK_EQ(index + 1, num_entries); |
| 6774 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6775 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6779 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6780 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6781 | } |
| 6782 | } |
| 6783 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6784 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6785 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6786 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6787 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6788 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6789 | |
| 6790 | GenPackedSwitchWithCompares(value_reg, |
| 6791 | lower_bound, |
| 6792 | num_entries, |
| 6793 | switch_instr->GetBlock(), |
| 6794 | switch_instr->GetDefaultBlock()); |
| 6795 | } |
| 6796 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6797 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6798 | LocationSummary* locations = |
| 6799 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6800 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6801 | |
| 6802 | // Constant area pointer. |
| 6803 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6804 | |
| 6805 | // And the temporary we need. |
| 6806 | locations->AddTemp(Location::RequiresRegister()); |
| 6807 | } |
| 6808 | |
| 6809 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6810 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6811 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6812 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6813 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6814 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6815 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6816 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6817 | GenPackedSwitchWithCompares(value_reg, |
| 6818 | lower_bound, |
| 6819 | num_entries, |
| 6820 | switch_instr->GetBlock(), |
| 6821 | default_block); |
| 6822 | return; |
| 6823 | } |
| 6824 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6825 | // Optimizing has a jump area. |
| 6826 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6827 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6828 | |
| 6829 | // Remove the bias, if needed. |
| 6830 | if (lower_bound != 0) { |
| 6831 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6832 | value_reg = temp_reg; |
| 6833 | } |
| 6834 | |
| 6835 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6836 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6837 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6838 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6839 | |
| 6840 | // We are in the range of the table. |
| 6841 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6842 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6843 | |
| 6844 | // Compute the actual target address by adding in constant_area. |
| 6845 | __ addl(temp_reg, constant_area); |
| 6846 | |
| 6847 | // And jump. |
| 6848 | __ jmp(temp_reg); |
| 6849 | } |
| 6850 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6851 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6852 | HX86ComputeBaseMethodAddress* insn) { |
| 6853 | LocationSummary* locations = |
| 6854 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6855 | locations->SetOut(Location::RequiresRegister()); |
| 6856 | } |
| 6857 | |
| 6858 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6859 | HX86ComputeBaseMethodAddress* insn) { |
| 6860 | LocationSummary* locations = insn->GetLocations(); |
| 6861 | Register reg = locations->Out().AsRegister<Register>(); |
| 6862 | |
| 6863 | // Generate call to next instruction. |
| 6864 | Label next_instruction; |
| 6865 | __ call(&next_instruction); |
| 6866 | __ Bind(&next_instruction); |
| 6867 | |
| 6868 | // Remember this offset for later use with constant area. |
| 6869 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6870 | |
| 6871 | // Grab the return address off the stack. |
| 6872 | __ popl(reg); |
| 6873 | } |
| 6874 | |
| 6875 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6876 | HX86LoadFromConstantTable* insn) { |
| 6877 | LocationSummary* locations = |
| 6878 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6879 | |
| 6880 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6881 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6882 | |
| 6883 | // 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^] | 6884 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6885 | return; |
| 6886 | } |
| 6887 | |
| 6888 | switch (insn->GetType()) { |
| 6889 | case Primitive::kPrimFloat: |
| 6890 | case Primitive::kPrimDouble: |
| 6891 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6892 | break; |
| 6893 | |
| 6894 | case Primitive::kPrimInt: |
| 6895 | locations->SetOut(Location::RequiresRegister()); |
| 6896 | break; |
| 6897 | |
| 6898 | default: |
| 6899 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame^] | 6904 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6905 | return; |
| 6906 | } |
| 6907 | |
| 6908 | LocationSummary* locations = insn->GetLocations(); |
| 6909 | Location out = locations->Out(); |
| 6910 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 6911 | HConstant *value = insn->GetConstant(); |
| 6912 | |
| 6913 | switch (insn->GetType()) { |
| 6914 | case Primitive::kPrimFloat: |
| 6915 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 6916 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 6917 | break; |
| 6918 | |
| 6919 | case Primitive::kPrimDouble: |
| 6920 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 6921 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 6922 | break; |
| 6923 | |
| 6924 | case Primitive::kPrimInt: |
| 6925 | __ movl(out.AsRegister<Register>(), |
| 6926 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 6927 | break; |
| 6928 | |
| 6929 | default: |
| 6930 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6931 | } |
| 6932 | } |
| 6933 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6934 | /** |
| 6935 | * Class to handle late fixup of offsets into constant area. |
| 6936 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 6937 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6938 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6939 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 6940 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6941 | |
| 6942 | protected: |
| 6943 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6944 | |
| 6945 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6946 | |
| 6947 | private: |
| 6948 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6949 | // Patch the correct offset for the instruction. The place to patch is the |
| 6950 | // last 4 bytes of the instruction. |
| 6951 | // The value to patch is the distance from the offset in the constant area |
| 6952 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6953 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6954 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6955 | |
| 6956 | // Patch in the right value. |
| 6957 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6958 | } |
| 6959 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6960 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6961 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6962 | }; |
| 6963 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6964 | /** |
| 6965 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6966 | * constant area. |
| 6967 | */ |
| 6968 | class JumpTableRIPFixup : public RIPFixup { |
| 6969 | public: |
| 6970 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 6971 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 6972 | |
| 6973 | void CreateJumpTable() { |
| 6974 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 6975 | |
| 6976 | // Ensure that the reference to the jump table has the correct offset. |
| 6977 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 6978 | SetOffset(offset_in_constant_table); |
| 6979 | |
| 6980 | // The label values in the jump table are computed relative to the |
| 6981 | // instruction addressing the constant area. |
| 6982 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 6983 | |
| 6984 | // Populate the jump table with the correct values for the jump table. |
| 6985 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 6986 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 6987 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 6988 | // The value that we want is the target offset - the position of the table. |
| 6989 | for (int32_t i = 0; i < num_entries; i++) { |
| 6990 | HBasicBlock* b = successors[i]; |
| 6991 | Label* l = codegen_->GetLabelOf(b); |
| 6992 | DCHECK(l->IsBound()); |
| 6993 | int32_t offset_to_block = l->Position() - relative_offset; |
| 6994 | assembler->AppendInt32(offset_to_block); |
| 6995 | } |
| 6996 | } |
| 6997 | |
| 6998 | private: |
| 6999 | const HX86PackedSwitch* switch_instr_; |
| 7000 | }; |
| 7001 | |
| 7002 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7003 | // Generate the constant area if needed. |
| 7004 | X86Assembler* assembler = GetAssembler(); |
| 7005 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7006 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7007 | // byte values. |
| 7008 | assembler->Align(4, 0); |
| 7009 | constant_area_start_ = assembler->CodeSize(); |
| 7010 | |
| 7011 | // Populate any jump tables. |
| 7012 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7013 | jump_table->CreateJumpTable(); |
| 7014 | } |
| 7015 | |
| 7016 | // And now add the constant area to the generated code. |
| 7017 | assembler->AddConstantArea(); |
| 7018 | } |
| 7019 | |
| 7020 | // And finish up. |
| 7021 | CodeGenerator::Finalize(allocator); |
| 7022 | } |
| 7023 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7024 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7025 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7026 | return Address(reg, kDummy32BitOffset, fixup); |
| 7027 | } |
| 7028 | |
| 7029 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7030 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7031 | return Address(reg, kDummy32BitOffset, fixup); |
| 7032 | } |
| 7033 | |
| 7034 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7035 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7036 | return Address(reg, kDummy32BitOffset, fixup); |
| 7037 | } |
| 7038 | |
| 7039 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7040 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7041 | return Address(reg, kDummy32BitOffset, fixup); |
| 7042 | } |
| 7043 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7044 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7045 | Register reg, |
| 7046 | Register value) { |
| 7047 | // Create a fixup to be used to create and address the jump table. |
| 7048 | JumpTableRIPFixup* table_fixup = |
| 7049 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7050 | |
| 7051 | // We have to populate the jump tables. |
| 7052 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7053 | |
| 7054 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7055 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7056 | } |
| 7057 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7058 | // TODO: target as memory. |
| 7059 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7060 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7061 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7062 | return; |
| 7063 | } |
| 7064 | |
| 7065 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7066 | |
| 7067 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7068 | if (target.Equals(return_loc)) { |
| 7069 | return; |
| 7070 | } |
| 7071 | |
| 7072 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7073 | // with the else branch. |
| 7074 | if (type == Primitive::kPrimLong) { |
| 7075 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7076 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7077 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7078 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7079 | } else { |
| 7080 | // Let the parallel move resolver take care of all of this. |
| 7081 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7082 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7083 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7084 | } |
| 7085 | } |
| 7086 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7087 | #undef __ |
| 7088 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7089 | } // namespace x86 |
| 7090 | } // namespace art |