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 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1130 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1131 | DCHECK(location.IsRegister()); |
| 1132 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1133 | } |
| 1134 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1135 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1136 | HParallelMove move(GetGraph()->GetArena()); |
| 1137 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1138 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1139 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1140 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1141 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1142 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1143 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1147 | if (location.IsRegister()) { |
| 1148 | locations->AddTemp(location); |
| 1149 | } else if (location.IsRegisterPair()) { |
| 1150 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1151 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1152 | } else { |
| 1153 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1154 | } |
| 1155 | } |
| 1156 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1157 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1158 | DCHECK(!successor->IsExitBlock()); |
| 1159 | |
| 1160 | HBasicBlock* block = got->GetBlock(); |
| 1161 | HInstruction* previous = got->GetPrevious(); |
| 1162 | |
| 1163 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1164 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1165 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1166 | return; |
| 1167 | } |
| 1168 | |
| 1169 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1170 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1171 | } |
| 1172 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1173 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
| 1176 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1177 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1178 | got->SetLocations(nullptr); |
| 1179 | } |
| 1180 | |
| 1181 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1182 | HandleGoto(got, got->GetSuccessor()); |
| 1183 | } |
| 1184 | |
| 1185 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1186 | try_boundary->SetLocations(nullptr); |
| 1187 | } |
| 1188 | |
| 1189 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1190 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1191 | if (!successor->IsExitBlock()) { |
| 1192 | HandleGoto(try_boundary, successor); |
| 1193 | } |
| 1194 | } |
| 1195 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1196 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1197 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1200 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1203 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1205 | LabelType* true_label, |
| 1206 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1207 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1208 | __ j(kUnordered, true_label); |
| 1209 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1210 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1211 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1212 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1215 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1216 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1217 | LabelType* true_label, |
| 1218 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1219 | LocationSummary* locations = cond->GetLocations(); |
| 1220 | Location left = locations->InAt(0); |
| 1221 | Location right = locations->InAt(1); |
| 1222 | IfCondition if_cond = cond->GetCondition(); |
| 1223 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1224 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1225 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1226 | IfCondition true_high_cond = if_cond; |
| 1227 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1228 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1229 | |
| 1230 | // Set the conditions for the test, remembering that == needs to be |
| 1231 | // decided using the low words. |
| 1232 | switch (if_cond) { |
| 1233 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1234 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1235 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1236 | break; |
| 1237 | case kCondLT: |
| 1238 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1239 | break; |
| 1240 | case kCondLE: |
| 1241 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1242 | break; |
| 1243 | case kCondGT: |
| 1244 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1245 | break; |
| 1246 | case kCondGE: |
| 1247 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1248 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1249 | case kCondB: |
| 1250 | false_high_cond = kCondA; |
| 1251 | break; |
| 1252 | case kCondBE: |
| 1253 | true_high_cond = kCondB; |
| 1254 | break; |
| 1255 | case kCondA: |
| 1256 | false_high_cond = kCondB; |
| 1257 | break; |
| 1258 | case kCondAE: |
| 1259 | true_high_cond = kCondA; |
| 1260 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | if (right.IsConstant()) { |
| 1264 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1265 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1266 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1267 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1268 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1270 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1271 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1272 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1273 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1274 | __ j(X86Condition(true_high_cond), true_label); |
| 1275 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1276 | } |
| 1277 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1278 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1279 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1280 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1281 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1282 | |
| 1283 | __ cmpl(left_high, right_high); |
| 1284 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1285 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1286 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1287 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1288 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1289 | __ j(X86Condition(true_high_cond), true_label); |
| 1290 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1291 | } |
| 1292 | // Must be equal high, so compare the lows. |
| 1293 | __ cmpl(left_low, right_low); |
| 1294 | } |
| 1295 | // The last comparison might be unsigned. |
| 1296 | __ j(final_condition, true_label); |
| 1297 | } |
| 1298 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1299 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1300 | Location rhs, |
| 1301 | HInstruction* insn, |
| 1302 | bool is_double) { |
| 1303 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1304 | if (is_double) { |
| 1305 | if (rhs.IsFpuRegister()) { |
| 1306 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1307 | } else if (const_area != nullptr) { |
| 1308 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1309 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1310 | codegen_->LiteralDoubleAddress( |
| 1311 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1312 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1313 | } else { |
| 1314 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1315 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1316 | } |
| 1317 | } else { |
| 1318 | if (rhs.IsFpuRegister()) { |
| 1319 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1320 | } else if (const_area != nullptr) { |
| 1321 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1322 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1323 | codegen_->LiteralFloatAddress( |
| 1324 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1325 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1326 | } else { |
| 1327 | DCHECK(rhs.IsStackSlot()); |
| 1328 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1333 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1334 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1335 | LabelType* true_target_in, |
| 1336 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1337 | // Generated branching requires both targets to be explicit. If either of the |
| 1338 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1339 | LabelType fallthrough_target; |
| 1340 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1341 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1342 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1343 | LocationSummary* locations = condition->GetLocations(); |
| 1344 | Location left = locations->InAt(0); |
| 1345 | Location right = locations->InAt(1); |
| 1346 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1347 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1348 | switch (type) { |
| 1349 | case Primitive::kPrimLong: |
| 1350 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1351 | break; |
| 1352 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1353 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1354 | GenerateFPJumps(condition, true_target, false_target); |
| 1355 | break; |
| 1356 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1357 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1358 | GenerateFPJumps(condition, true_target, false_target); |
| 1359 | break; |
| 1360 | default: |
| 1361 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1362 | } |
| 1363 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1364 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1365 | __ jmp(false_target); |
| 1366 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1367 | |
| 1368 | if (fallthrough_target.IsLinked()) { |
| 1369 | __ Bind(&fallthrough_target); |
| 1370 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1371 | } |
| 1372 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1373 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1374 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1375 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1376 | // conditions if they are materialized due to the complex branching. |
| 1377 | return cond->IsCondition() && |
| 1378 | cond->GetNext() == branch && |
| 1379 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1380 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1381 | } |
| 1382 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1383 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1384 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1385 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1386 | LabelType* true_target, |
| 1387 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1388 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1389 | |
| 1390 | if (true_target == nullptr && false_target == nullptr) { |
| 1391 | // Nothing to do. The code always falls through. |
| 1392 | return; |
| 1393 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1394 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1395 | if (cond->AsIntConstant()->IsOne()) { |
| 1396 | if (true_target != nullptr) { |
| 1397 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1398 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1399 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1401 | if (false_target != nullptr) { |
| 1402 | __ jmp(false_target); |
| 1403 | } |
| 1404 | } |
| 1405 | return; |
| 1406 | } |
| 1407 | |
| 1408 | // The following code generates these patterns: |
| 1409 | // (1) true_target == nullptr && false_target != nullptr |
| 1410 | // - opposite condition true => branch to false_target |
| 1411 | // (2) true_target != nullptr && false_target == nullptr |
| 1412 | // - condition true => branch to true_target |
| 1413 | // (3) true_target != nullptr && false_target != nullptr |
| 1414 | // - condition true => branch to true_target |
| 1415 | // - branch to false_target |
| 1416 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1417 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1418 | if (true_target == nullptr) { |
| 1419 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1420 | } else { |
| 1421 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1422 | } |
| 1423 | } else { |
| 1424 | // Materialized condition, compare against 0. |
| 1425 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1426 | if (lhs.IsRegister()) { |
| 1427 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1428 | } else { |
| 1429 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1430 | } |
| 1431 | if (true_target == nullptr) { |
| 1432 | __ j(kEqual, false_target); |
| 1433 | } else { |
| 1434 | __ j(kNotEqual, true_target); |
| 1435 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1436 | } |
| 1437 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1438 | // Condition has not been materialized, use its inputs as the comparison and |
| 1439 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1440 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1441 | |
| 1442 | // If this is a long or FP comparison that has been folded into |
| 1443 | // the HCondition, generate the comparison directly. |
| 1444 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1445 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1446 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | Location lhs = condition->GetLocations()->InAt(0); |
| 1451 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1452 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1453 | if (rhs.IsRegister()) { |
| 1454 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1455 | } else if (rhs.IsConstant()) { |
| 1456 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1457 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1458 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1460 | } |
| 1461 | if (true_target == nullptr) { |
| 1462 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1463 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1464 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1465 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1466 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1467 | |
| 1468 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1469 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1470 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1471 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1475 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1477 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1478 | locations->SetInAt(0, Location::Any()); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1483 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1484 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1485 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1486 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1487 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1488 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1489 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1493 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1494 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1495 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1496 | locations->SetInAt(0, Location::Any()); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1501 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1502 | GenerateTestAndBranch<Label>(deoptimize, |
| 1503 | /* condition_input_index */ 0, |
| 1504 | slow_path->GetEntryLabel(), |
| 1505 | /* false_target */ nullptr); |
| 1506 | } |
| 1507 | |
| 1508 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1509 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
| 1510 | Primitive::Type select_type = select->GetType(); |
| 1511 | HInstruction* cond = select->GetCondition(); |
| 1512 | |
| 1513 | if (Primitive::IsFloatingPointType(select_type)) { |
| 1514 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1515 | } else { |
| 1516 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1517 | } |
| 1518 | locations->SetInAt(1, Location::Any()); |
| 1519 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1520 | locations->SetInAt(2, Location::Any()); |
| 1521 | } |
| 1522 | locations->SetOut(Location::SameAsFirstInput()); |
| 1523 | } |
| 1524 | |
| 1525 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1526 | LocationSummary* locations = select->GetLocations(); |
| 1527 | NearLabel false_target; |
| 1528 | GenerateTestAndBranch<NearLabel>( |
| 1529 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1530 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1531 | __ Bind(&false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1534 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1535 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1536 | } |
| 1537 | |
| 1538 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | b7070a2 | 2016-01-08 18:13:53 +0000 | [diff] [blame] | 1539 | if (codegen_->HasStackMapAtCurrentPc()) { |
| 1540 | // Ensure that we do not collide with the stack map of the previous instruction. |
| 1541 | __ nop(); |
| 1542 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1543 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1544 | } |
| 1545 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1546 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1547 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1550 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1551 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1554 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1555 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1558 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1559 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1562 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1563 | LocationSummary* locations = |
| 1564 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1565 | switch (store->InputAt(1)->GetType()) { |
| 1566 | case Primitive::kPrimBoolean: |
| 1567 | case Primitive::kPrimByte: |
| 1568 | case Primitive::kPrimChar: |
| 1569 | case Primitive::kPrimShort: |
| 1570 | case Primitive::kPrimInt: |
| 1571 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1572 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1573 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1574 | break; |
| 1575 | |
| 1576 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1577 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1578 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1579 | break; |
| 1580 | |
| 1581 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1582 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1583 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1586 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1589 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1590 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1591 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1592 | // Handle the long/FP comparisons made in instruction simplification. |
| 1593 | switch (cond->InputAt(0)->GetType()) { |
| 1594 | case Primitive::kPrimLong: { |
| 1595 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1596 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1597 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1598 | locations->SetOut(Location::RequiresRegister()); |
| 1599 | } |
| 1600 | break; |
| 1601 | } |
| 1602 | case Primitive::kPrimFloat: |
| 1603 | case Primitive::kPrimDouble: { |
| 1604 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1605 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1606 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1607 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1608 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1609 | } else { |
| 1610 | locations->SetInAt(1, Location::Any()); |
| 1611 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1612 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1613 | locations->SetOut(Location::RequiresRegister()); |
| 1614 | } |
| 1615 | break; |
| 1616 | } |
| 1617 | default: |
| 1618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1619 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1620 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1621 | // We need a byte register. |
| 1622 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1623 | } |
| 1624 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1625 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1628 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1629 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1630 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1631 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1632 | |
| 1633 | LocationSummary* locations = cond->GetLocations(); |
| 1634 | Location lhs = locations->InAt(0); |
| 1635 | Location rhs = locations->InAt(1); |
| 1636 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1637 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1638 | |
| 1639 | switch (cond->InputAt(0)->GetType()) { |
| 1640 | default: { |
| 1641 | // Integer case. |
| 1642 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1643 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1644 | __ xorl(reg, reg); |
| 1645 | |
| 1646 | if (rhs.IsRegister()) { |
| 1647 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1648 | } else if (rhs.IsConstant()) { |
| 1649 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1650 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1651 | } else { |
| 1652 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1653 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1654 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1655 | return; |
| 1656 | } |
| 1657 | case Primitive::kPrimLong: |
| 1658 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1659 | break; |
| 1660 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1661 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1662 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1663 | break; |
| 1664 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1665 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1666 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1667 | break; |
| 1668 | } |
| 1669 | |
| 1670 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1671 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1672 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1673 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1674 | __ Bind(&false_label); |
| 1675 | __ xorl(reg, reg); |
| 1676 | __ jmp(&done_label); |
| 1677 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1678 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1679 | __ Bind(&true_label); |
| 1680 | __ movl(reg, Immediate(1)); |
| 1681 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1685 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1689 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1693 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1697 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1701 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1705 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1709 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1713 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* 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::VisitGreaterThan(HGreaterThan* 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::VisitGreaterThanOrEqual(HGreaterThanOrEqual* 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::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1729 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1732 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1733 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1737 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1741 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
| 1744 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1745 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1749 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1753 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1757 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1761 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1764 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1765 | LocationSummary* locations = |
| 1766 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1767 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1770 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1771 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1774 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1775 | LocationSummary* locations = |
| 1776 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1777 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1778 | } |
| 1779 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1780 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1781 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1784 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1785 | LocationSummary* locations = |
| 1786 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1787 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1788 | } |
| 1789 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1790 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1791 | // Will be generated at use site. |
| 1792 | } |
| 1793 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1794 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1795 | LocationSummary* locations = |
| 1796 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1797 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1798 | } |
| 1799 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1800 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1801 | // Will be generated at use site. |
| 1802 | } |
| 1803 | |
| 1804 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1805 | LocationSummary* locations = |
| 1806 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1807 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1808 | } |
| 1809 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1810 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1811 | // Will be generated at use site. |
| 1812 | } |
| 1813 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1814 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1815 | memory_barrier->SetLocations(nullptr); |
| 1816 | } |
| 1817 | |
| 1818 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1819 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1822 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1823 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1826 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1827 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1830 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1831 | LocationSummary* locations = |
| 1832 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1833 | switch (ret->InputAt(0)->GetType()) { |
| 1834 | case Primitive::kPrimBoolean: |
| 1835 | case Primitive::kPrimByte: |
| 1836 | case Primitive::kPrimChar: |
| 1837 | case Primitive::kPrimShort: |
| 1838 | case Primitive::kPrimInt: |
| 1839 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1840 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1841 | break; |
| 1842 | |
| 1843 | case Primitive::kPrimLong: |
| 1844 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1845 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1846 | break; |
| 1847 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1848 | case Primitive::kPrimFloat: |
| 1849 | case Primitive::kPrimDouble: |
| 1850 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1851 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1852 | break; |
| 1853 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1854 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1855 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1856 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1859 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1860 | if (kIsDebugBuild) { |
| 1861 | switch (ret->InputAt(0)->GetType()) { |
| 1862 | case Primitive::kPrimBoolean: |
| 1863 | case Primitive::kPrimByte: |
| 1864 | case Primitive::kPrimChar: |
| 1865 | case Primitive::kPrimShort: |
| 1866 | case Primitive::kPrimInt: |
| 1867 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1868 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1869 | break; |
| 1870 | |
| 1871 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1872 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1873 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1874 | break; |
| 1875 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1876 | case Primitive::kPrimFloat: |
| 1877 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1878 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1879 | break; |
| 1880 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1881 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1882 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1883 | } |
| 1884 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1885 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1888 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1889 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1890 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1891 | // the method_idx. |
| 1892 | HandleInvoke(invoke); |
| 1893 | } |
| 1894 | |
| 1895 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1896 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1897 | } |
| 1898 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1899 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1900 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1901 | // art::PrepareForRegisterAllocation. |
| 1902 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1903 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1904 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1905 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1906 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1907 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1908 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1909 | return; |
| 1910 | } |
| 1911 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1912 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1913 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1914 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1915 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1916 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1917 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1918 | } |
| 1919 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1920 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1921 | if (invoke->GetLocations()->Intrinsified()) { |
| 1922 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1923 | intrinsic.Dispatch(invoke); |
| 1924 | return true; |
| 1925 | } |
| 1926 | return false; |
| 1927 | } |
| 1928 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1929 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1930 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1931 | // art::PrepareForRegisterAllocation. |
| 1932 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1933 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1934 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1935 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1936 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1937 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1938 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1939 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1940 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1941 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1945 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1946 | if (intrinsic.TryDispatch(invoke)) { |
| 1947 | return; |
| 1948 | } |
| 1949 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1950 | HandleInvoke(invoke); |
| 1951 | } |
| 1952 | |
| 1953 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1954 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1955 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1958 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1959 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1960 | return; |
| 1961 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1962 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1963 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1964 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1965 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1968 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1969 | // This call to HandleInvoke allocates a temporary (core) register |
| 1970 | // which is also used to transfer the hidden argument from FP to |
| 1971 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1972 | HandleInvoke(invoke); |
| 1973 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1974 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1978 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1979 | LocationSummary* locations = invoke->GetLocations(); |
| 1980 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1981 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1982 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1983 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1984 | Location receiver = locations->InAt(0); |
| 1985 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1986 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1987 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 1988 | // won't be modified thereafter, before the `call` instruction. |
| 1989 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1990 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1991 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1992 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1993 | if (receiver.IsStackSlot()) { |
| 1994 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1995 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1996 | __ movl(temp, Address(temp, class_offset)); |
| 1997 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1998 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1999 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2000 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2001 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2002 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2003 | // emit a read barrier for the previous class reference load. |
| 2004 | // However this is not required in practice, as this is an |
| 2005 | // intermediate/temporary reference and because the current |
| 2006 | // concurrent copying collector keeps the from-space memory |
| 2007 | // intact/accessible until the end of the marking phase (the |
| 2008 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2009 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2010 | // temp = temp->GetImtEntryAt(method_offset); |
| 2011 | __ movl(temp, Address(temp, method_offset)); |
| 2012 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2013 | __ call(Address(temp, |
| 2014 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2015 | |
| 2016 | DCHECK(!codegen_->IsLeafMethod()); |
| 2017 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2018 | } |
| 2019 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2020 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2021 | LocationSummary* locations = |
| 2022 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2023 | switch (neg->GetResultType()) { |
| 2024 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2025 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2026 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2027 | locations->SetOut(Location::SameAsFirstInput()); |
| 2028 | break; |
| 2029 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2030 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2031 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2032 | locations->SetOut(Location::SameAsFirstInput()); |
| 2033 | locations->AddTemp(Location::RequiresRegister()); |
| 2034 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2035 | break; |
| 2036 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2037 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2038 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2039 | locations->SetOut(Location::SameAsFirstInput()); |
| 2040 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2041 | break; |
| 2042 | |
| 2043 | default: |
| 2044 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2049 | LocationSummary* locations = neg->GetLocations(); |
| 2050 | Location out = locations->Out(); |
| 2051 | Location in = locations->InAt(0); |
| 2052 | switch (neg->GetResultType()) { |
| 2053 | case Primitive::kPrimInt: |
| 2054 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2055 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2056 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2057 | break; |
| 2058 | |
| 2059 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2060 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2061 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2062 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2063 | // Negation is similar to subtraction from zero. The least |
| 2064 | // significant byte triggers a borrow when it is different from |
| 2065 | // zero; to take it into account, add 1 to the most significant |
| 2066 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2067 | // operation. |
| 2068 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2069 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2070 | break; |
| 2071 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2072 | case Primitive::kPrimFloat: { |
| 2073 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2074 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2075 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2076 | // Implement float negation with an exclusive or with value |
| 2077 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2078 | // single-precision floating-point number). |
| 2079 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2080 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2081 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2082 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2083 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2084 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2085 | case Primitive::kPrimDouble: { |
| 2086 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2087 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2088 | // Implement double negation with an exclusive or with value |
| 2089 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2090 | // a double-precision floating-point number). |
| 2091 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2092 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2093 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2094 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2095 | |
| 2096 | default: |
| 2097 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2098 | } |
| 2099 | } |
| 2100 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2101 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2102 | LocationSummary* locations = |
| 2103 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2104 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2105 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2106 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2107 | locations->SetOut(Location::SameAsFirstInput()); |
| 2108 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2109 | } |
| 2110 | |
| 2111 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2112 | LocationSummary* locations = neg->GetLocations(); |
| 2113 | Location out = locations->Out(); |
| 2114 | DCHECK(locations->InAt(0).Equals(out)); |
| 2115 | |
| 2116 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2117 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2118 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2119 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2120 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2121 | } else { |
| 2122 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2123 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2124 | } |
| 2125 | } |
| 2126 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2127 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2128 | Primitive::Type result_type = conversion->GetResultType(); |
| 2129 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2130 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2131 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2132 | // The float-to-long and double-to-long type conversions rely on a |
| 2133 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2134 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2135 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2136 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2137 | ? LocationSummary::kCall |
| 2138 | : LocationSummary::kNoCall; |
| 2139 | LocationSummary* locations = |
| 2140 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2141 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2142 | // The Java language does not allow treating boolean as an integral type but |
| 2143 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2144 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2145 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimByte: |
| 2147 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2148 | case Primitive::kPrimLong: { |
| 2149 | // Type conversion from long to byte is a result of code transformations. |
| 2150 | HInstruction* input = conversion->InputAt(0); |
| 2151 | Location input_location = input->IsConstant() |
| 2152 | ? Location::ConstantLocation(input->AsConstant()) |
| 2153 | : Location::RegisterPairLocation(EAX, EDX); |
| 2154 | locations->SetInAt(0, input_location); |
| 2155 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2156 | // the validation of the linear scan implementation |
| 2157 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2158 | break; |
| 2159 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2160 | case Primitive::kPrimBoolean: |
| 2161 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2162 | case Primitive::kPrimShort: |
| 2163 | case Primitive::kPrimInt: |
| 2164 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2165 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2166 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2167 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2168 | // the validation of the linear scan implementation |
| 2169 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | |
| 2172 | default: |
| 2173 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2174 | << " to " << result_type; |
| 2175 | } |
| 2176 | break; |
| 2177 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimShort: |
| 2179 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimLong: |
| 2181 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimBoolean: |
| 2183 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2184 | case Primitive::kPrimByte: |
| 2185 | case Primitive::kPrimInt: |
| 2186 | case Primitive::kPrimChar: |
| 2187 | // Processing a Dex `int-to-short' instruction. |
| 2188 | locations->SetInAt(0, Location::Any()); |
| 2189 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2190 | break; |
| 2191 | |
| 2192 | default: |
| 2193 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2194 | << " to " << result_type; |
| 2195 | } |
| 2196 | break; |
| 2197 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2198 | case Primitive::kPrimInt: |
| 2199 | switch (input_type) { |
| 2200 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2201 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2202 | locations->SetInAt(0, Location::Any()); |
| 2203 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2204 | break; |
| 2205 | |
| 2206 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2207 | // Processing a Dex `float-to-int' instruction. |
| 2208 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2209 | locations->SetOut(Location::RequiresRegister()); |
| 2210 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2211 | break; |
| 2212 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2214 | // Processing a Dex `double-to-int' instruction. |
| 2215 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2216 | locations->SetOut(Location::RequiresRegister()); |
| 2217 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2218 | break; |
| 2219 | |
| 2220 | default: |
| 2221 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2222 | << " to " << result_type; |
| 2223 | } |
| 2224 | break; |
| 2225 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2226 | case Primitive::kPrimLong: |
| 2227 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2228 | case Primitive::kPrimBoolean: |
| 2229 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimByte: |
| 2231 | case Primitive::kPrimShort: |
| 2232 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2233 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2234 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2235 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2236 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2237 | break; |
| 2238 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2239 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2240 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2241 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2242 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2243 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2244 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2245 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2246 | // The runtime helper puts the result in EAX, EDX. |
| 2247 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2248 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2249 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2250 | |
| 2251 | default: |
| 2252 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2253 | << " to " << result_type; |
| 2254 | } |
| 2255 | break; |
| 2256 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2257 | case Primitive::kPrimChar: |
| 2258 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimLong: |
| 2260 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimBoolean: |
| 2262 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimByte: |
| 2264 | case Primitive::kPrimShort: |
| 2265 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2266 | // Processing a Dex `int-to-char' instruction. |
| 2267 | locations->SetInAt(0, Location::Any()); |
| 2268 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2269 | break; |
| 2270 | |
| 2271 | default: |
| 2272 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2273 | << " to " << result_type; |
| 2274 | } |
| 2275 | break; |
| 2276 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2277 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2278 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2279 | case Primitive::kPrimBoolean: |
| 2280 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2281 | case Primitive::kPrimByte: |
| 2282 | case Primitive::kPrimShort: |
| 2283 | case Primitive::kPrimInt: |
| 2284 | case Primitive::kPrimChar: |
| 2285 | // Processing a Dex `int-to-float' instruction. |
| 2286 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2287 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2288 | break; |
| 2289 | |
| 2290 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2291 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2292 | locations->SetInAt(0, Location::Any()); |
| 2293 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2294 | break; |
| 2295 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2296 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2297 | // Processing a Dex `double-to-float' instruction. |
| 2298 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2299 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2300 | break; |
| 2301 | |
| 2302 | default: |
| 2303 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2304 | << " to " << result_type; |
| 2305 | }; |
| 2306 | break; |
| 2307 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2308 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2309 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimBoolean: |
| 2311 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimByte: |
| 2313 | case Primitive::kPrimShort: |
| 2314 | case Primitive::kPrimInt: |
| 2315 | case Primitive::kPrimChar: |
| 2316 | // Processing a Dex `int-to-double' instruction. |
| 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2318 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2319 | break; |
| 2320 | |
| 2321 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2322 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2323 | locations->SetInAt(0, Location::Any()); |
| 2324 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2325 | break; |
| 2326 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2328 | // Processing a Dex `float-to-double' instruction. |
| 2329 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2330 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2331 | break; |
| 2332 | |
| 2333 | default: |
| 2334 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2335 | << " to " << result_type; |
| 2336 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2337 | break; |
| 2338 | |
| 2339 | default: |
| 2340 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2341 | << " to " << result_type; |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2346 | LocationSummary* locations = conversion->GetLocations(); |
| 2347 | Location out = locations->Out(); |
| 2348 | Location in = locations->InAt(0); |
| 2349 | Primitive::Type result_type = conversion->GetResultType(); |
| 2350 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2351 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2352 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2353 | case Primitive::kPrimByte: |
| 2354 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2355 | case Primitive::kPrimLong: |
| 2356 | // Type conversion from long to byte is a result of code transformations. |
| 2357 | if (in.IsRegisterPair()) { |
| 2358 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2359 | } else { |
| 2360 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2361 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2362 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2363 | } |
| 2364 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2365 | case Primitive::kPrimBoolean: |
| 2366 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2367 | case Primitive::kPrimShort: |
| 2368 | case Primitive::kPrimInt: |
| 2369 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2370 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2371 | if (in.IsRegister()) { |
| 2372 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2373 | } else { |
| 2374 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2375 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2376 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2377 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | |
| 2380 | default: |
| 2381 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2382 | << " to " << result_type; |
| 2383 | } |
| 2384 | break; |
| 2385 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2386 | case Primitive::kPrimShort: |
| 2387 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2388 | case Primitive::kPrimLong: |
| 2389 | // Type conversion from long to short is a result of code transformations. |
| 2390 | if (in.IsRegisterPair()) { |
| 2391 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2392 | } else if (in.IsDoubleStackSlot()) { |
| 2393 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2394 | } else { |
| 2395 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2396 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2397 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2398 | } |
| 2399 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2400 | case Primitive::kPrimBoolean: |
| 2401 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2402 | case Primitive::kPrimByte: |
| 2403 | case Primitive::kPrimInt: |
| 2404 | case Primitive::kPrimChar: |
| 2405 | // Processing a Dex `int-to-short' instruction. |
| 2406 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2407 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2408 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2409 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2410 | } else { |
| 2411 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2412 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2413 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2414 | } |
| 2415 | break; |
| 2416 | |
| 2417 | default: |
| 2418 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2419 | << " to " << result_type; |
| 2420 | } |
| 2421 | break; |
| 2422 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2423 | case Primitive::kPrimInt: |
| 2424 | switch (input_type) { |
| 2425 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2426 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2427 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2428 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2429 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2430 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2431 | } else { |
| 2432 | DCHECK(in.IsConstant()); |
| 2433 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2434 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2435 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2436 | } |
| 2437 | break; |
| 2438 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2439 | case Primitive::kPrimFloat: { |
| 2440 | // Processing a Dex `float-to-int' instruction. |
| 2441 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2442 | Register output = out.AsRegister<Register>(); |
| 2443 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2444 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2445 | |
| 2446 | __ movl(output, Immediate(kPrimIntMax)); |
| 2447 | // temp = int-to-float(output) |
| 2448 | __ cvtsi2ss(temp, output); |
| 2449 | // if input >= temp goto done |
| 2450 | __ comiss(input, temp); |
| 2451 | __ j(kAboveEqual, &done); |
| 2452 | // if input == NaN goto nan |
| 2453 | __ j(kUnordered, &nan); |
| 2454 | // output = float-to-int-truncate(input) |
| 2455 | __ cvttss2si(output, input); |
| 2456 | __ jmp(&done); |
| 2457 | __ Bind(&nan); |
| 2458 | // output = 0 |
| 2459 | __ xorl(output, output); |
| 2460 | __ Bind(&done); |
| 2461 | break; |
| 2462 | } |
| 2463 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2464 | case Primitive::kPrimDouble: { |
| 2465 | // Processing a Dex `double-to-int' instruction. |
| 2466 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2467 | Register output = out.AsRegister<Register>(); |
| 2468 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2469 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2470 | |
| 2471 | __ movl(output, Immediate(kPrimIntMax)); |
| 2472 | // temp = int-to-double(output) |
| 2473 | __ cvtsi2sd(temp, output); |
| 2474 | // if input >= temp goto done |
| 2475 | __ comisd(input, temp); |
| 2476 | __ j(kAboveEqual, &done); |
| 2477 | // if input == NaN goto nan |
| 2478 | __ j(kUnordered, &nan); |
| 2479 | // output = double-to-int-truncate(input) |
| 2480 | __ cvttsd2si(output, input); |
| 2481 | __ jmp(&done); |
| 2482 | __ Bind(&nan); |
| 2483 | // output = 0 |
| 2484 | __ xorl(output, output); |
| 2485 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2486 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2487 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2488 | |
| 2489 | default: |
| 2490 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2491 | << " to " << result_type; |
| 2492 | } |
| 2493 | break; |
| 2494 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimLong: |
| 2496 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimBoolean: |
| 2498 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2499 | case Primitive::kPrimByte: |
| 2500 | case Primitive::kPrimShort: |
| 2501 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2502 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2503 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2504 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2505 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2506 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2507 | __ cdq(); |
| 2508 | break; |
| 2509 | |
| 2510 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2511 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2512 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2513 | conversion, |
| 2514 | conversion->GetDexPc(), |
| 2515 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2516 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2517 | break; |
| 2518 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2519 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2520 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2521 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2522 | conversion, |
| 2523 | conversion->GetDexPc(), |
| 2524 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2525 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2526 | break; |
| 2527 | |
| 2528 | default: |
| 2529 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2530 | << " to " << result_type; |
| 2531 | } |
| 2532 | break; |
| 2533 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2534 | case Primitive::kPrimChar: |
| 2535 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2536 | case Primitive::kPrimLong: |
| 2537 | // Type conversion from long to short is a result of code transformations. |
| 2538 | if (in.IsRegisterPair()) { |
| 2539 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2540 | } else if (in.IsDoubleStackSlot()) { |
| 2541 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2542 | } else { |
| 2543 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2544 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2545 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2546 | } |
| 2547 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2548 | case Primitive::kPrimBoolean: |
| 2549 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimByte: |
| 2551 | case Primitive::kPrimShort: |
| 2552 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2553 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2554 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2555 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2556 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2557 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2558 | } else { |
| 2559 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2560 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2561 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2562 | } |
| 2563 | break; |
| 2564 | |
| 2565 | default: |
| 2566 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2567 | << " to " << result_type; |
| 2568 | } |
| 2569 | break; |
| 2570 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2571 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2572 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2573 | case Primitive::kPrimBoolean: |
| 2574 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2575 | case Primitive::kPrimByte: |
| 2576 | case Primitive::kPrimShort: |
| 2577 | case Primitive::kPrimInt: |
| 2578 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2579 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2580 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2581 | break; |
| 2582 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimLong: { |
| 2584 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2585 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2586 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2587 | // Create stack space for the call to |
| 2588 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2589 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2590 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2591 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2592 | __ subl(ESP, Immediate(adjustment)); |
| 2593 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2594 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2595 | // Load the value to the FP stack, using temporaries if needed. |
| 2596 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2597 | |
| 2598 | if (out.IsStackSlot()) { |
| 2599 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2600 | } else { |
| 2601 | __ fstps(Address(ESP, 0)); |
| 2602 | Location stack_temp = Location::StackSlot(0); |
| 2603 | codegen_->Move32(out, stack_temp); |
| 2604 | } |
| 2605 | |
| 2606 | // Remove the temporary stack space we allocated. |
| 2607 | if (adjustment != 0) { |
| 2608 | __ addl(ESP, Immediate(adjustment)); |
| 2609 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2610 | break; |
| 2611 | } |
| 2612 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2613 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2614 | // Processing a Dex `double-to-float' instruction. |
| 2615 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2616 | break; |
| 2617 | |
| 2618 | default: |
| 2619 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2620 | << " to " << result_type; |
| 2621 | }; |
| 2622 | break; |
| 2623 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2624 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2625 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2626 | case Primitive::kPrimBoolean: |
| 2627 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2628 | case Primitive::kPrimByte: |
| 2629 | case Primitive::kPrimShort: |
| 2630 | case Primitive::kPrimInt: |
| 2631 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2632 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2633 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2634 | break; |
| 2635 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2636 | case Primitive::kPrimLong: { |
| 2637 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2638 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2639 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2640 | // Create stack space for the call to |
| 2641 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2642 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2643 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2644 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2645 | __ subl(ESP, Immediate(adjustment)); |
| 2646 | } |
| 2647 | |
| 2648 | // Load the value to the FP stack, using temporaries if needed. |
| 2649 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2650 | |
| 2651 | if (out.IsDoubleStackSlot()) { |
| 2652 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2653 | } else { |
| 2654 | __ fstpl(Address(ESP, 0)); |
| 2655 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2656 | codegen_->Move64(out, stack_temp); |
| 2657 | } |
| 2658 | |
| 2659 | // Remove the temporary stack space we allocated. |
| 2660 | if (adjustment != 0) { |
| 2661 | __ addl(ESP, Immediate(adjustment)); |
| 2662 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2663 | break; |
| 2664 | } |
| 2665 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2667 | // Processing a Dex `float-to-double' instruction. |
| 2668 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2669 | break; |
| 2670 | |
| 2671 | default: |
| 2672 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2673 | << " to " << result_type; |
| 2674 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2675 | break; |
| 2676 | |
| 2677 | default: |
| 2678 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2679 | << " to " << result_type; |
| 2680 | } |
| 2681 | } |
| 2682 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2683 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2684 | LocationSummary* locations = |
| 2685 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2686 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2687 | case Primitive::kPrimInt: { |
| 2688 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2689 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2690 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2691 | break; |
| 2692 | } |
| 2693 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2694 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2695 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2696 | locations->SetInAt(1, Location::Any()); |
| 2697 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2701 | case Primitive::kPrimFloat: |
| 2702 | case Primitive::kPrimDouble: { |
| 2703 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2704 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2705 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2706 | } else if (add->InputAt(1)->IsConstant()) { |
| 2707 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2708 | } else { |
| 2709 | locations->SetInAt(1, Location::Any()); |
| 2710 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2711 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2712 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2713 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2714 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2715 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2716 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2717 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2718 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2722 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2723 | Location first = locations->InAt(0); |
| 2724 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2725 | Location out = locations->Out(); |
| 2726 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2727 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2728 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2729 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2730 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2731 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2732 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2733 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2734 | } else { |
| 2735 | __ leal(out.AsRegister<Register>(), Address( |
| 2736 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2737 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2738 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2739 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2740 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2741 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2742 | } else { |
| 2743 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2744 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2745 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2746 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2747 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2748 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2749 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2753 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2754 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2755 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2756 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2757 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2758 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2759 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2760 | } else { |
| 2761 | DCHECK(second.IsConstant()) << second; |
| 2762 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2763 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2764 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2765 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2766 | break; |
| 2767 | } |
| 2768 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2769 | case Primitive::kPrimFloat: { |
| 2770 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2771 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2772 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2773 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2774 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2775 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2776 | codegen_->LiteralFloatAddress( |
| 2777 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2778 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2779 | } else { |
| 2780 | DCHECK(second.IsStackSlot()); |
| 2781 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2782 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2783 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | case Primitive::kPrimDouble: { |
| 2787 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2788 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2789 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2790 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2791 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2792 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2793 | codegen_->LiteralDoubleAddress( |
| 2794 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2795 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2796 | } else { |
| 2797 | DCHECK(second.IsDoubleStackSlot()); |
| 2798 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2799 | } |
| 2800 | break; |
| 2801 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2802 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2803 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2804 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2805 | } |
| 2806 | } |
| 2807 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2808 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2809 | LocationSummary* locations = |
| 2810 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2811 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2812 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2813 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2814 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2815 | locations->SetInAt(1, Location::Any()); |
| 2816 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2817 | break; |
| 2818 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2819 | case Primitive::kPrimFloat: |
| 2820 | case Primitive::kPrimDouble: { |
| 2821 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2822 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2823 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2824 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2825 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2826 | } else { |
| 2827 | locations->SetInAt(1, Location::Any()); |
| 2828 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2829 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2830 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2831 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2832 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2833 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2834 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2835 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2839 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2840 | Location first = locations->InAt(0); |
| 2841 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2842 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2843 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2844 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2845 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2846 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2847 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2848 | __ subl(first.AsRegister<Register>(), |
| 2849 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2850 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2851 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2852 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2853 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2857 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2858 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2859 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2860 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2861 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2862 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2863 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2864 | } else { |
| 2865 | DCHECK(second.IsConstant()) << second; |
| 2866 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2867 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2868 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2869 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2870 | break; |
| 2871 | } |
| 2872 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2873 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2874 | if (second.IsFpuRegister()) { |
| 2875 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2876 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2877 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2878 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2879 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2880 | codegen_->LiteralFloatAddress( |
| 2881 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2882 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2883 | } else { |
| 2884 | DCHECK(second.IsStackSlot()); |
| 2885 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2886 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2887 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2891 | if (second.IsFpuRegister()) { |
| 2892 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2893 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2894 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2895 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2896 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2897 | codegen_->LiteralDoubleAddress( |
| 2898 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2899 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2900 | } else { |
| 2901 | DCHECK(second.IsDoubleStackSlot()); |
| 2902 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2903 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2904 | break; |
| 2905 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2906 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2907 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2908 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2909 | } |
| 2910 | } |
| 2911 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2912 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2913 | LocationSummary* locations = |
| 2914 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2915 | switch (mul->GetResultType()) { |
| 2916 | case Primitive::kPrimInt: |
| 2917 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2918 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2919 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2920 | // Can use 3 operand multiply. |
| 2921 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2922 | } else { |
| 2923 | locations->SetOut(Location::SameAsFirstInput()); |
| 2924 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2925 | break; |
| 2926 | case Primitive::kPrimLong: { |
| 2927 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2928 | locations->SetInAt(1, Location::Any()); |
| 2929 | locations->SetOut(Location::SameAsFirstInput()); |
| 2930 | // Needed for imul on 32bits with 64bits output. |
| 2931 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2932 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2933 | break; |
| 2934 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2935 | case Primitive::kPrimFloat: |
| 2936 | case Primitive::kPrimDouble: { |
| 2937 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2938 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2939 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2940 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2941 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2942 | } else { |
| 2943 | locations->SetInAt(1, Location::Any()); |
| 2944 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2945 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2946 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2947 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2948 | |
| 2949 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2950 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2955 | LocationSummary* locations = mul->GetLocations(); |
| 2956 | Location first = locations->InAt(0); |
| 2957 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2958 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2959 | |
| 2960 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2961 | case Primitive::kPrimInt: |
| 2962 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2963 | // problems where the output may not be the same as the first operand. |
| 2964 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2965 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2966 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2967 | } else if (second.IsRegister()) { |
| 2968 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2969 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2970 | } else { |
| 2971 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2972 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2973 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2974 | } |
| 2975 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2976 | |
| 2977 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2978 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2979 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2980 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2981 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2982 | |
| 2983 | DCHECK_EQ(EAX, eax); |
| 2984 | DCHECK_EQ(EDX, edx); |
| 2985 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2986 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2987 | // output: in1 |
| 2988 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2989 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2990 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2991 | if (second.IsConstant()) { |
| 2992 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2993 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2994 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2995 | int32_t low_value = Low32Bits(value); |
| 2996 | int32_t high_value = High32Bits(value); |
| 2997 | Immediate low(low_value); |
| 2998 | Immediate high(high_value); |
| 2999 | |
| 3000 | __ movl(eax, high); |
| 3001 | // eax <- in1.lo * in2.hi |
| 3002 | __ imull(eax, in1_lo); |
| 3003 | // in1.hi <- in1.hi * in2.lo |
| 3004 | __ imull(in1_hi, low); |
| 3005 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3006 | __ addl(in1_hi, eax); |
| 3007 | // move in2_lo to eax to prepare for double precision |
| 3008 | __ movl(eax, low); |
| 3009 | // edx:eax <- in1.lo * in2.lo |
| 3010 | __ mull(in1_lo); |
| 3011 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3012 | __ addl(in1_hi, edx); |
| 3013 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3014 | __ movl(in1_lo, eax); |
| 3015 | } else if (second.IsRegisterPair()) { |
| 3016 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3017 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3018 | |
| 3019 | __ movl(eax, in2_hi); |
| 3020 | // eax <- in1.lo * in2.hi |
| 3021 | __ imull(eax, in1_lo); |
| 3022 | // in1.hi <- in1.hi * in2.lo |
| 3023 | __ imull(in1_hi, in2_lo); |
| 3024 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3025 | __ addl(in1_hi, eax); |
| 3026 | // move in1_lo to eax to prepare for double precision |
| 3027 | __ movl(eax, in1_lo); |
| 3028 | // edx:eax <- in1.lo * in2.lo |
| 3029 | __ mull(in2_lo); |
| 3030 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3031 | __ addl(in1_hi, edx); |
| 3032 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3033 | __ movl(in1_lo, eax); |
| 3034 | } else { |
| 3035 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3036 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3037 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3038 | |
| 3039 | __ movl(eax, in2_hi); |
| 3040 | // eax <- in1.lo * in2.hi |
| 3041 | __ imull(eax, in1_lo); |
| 3042 | // in1.hi <- in1.hi * in2.lo |
| 3043 | __ imull(in1_hi, in2_lo); |
| 3044 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3045 | __ addl(in1_hi, eax); |
| 3046 | // move in1_lo to eax to prepare for double precision |
| 3047 | __ movl(eax, in1_lo); |
| 3048 | // edx:eax <- in1.lo * in2.lo |
| 3049 | __ mull(in2_lo); |
| 3050 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3051 | __ addl(in1_hi, edx); |
| 3052 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3053 | __ movl(in1_lo, eax); |
| 3054 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3055 | |
| 3056 | break; |
| 3057 | } |
| 3058 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3059 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3060 | DCHECK(first.Equals(locations->Out())); |
| 3061 | if (second.IsFpuRegister()) { |
| 3062 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3063 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3064 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3065 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3066 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3067 | codegen_->LiteralFloatAddress( |
| 3068 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3069 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3070 | } else { |
| 3071 | DCHECK(second.IsStackSlot()); |
| 3072 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3073 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3074 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3078 | DCHECK(first.Equals(locations->Out())); |
| 3079 | if (second.IsFpuRegister()) { |
| 3080 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3081 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3082 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3083 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3084 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3085 | codegen_->LiteralDoubleAddress( |
| 3086 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3087 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3088 | } else { |
| 3089 | DCHECK(second.IsDoubleStackSlot()); |
| 3090 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3091 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3092 | break; |
| 3093 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3094 | |
| 3095 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3096 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3100 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3101 | uint32_t temp_offset, |
| 3102 | uint32_t stack_adjustment, |
| 3103 | bool is_fp, |
| 3104 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3105 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3106 | DCHECK(!is_wide); |
| 3107 | if (is_fp) { |
| 3108 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3109 | } else { |
| 3110 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3111 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3112 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3113 | DCHECK(is_wide); |
| 3114 | if (is_fp) { |
| 3115 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3116 | } else { |
| 3117 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3118 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3119 | } else { |
| 3120 | // 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] | 3121 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3122 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3123 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3124 | if (is_fp) { |
| 3125 | __ flds(Address(ESP, temp_offset)); |
| 3126 | } else { |
| 3127 | __ filds(Address(ESP, temp_offset)); |
| 3128 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3129 | } else { |
| 3130 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3131 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3132 | if (is_fp) { |
| 3133 | __ fldl(Address(ESP, temp_offset)); |
| 3134 | } else { |
| 3135 | __ fildl(Address(ESP, temp_offset)); |
| 3136 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3137 | } |
| 3138 | } |
| 3139 | } |
| 3140 | |
| 3141 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3142 | Primitive::Type type = rem->GetResultType(); |
| 3143 | bool is_float = type == Primitive::kPrimFloat; |
| 3144 | size_t elem_size = Primitive::ComponentSize(type); |
| 3145 | LocationSummary* locations = rem->GetLocations(); |
| 3146 | Location first = locations->InAt(0); |
| 3147 | Location second = locations->InAt(1); |
| 3148 | Location out = locations->Out(); |
| 3149 | |
| 3150 | // Create stack space for 2 elements. |
| 3151 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3152 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3153 | |
| 3154 | // 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] | 3155 | const bool is_wide = !is_float; |
| 3156 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3157 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3158 | |
| 3159 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3160 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3161 | __ Bind(&retry); |
| 3162 | __ fprem(); |
| 3163 | |
| 3164 | // Move FP status to AX. |
| 3165 | __ fstsw(); |
| 3166 | |
| 3167 | // And see if the argument reduction is complete. This is signaled by the |
| 3168 | // C2 FPU flag bit set to 0. |
| 3169 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3170 | __ j(kNotEqual, &retry); |
| 3171 | |
| 3172 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3173 | // Store FP top of stack to real stack. |
| 3174 | if (is_float) { |
| 3175 | __ fsts(Address(ESP, 0)); |
| 3176 | } else { |
| 3177 | __ fstl(Address(ESP, 0)); |
| 3178 | } |
| 3179 | |
| 3180 | // Pop the 2 items from the FP stack. |
| 3181 | __ fucompp(); |
| 3182 | |
| 3183 | // Load the value from the stack into an XMM register. |
| 3184 | DCHECK(out.IsFpuRegister()) << out; |
| 3185 | if (is_float) { |
| 3186 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3187 | } else { |
| 3188 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3189 | } |
| 3190 | |
| 3191 | // And remove the temporary stack space we allocated. |
| 3192 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3193 | } |
| 3194 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3195 | |
| 3196 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3197 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3198 | |
| 3199 | LocationSummary* locations = instruction->GetLocations(); |
| 3200 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3201 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3202 | |
| 3203 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3204 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3205 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3206 | |
| 3207 | DCHECK(imm == 1 || imm == -1); |
| 3208 | |
| 3209 | if (instruction->IsRem()) { |
| 3210 | __ xorl(out_register, out_register); |
| 3211 | } else { |
| 3212 | __ movl(out_register, input_register); |
| 3213 | if (imm == -1) { |
| 3214 | __ negl(out_register); |
| 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3220 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3221 | LocationSummary* locations = instruction->GetLocations(); |
| 3222 | |
| 3223 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3224 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3225 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3226 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3227 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3228 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3229 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3230 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3231 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3232 | __ testl(input_register, input_register); |
| 3233 | __ cmovl(kGreaterEqual, num, input_register); |
| 3234 | int shift = CTZ(imm); |
| 3235 | __ sarl(num, Immediate(shift)); |
| 3236 | |
| 3237 | if (imm < 0) { |
| 3238 | __ negl(num); |
| 3239 | } |
| 3240 | |
| 3241 | __ movl(out_register, num); |
| 3242 | } |
| 3243 | |
| 3244 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3245 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3246 | |
| 3247 | LocationSummary* locations = instruction->GetLocations(); |
| 3248 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3249 | |
| 3250 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3251 | Register out = locations->Out().AsRegister<Register>(); |
| 3252 | Register num; |
| 3253 | Register edx; |
| 3254 | |
| 3255 | if (instruction->IsDiv()) { |
| 3256 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3257 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3258 | } else { |
| 3259 | edx = locations->Out().AsRegister<Register>(); |
| 3260 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3261 | } |
| 3262 | |
| 3263 | DCHECK_EQ(EAX, eax); |
| 3264 | DCHECK_EQ(EDX, edx); |
| 3265 | if (instruction->IsDiv()) { |
| 3266 | DCHECK_EQ(EAX, out); |
| 3267 | } else { |
| 3268 | DCHECK_EQ(EDX, out); |
| 3269 | } |
| 3270 | |
| 3271 | int64_t magic; |
| 3272 | int shift; |
| 3273 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3274 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3275 | NearLabel ndiv; |
| 3276 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3277 | // If numerator is 0, the result is 0, no computation needed. |
| 3278 | __ testl(eax, eax); |
| 3279 | __ j(kNotEqual, &ndiv); |
| 3280 | |
| 3281 | __ xorl(out, out); |
| 3282 | __ jmp(&end); |
| 3283 | |
| 3284 | __ Bind(&ndiv); |
| 3285 | |
| 3286 | // Save the numerator. |
| 3287 | __ movl(num, eax); |
| 3288 | |
| 3289 | // EAX = magic |
| 3290 | __ movl(eax, Immediate(magic)); |
| 3291 | |
| 3292 | // EDX:EAX = magic * numerator |
| 3293 | __ imull(num); |
| 3294 | |
| 3295 | if (imm > 0 && magic < 0) { |
| 3296 | // EDX += num |
| 3297 | __ addl(edx, num); |
| 3298 | } else if (imm < 0 && magic > 0) { |
| 3299 | __ subl(edx, num); |
| 3300 | } |
| 3301 | |
| 3302 | // Shift if needed. |
| 3303 | if (shift != 0) { |
| 3304 | __ sarl(edx, Immediate(shift)); |
| 3305 | } |
| 3306 | |
| 3307 | // EDX += 1 if EDX < 0 |
| 3308 | __ movl(eax, edx); |
| 3309 | __ shrl(edx, Immediate(31)); |
| 3310 | __ addl(edx, eax); |
| 3311 | |
| 3312 | if (instruction->IsRem()) { |
| 3313 | __ movl(eax, num); |
| 3314 | __ imull(edx, Immediate(imm)); |
| 3315 | __ subl(eax, edx); |
| 3316 | __ movl(edx, eax); |
| 3317 | } else { |
| 3318 | __ movl(eax, edx); |
| 3319 | } |
| 3320 | __ Bind(&end); |
| 3321 | } |
| 3322 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3323 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3324 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3325 | |
| 3326 | LocationSummary* locations = instruction->GetLocations(); |
| 3327 | Location out = locations->Out(); |
| 3328 | Location first = locations->InAt(0); |
| 3329 | Location second = locations->InAt(1); |
| 3330 | bool is_div = instruction->IsDiv(); |
| 3331 | |
| 3332 | switch (instruction->GetResultType()) { |
| 3333 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3334 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3335 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3336 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3337 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3338 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3339 | |
| 3340 | if (imm == 0) { |
| 3341 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3342 | } else if (imm == 1 || imm == -1) { |
| 3343 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3344 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3345 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3346 | } else { |
| 3347 | DCHECK(imm <= -2 || imm >= 2); |
| 3348 | GenerateDivRemWithAnyConstant(instruction); |
| 3349 | } |
| 3350 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3351 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3352 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3353 | is_div); |
| 3354 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3355 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3356 | Register second_reg = second.AsRegister<Register>(); |
| 3357 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3358 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3359 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3360 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3361 | __ cmpl(second_reg, Immediate(-1)); |
| 3362 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3363 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3364 | // edx:eax <- sign-extended of eax |
| 3365 | __ cdq(); |
| 3366 | // eax = quotient, edx = remainder |
| 3367 | __ idivl(second_reg); |
| 3368 | __ Bind(slow_path->GetExitLabel()); |
| 3369 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3370 | break; |
| 3371 | } |
| 3372 | |
| 3373 | case Primitive::kPrimLong: { |
| 3374 | InvokeRuntimeCallingConvention calling_convention; |
| 3375 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3376 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3377 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3378 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3379 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3380 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3381 | |
| 3382 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3383 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3384 | instruction, |
| 3385 | instruction->GetDexPc(), |
| 3386 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3387 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3388 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3389 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3390 | instruction, |
| 3391 | instruction->GetDexPc(), |
| 3392 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3393 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3394 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3395 | break; |
| 3396 | } |
| 3397 | |
| 3398 | default: |
| 3399 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3400 | } |
| 3401 | } |
| 3402 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3403 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3404 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3405 | ? LocationSummary::kCall |
| 3406 | : LocationSummary::kNoCall; |
| 3407 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3408 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3409 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3410 | case Primitive::kPrimInt: { |
| 3411 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3412 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3413 | locations->SetOut(Location::SameAsFirstInput()); |
| 3414 | // Intel uses edx:eax as the dividend. |
| 3415 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3416 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3417 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3418 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3419 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3420 | locations->AddTemp(Location::RequiresRegister()); |
| 3421 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3422 | break; |
| 3423 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3424 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3425 | InvokeRuntimeCallingConvention calling_convention; |
| 3426 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3427 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3428 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3429 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3430 | // Runtime helper puts the result in EAX, EDX. |
| 3431 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3432 | break; |
| 3433 | } |
| 3434 | case Primitive::kPrimFloat: |
| 3435 | case Primitive::kPrimDouble: { |
| 3436 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3437 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3438 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3439 | } else if (div->InputAt(1)->IsConstant()) { |
| 3440 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3441 | } else { |
| 3442 | locations->SetInAt(1, Location::Any()); |
| 3443 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3444 | locations->SetOut(Location::SameAsFirstInput()); |
| 3445 | break; |
| 3446 | } |
| 3447 | |
| 3448 | default: |
| 3449 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3454 | LocationSummary* locations = div->GetLocations(); |
| 3455 | Location first = locations->InAt(0); |
| 3456 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3457 | |
| 3458 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3459 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3460 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3461 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3462 | break; |
| 3463 | } |
| 3464 | |
| 3465 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3466 | if (second.IsFpuRegister()) { |
| 3467 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3468 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3469 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3470 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3471 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3472 | codegen_->LiteralFloatAddress( |
| 3473 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3474 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3475 | } else { |
| 3476 | DCHECK(second.IsStackSlot()); |
| 3477 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3478 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3479 | break; |
| 3480 | } |
| 3481 | |
| 3482 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3483 | if (second.IsFpuRegister()) { |
| 3484 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3485 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3486 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3487 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3488 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3489 | codegen_->LiteralDoubleAddress( |
| 3490 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3491 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3492 | } else { |
| 3493 | DCHECK(second.IsDoubleStackSlot()); |
| 3494 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3495 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3496 | break; |
| 3497 | } |
| 3498 | |
| 3499 | default: |
| 3500 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3501 | } |
| 3502 | } |
| 3503 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3504 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3505 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3506 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3507 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3508 | ? LocationSummary::kCall |
| 3509 | : LocationSummary::kNoCall; |
| 3510 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3511 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3512 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3513 | case Primitive::kPrimInt: { |
| 3514 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3515 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3516 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3517 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3518 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3519 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3520 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3521 | locations->AddTemp(Location::RequiresRegister()); |
| 3522 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3523 | break; |
| 3524 | } |
| 3525 | case Primitive::kPrimLong: { |
| 3526 | InvokeRuntimeCallingConvention calling_convention; |
| 3527 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3528 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3529 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3530 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3531 | // Runtime helper puts the result in EAX, EDX. |
| 3532 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3533 | break; |
| 3534 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3535 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3536 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3537 | locations->SetInAt(0, Location::Any()); |
| 3538 | locations->SetInAt(1, Location::Any()); |
| 3539 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3540 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3541 | break; |
| 3542 | } |
| 3543 | |
| 3544 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3545 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3550 | Primitive::Type type = rem->GetResultType(); |
| 3551 | switch (type) { |
| 3552 | case Primitive::kPrimInt: |
| 3553 | case Primitive::kPrimLong: { |
| 3554 | GenerateDivRemIntegral(rem); |
| 3555 | break; |
| 3556 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3557 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3558 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3559 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | } |
| 3562 | default: |
| 3563 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3564 | } |
| 3565 | } |
| 3566 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3567 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3568 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3569 | ? LocationSummary::kCallOnSlowPath |
| 3570 | : LocationSummary::kNoCall; |
| 3571 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3572 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3573 | case Primitive::kPrimByte: |
| 3574 | case Primitive::kPrimChar: |
| 3575 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3576 | case Primitive::kPrimInt: { |
| 3577 | locations->SetInAt(0, Location::Any()); |
| 3578 | break; |
| 3579 | } |
| 3580 | case Primitive::kPrimLong: { |
| 3581 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3582 | if (!instruction->IsConstant()) { |
| 3583 | locations->AddTemp(Location::RequiresRegister()); |
| 3584 | } |
| 3585 | break; |
| 3586 | } |
| 3587 | default: |
| 3588 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3589 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3590 | if (instruction->HasUses()) { |
| 3591 | locations->SetOut(Location::SameAsFirstInput()); |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3596 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3597 | codegen_->AddSlowPath(slow_path); |
| 3598 | |
| 3599 | LocationSummary* locations = instruction->GetLocations(); |
| 3600 | Location value = locations->InAt(0); |
| 3601 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3602 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3603 | case Primitive::kPrimByte: |
| 3604 | case Primitive::kPrimChar: |
| 3605 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3606 | case Primitive::kPrimInt: { |
| 3607 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3608 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3609 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3610 | } else if (value.IsStackSlot()) { |
| 3611 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3612 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3613 | } else { |
| 3614 | DCHECK(value.IsConstant()) << value; |
| 3615 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3616 | __ jmp(slow_path->GetEntryLabel()); |
| 3617 | } |
| 3618 | } |
| 3619 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3620 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3621 | case Primitive::kPrimLong: { |
| 3622 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3623 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3624 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3625 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3626 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3627 | } else { |
| 3628 | DCHECK(value.IsConstant()) << value; |
| 3629 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3630 | __ jmp(slow_path->GetEntryLabel()); |
| 3631 | } |
| 3632 | } |
| 3633 | break; |
| 3634 | } |
| 3635 | default: |
| 3636 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3637 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3638 | } |
| 3639 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3640 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3641 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3642 | |
| 3643 | LocationSummary* locations = |
| 3644 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3645 | |
| 3646 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3647 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3648 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3649 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3650 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3651 | // The shift count needs to be in CL or a constant. |
| 3652 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3653 | locations->SetOut(Location::SameAsFirstInput()); |
| 3654 | break; |
| 3655 | } |
| 3656 | default: |
| 3657 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3662 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3663 | |
| 3664 | LocationSummary* locations = op->GetLocations(); |
| 3665 | Location first = locations->InAt(0); |
| 3666 | Location second = locations->InAt(1); |
| 3667 | DCHECK(first.Equals(locations->Out())); |
| 3668 | |
| 3669 | switch (op->GetResultType()) { |
| 3670 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3671 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3672 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3673 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3674 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3675 | DCHECK_EQ(ECX, second_reg); |
| 3676 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3677 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3678 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3679 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3680 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3681 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3682 | } |
| 3683 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3684 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3685 | if (shift == 0) { |
| 3686 | return; |
| 3687 | } |
| 3688 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3689 | if (op->IsShl()) { |
| 3690 | __ shll(first_reg, imm); |
| 3691 | } else if (op->IsShr()) { |
| 3692 | __ sarl(first_reg, imm); |
| 3693 | } else { |
| 3694 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3695 | } |
| 3696 | } |
| 3697 | break; |
| 3698 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3699 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3700 | if (second.IsRegister()) { |
| 3701 | Register second_reg = second.AsRegister<Register>(); |
| 3702 | DCHECK_EQ(ECX, second_reg); |
| 3703 | if (op->IsShl()) { |
| 3704 | GenerateShlLong(first, second_reg); |
| 3705 | } else if (op->IsShr()) { |
| 3706 | GenerateShrLong(first, second_reg); |
| 3707 | } else { |
| 3708 | GenerateUShrLong(first, second_reg); |
| 3709 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3710 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3711 | // Shift by a constant. |
| 3712 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3713 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3714 | if (shift != 0) { |
| 3715 | if (op->IsShl()) { |
| 3716 | GenerateShlLong(first, shift); |
| 3717 | } else if (op->IsShr()) { |
| 3718 | GenerateShrLong(first, shift); |
| 3719 | } else { |
| 3720 | GenerateUShrLong(first, shift); |
| 3721 | } |
| 3722 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3723 | } |
| 3724 | break; |
| 3725 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3726 | default: |
| 3727 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3728 | } |
| 3729 | } |
| 3730 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3731 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3732 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3733 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3734 | if (shift == 1) { |
| 3735 | // This is just an addition. |
| 3736 | __ addl(low, low); |
| 3737 | __ adcl(high, high); |
| 3738 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3739 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3740 | codegen_->EmitParallelMoves( |
| 3741 | loc.ToLow(), |
| 3742 | loc.ToHigh(), |
| 3743 | Primitive::kPrimInt, |
| 3744 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3745 | loc.ToLow(), |
| 3746 | Primitive::kPrimInt); |
| 3747 | } else if (shift > 32) { |
| 3748 | // Low part becomes 0. High part is low part << (shift-32). |
| 3749 | __ movl(high, low); |
| 3750 | __ shll(high, Immediate(shift - 32)); |
| 3751 | __ xorl(low, low); |
| 3752 | } else { |
| 3753 | // Between 1 and 31. |
| 3754 | __ shld(high, low, Immediate(shift)); |
| 3755 | __ shll(low, Immediate(shift)); |
| 3756 | } |
| 3757 | } |
| 3758 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3759 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3760 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3761 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3762 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3763 | __ testl(shifter, Immediate(32)); |
| 3764 | __ j(kEqual, &done); |
| 3765 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3766 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3767 | __ Bind(&done); |
| 3768 | } |
| 3769 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3770 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3771 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3772 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3773 | if (shift == 32) { |
| 3774 | // Need to copy the sign. |
| 3775 | DCHECK_NE(low, high); |
| 3776 | __ movl(low, high); |
| 3777 | __ sarl(high, Immediate(31)); |
| 3778 | } else if (shift > 32) { |
| 3779 | DCHECK_NE(low, high); |
| 3780 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3781 | __ movl(low, high); |
| 3782 | __ sarl(high, Immediate(31)); |
| 3783 | __ sarl(low, Immediate(shift - 32)); |
| 3784 | } else { |
| 3785 | // Between 1 and 31. |
| 3786 | __ shrd(low, high, Immediate(shift)); |
| 3787 | __ sarl(high, Immediate(shift)); |
| 3788 | } |
| 3789 | } |
| 3790 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3791 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3792 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3793 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3794 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3795 | __ testl(shifter, Immediate(32)); |
| 3796 | __ j(kEqual, &done); |
| 3797 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3798 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3799 | __ Bind(&done); |
| 3800 | } |
| 3801 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3802 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3803 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3804 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3805 | if (shift == 32) { |
| 3806 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3807 | codegen_->EmitParallelMoves( |
| 3808 | loc.ToHigh(), |
| 3809 | loc.ToLow(), |
| 3810 | Primitive::kPrimInt, |
| 3811 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3812 | loc.ToHigh(), |
| 3813 | Primitive::kPrimInt); |
| 3814 | } else if (shift > 32) { |
| 3815 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3816 | __ movl(low, high); |
| 3817 | __ shrl(low, Immediate(shift - 32)); |
| 3818 | __ xorl(high, high); |
| 3819 | } else { |
| 3820 | // Between 1 and 31. |
| 3821 | __ shrd(low, high, Immediate(shift)); |
| 3822 | __ shrl(high, Immediate(shift)); |
| 3823 | } |
| 3824 | } |
| 3825 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3826 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3827 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3828 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3829 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3830 | __ testl(shifter, Immediate(32)); |
| 3831 | __ j(kEqual, &done); |
| 3832 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3833 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3834 | __ Bind(&done); |
| 3835 | } |
| 3836 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3837 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3838 | LocationSummary* locations = |
| 3839 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3840 | |
| 3841 | switch (ror->GetResultType()) { |
| 3842 | case Primitive::kPrimLong: |
| 3843 | // Add the temporary needed. |
| 3844 | locations->AddTemp(Location::RequiresRegister()); |
| 3845 | FALLTHROUGH_INTENDED; |
| 3846 | case Primitive::kPrimInt: |
| 3847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3848 | // The shift count needs to be in CL (unless it is a constant). |
| 3849 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3850 | locations->SetOut(Location::SameAsFirstInput()); |
| 3851 | break; |
| 3852 | default: |
| 3853 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3854 | UNREACHABLE(); |
| 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3859 | LocationSummary* locations = ror->GetLocations(); |
| 3860 | Location first = locations->InAt(0); |
| 3861 | Location second = locations->InAt(1); |
| 3862 | |
| 3863 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3864 | Register first_reg = first.AsRegister<Register>(); |
| 3865 | if (second.IsRegister()) { |
| 3866 | Register second_reg = second.AsRegister<Register>(); |
| 3867 | __ rorl(first_reg, second_reg); |
| 3868 | } else { |
| 3869 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3870 | __ rorl(first_reg, imm); |
| 3871 | } |
| 3872 | return; |
| 3873 | } |
| 3874 | |
| 3875 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3876 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3877 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3878 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3879 | if (second.IsRegister()) { |
| 3880 | Register second_reg = second.AsRegister<Register>(); |
| 3881 | DCHECK_EQ(second_reg, ECX); |
| 3882 | __ movl(temp_reg, first_reg_hi); |
| 3883 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3884 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3885 | __ movl(temp_reg, first_reg_hi); |
| 3886 | __ testl(second_reg, Immediate(32)); |
| 3887 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3888 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3889 | } else { |
| 3890 | int32_t shift_amt = |
| 3891 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3892 | if (shift_amt == 0) { |
| 3893 | // Already fine. |
| 3894 | return; |
| 3895 | } |
| 3896 | if (shift_amt == 32) { |
| 3897 | // Just swap. |
| 3898 | __ movl(temp_reg, first_reg_lo); |
| 3899 | __ movl(first_reg_lo, first_reg_hi); |
| 3900 | __ movl(first_reg_hi, temp_reg); |
| 3901 | return; |
| 3902 | } |
| 3903 | |
| 3904 | Immediate imm(shift_amt); |
| 3905 | // Save the constents of the low value. |
| 3906 | __ movl(temp_reg, first_reg_lo); |
| 3907 | |
| 3908 | // Shift right into low, feeding bits from high. |
| 3909 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3910 | |
| 3911 | // Shift right into high, feeding bits from the original low. |
| 3912 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3913 | |
| 3914 | // Swap if needed. |
| 3915 | if (shift_amt > 32) { |
| 3916 | __ movl(temp_reg, first_reg_lo); |
| 3917 | __ movl(first_reg_lo, first_reg_hi); |
| 3918 | __ movl(first_reg_hi, temp_reg); |
| 3919 | } |
| 3920 | } |
| 3921 | } |
| 3922 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3923 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3924 | HandleShift(shl); |
| 3925 | } |
| 3926 | |
| 3927 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3928 | HandleShift(shl); |
| 3929 | } |
| 3930 | |
| 3931 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3932 | HandleShift(shr); |
| 3933 | } |
| 3934 | |
| 3935 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3936 | HandleShift(shr); |
| 3937 | } |
| 3938 | |
| 3939 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3940 | HandleShift(ushr); |
| 3941 | } |
| 3942 | |
| 3943 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3944 | HandleShift(ushr); |
| 3945 | } |
| 3946 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3947 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3948 | LocationSummary* locations = |
| 3949 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3950 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3951 | if (instruction->IsStringAlloc()) { |
| 3952 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3953 | } else { |
| 3954 | InvokeRuntimeCallingConvention calling_convention; |
| 3955 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3956 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3957 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3961 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3962 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3963 | if (instruction->IsStringAlloc()) { |
| 3964 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3965 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3966 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3967 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3968 | __ call(Address(temp, code_offset.Int32Value())); |
| 3969 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3970 | } else { |
| 3971 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3972 | instruction, |
| 3973 | instruction->GetDexPc(), |
| 3974 | nullptr); |
| 3975 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3976 | DCHECK(!codegen_->IsLeafMethod()); |
| 3977 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3978 | } |
| 3979 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3980 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3981 | LocationSummary* locations = |
| 3982 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3983 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3984 | InvokeRuntimeCallingConvention calling_convention; |
| 3985 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3986 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3987 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3991 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3992 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3993 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3994 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3995 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3996 | instruction, |
| 3997 | instruction->GetDexPc(), |
| 3998 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3999 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4000 | DCHECK(!codegen_->IsLeafMethod()); |
| 4001 | } |
| 4002 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4003 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4004 | LocationSummary* locations = |
| 4005 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4006 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4007 | if (location.IsStackSlot()) { |
| 4008 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4009 | } else if (location.IsDoubleStackSlot()) { |
| 4010 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4011 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4012 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4013 | } |
| 4014 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4015 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4016 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4017 | } |
| 4018 | |
| 4019 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4020 | LocationSummary* locations = |
| 4021 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4022 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4023 | } |
| 4024 | |
| 4025 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4026 | } |
| 4027 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4028 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4029 | LocationSummary* locations = |
| 4030 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4031 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4032 | locations->SetOut(Location::RequiresRegister()); |
| 4033 | } |
| 4034 | |
| 4035 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4036 | LocationSummary* locations = instruction->GetLocations(); |
| 4037 | uint32_t method_offset = 0; |
| 4038 | if (instruction->GetTableKind() == HClassTableGet::kVTable) { |
| 4039 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4040 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4041 | } else { |
| 4042 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4043 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4044 | } |
| 4045 | __ movl(locations->Out().AsRegister<Register>(), |
| 4046 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4047 | } |
| 4048 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4049 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4050 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4051 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4053 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4054 | } |
| 4055 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4056 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4057 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4058 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4059 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4060 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4061 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4062 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4063 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4064 | break; |
| 4065 | |
| 4066 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4067 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4068 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4069 | break; |
| 4070 | |
| 4071 | default: |
| 4072 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4073 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4074 | } |
| 4075 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4076 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4077 | LocationSummary* locations = |
| 4078 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4079 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4080 | locations->SetOut(Location::SameAsFirstInput()); |
| 4081 | } |
| 4082 | |
| 4083 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4084 | LocationSummary* locations = bool_not->GetLocations(); |
| 4085 | Location in = locations->InAt(0); |
| 4086 | Location out = locations->Out(); |
| 4087 | DCHECK(in.Equals(out)); |
| 4088 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4089 | } |
| 4090 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4091 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4092 | LocationSummary* locations = |
| 4093 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4094 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4095 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4096 | case Primitive::kPrimLong: { |
| 4097 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4098 | locations->SetInAt(1, Location::Any()); |
| 4099 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4100 | break; |
| 4101 | } |
| 4102 | case Primitive::kPrimFloat: |
| 4103 | case Primitive::kPrimDouble: { |
| 4104 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4105 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4106 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4107 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4108 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4109 | } else { |
| 4110 | locations->SetInAt(1, Location::Any()); |
| 4111 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4112 | locations->SetOut(Location::RequiresRegister()); |
| 4113 | break; |
| 4114 | } |
| 4115 | default: |
| 4116 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4117 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4121 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4122 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4123 | Location left = locations->InAt(0); |
| 4124 | Location right = locations->InAt(1); |
| 4125 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4126 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4127 | Condition less_cond = kLess; |
| 4128 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4129 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4130 | case Primitive::kPrimInt: { |
| 4131 | Register left_reg = left.AsRegister<Register>(); |
| 4132 | if (right.IsConstant()) { |
| 4133 | int32_t value = right.GetConstant()->AsIntConstant()->GetValue(); |
| 4134 | codegen_->Compare32BitValue(left_reg, value); |
| 4135 | } else if (right.IsStackSlot()) { |
| 4136 | __ cmpl(left_reg, Address(ESP, right.GetStackIndex())); |
| 4137 | } else { |
| 4138 | __ cmpl(left_reg, right.AsRegister<Register>()); |
| 4139 | } |
| 4140 | break; |
| 4141 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4142 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4143 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4144 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4145 | int32_t val_low = 0; |
| 4146 | int32_t val_high = 0; |
| 4147 | bool right_is_const = false; |
| 4148 | |
| 4149 | if (right.IsConstant()) { |
| 4150 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4151 | right_is_const = true; |
| 4152 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4153 | val_low = Low32Bits(val); |
| 4154 | val_high = High32Bits(val); |
| 4155 | } |
| 4156 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4157 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4158 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4159 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4160 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4161 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4162 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4163 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4164 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4165 | __ j(kLess, &less); // Signed compare. |
| 4166 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4167 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4168 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4169 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4170 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4171 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4172 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4173 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4174 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4175 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4176 | break; |
| 4177 | } |
| 4178 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4179 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4180 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4181 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4182 | break; |
| 4183 | } |
| 4184 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4185 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4186 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4187 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4188 | break; |
| 4189 | } |
| 4190 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4191 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4192 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4193 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4194 | __ movl(out, Immediate(0)); |
| 4195 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4196 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4197 | |
| 4198 | __ Bind(&greater); |
| 4199 | __ movl(out, Immediate(1)); |
| 4200 | __ jmp(&done); |
| 4201 | |
| 4202 | __ Bind(&less); |
| 4203 | __ movl(out, Immediate(-1)); |
| 4204 | |
| 4205 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4206 | } |
| 4207 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4208 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4209 | LocationSummary* locations = |
| 4210 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4211 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4212 | locations->SetInAt(i, Location::Any()); |
| 4213 | } |
| 4214 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4215 | } |
| 4216 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4217 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4218 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4219 | } |
| 4220 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4221 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4222 | /* |
| 4223 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4224 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4225 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4226 | */ |
| 4227 | switch (kind) { |
| 4228 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4229 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4230 | break; |
| 4231 | } |
| 4232 | case MemBarrierKind::kAnyStore: |
| 4233 | case MemBarrierKind::kLoadAny: |
| 4234 | case MemBarrierKind::kStoreStore: { |
| 4235 | // nop |
| 4236 | break; |
| 4237 | } |
| 4238 | default: |
| 4239 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4240 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4241 | } |
| 4242 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4243 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4244 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4245 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4246 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4247 | |
| 4248 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4249 | // is incompatible with it. |
| 4250 | if (GetGraph()->HasIrreducibleLoops() && |
| 4251 | (dispatch_info.method_load_kind == |
| 4252 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4253 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4254 | } |
| 4255 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4256 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4257 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4258 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4259 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4260 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4261 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4262 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4263 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4264 | 0u |
| 4265 | }; |
| 4266 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4267 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4268 | } |
| 4269 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4270 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4271 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4272 | Register temp) { |
| 4273 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4274 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4275 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4276 | return location.AsRegister<Register>(); |
| 4277 | } |
| 4278 | // For intrinsics we allow any location, so it may be on the stack. |
| 4279 | if (!location.IsRegister()) { |
| 4280 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4281 | return temp; |
| 4282 | } |
| 4283 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4284 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4285 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4286 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4287 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4288 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4289 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4290 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4291 | __ movl(temp, Address(ESP, stack_offset)); |
| 4292 | return temp; |
| 4293 | } |
| 4294 | return location.AsRegister<Register>(); |
| 4295 | } |
| 4296 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4297 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4298 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4299 | switch (invoke->GetMethodLoadKind()) { |
| 4300 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4301 | // temp = thread->string_init_entrypoint |
| 4302 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4303 | break; |
| 4304 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4305 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4306 | break; |
| 4307 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4308 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4309 | break; |
| 4310 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4311 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4312 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4313 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4314 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4315 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4316 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4317 | temp.AsRegister<Register>()); |
| 4318 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4319 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4320 | // Add the patch entry and bind its label at the end of the instruction. |
| 4321 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4322 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4323 | break; |
| 4324 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4325 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4326 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4327 | Register method_reg; |
| 4328 | Register reg = temp.AsRegister<Register>(); |
| 4329 | if (current_method.IsRegister()) { |
| 4330 | method_reg = current_method.AsRegister<Register>(); |
| 4331 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4332 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4333 | DCHECK(!current_method.IsValid()); |
| 4334 | method_reg = reg; |
| 4335 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4336 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4337 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4338 | __ movl(reg, Address(method_reg, |
| 4339 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4340 | // temp = temp[index_in_cache] |
| 4341 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4342 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4343 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4344 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | switch (invoke->GetCodePtrLocation()) { |
| 4348 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4349 | __ call(GetFrameEntryLabel()); |
| 4350 | break; |
| 4351 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4352 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4353 | Label* label = &relative_call_patches_.back().label; |
| 4354 | __ call(label); // Bind to the patch label, override at link time. |
| 4355 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4356 | break; |
| 4357 | } |
| 4358 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4359 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4360 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4361 | LOG(FATAL) << "Unsupported"; |
| 4362 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4363 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4364 | // (callee_method + offset_of_quick_compiled_code)() |
| 4365 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4366 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4367 | kX86WordSize).Int32Value())); |
| 4368 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4372 | } |
| 4373 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4374 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4375 | Register temp = temp_in.AsRegister<Register>(); |
| 4376 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4377 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4378 | |
| 4379 | // Use the calling convention instead of the location of the receiver, as |
| 4380 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4381 | // slow path, the arguments have been moved to the right place, so here we are |
| 4382 | // guaranteed that the receiver is the first register of the calling convention. |
| 4383 | InvokeDexCallingConvention calling_convention; |
| 4384 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4385 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4386 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4387 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4388 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4389 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4390 | // emit a read barrier for the previous class reference load. |
| 4391 | // However this is not required in practice, as this is an |
| 4392 | // intermediate/temporary reference and because the current |
| 4393 | // concurrent copying collector keeps the from-space memory |
| 4394 | // intact/accessible until the end of the marking phase (the |
| 4395 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4396 | __ MaybeUnpoisonHeapReference(temp); |
| 4397 | // temp = temp->GetMethodAt(method_offset); |
| 4398 | __ movl(temp, Address(temp, method_offset)); |
| 4399 | // call temp->GetEntryPoint(); |
| 4400 | __ call(Address( |
| 4401 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4402 | } |
| 4403 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4404 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4405 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4406 | size_t size = |
| 4407 | method_patches_.size() + |
| 4408 | relative_call_patches_.size() + |
| 4409 | pc_relative_dex_cache_patches_.size(); |
| 4410 | linker_patches->reserve(size); |
| 4411 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4412 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4413 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4414 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4415 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4416 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4417 | info.target_method.dex_file, |
| 4418 | info.target_method.dex_method_index)); |
| 4419 | } |
| 4420 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4421 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4422 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4423 | info.target_method.dex_file, |
| 4424 | info.target_method.dex_method_index)); |
| 4425 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4426 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4427 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4428 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4429 | &info.target_dex_file, |
| 4430 | GetMethodAddressOffset(), |
| 4431 | info.element_offset)); |
| 4432 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4435 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4436 | Register card, |
| 4437 | Register object, |
| 4438 | Register value, |
| 4439 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4440 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4441 | if (value_can_be_null) { |
| 4442 | __ testl(value, value); |
| 4443 | __ j(kEqual, &is_null); |
| 4444 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4445 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4446 | __ movl(temp, object); |
| 4447 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4448 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4449 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4450 | if (value_can_be_null) { |
| 4451 | __ Bind(&is_null); |
| 4452 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4453 | } |
| 4454 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4455 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4456 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4457 | |
| 4458 | bool object_field_get_with_read_barrier = |
| 4459 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4460 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4461 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4462 | kEmitCompilerReadBarrier ? |
| 4463 | LocationSummary::kCallOnSlowPath : |
| 4464 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4465 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4466 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4467 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4468 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4469 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4470 | // The output overlaps in case of long: we don't want the low move |
| 4471 | // to overwrite the object's location. Likewise, in the case of |
| 4472 | // an object field get with read barriers enabled, we do not want |
| 4473 | // the move to overwrite the object's location, as we need it to emit |
| 4474 | // the read barrier. |
| 4475 | locations->SetOut( |
| 4476 | Location::RequiresRegister(), |
| 4477 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4478 | Location::kOutputOverlap : |
| 4479 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4480 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4481 | |
| 4482 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4483 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4484 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4485 | // load the temp into the XMM and then copy the XMM into the |
| 4486 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4487 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4488 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4489 | // We need a temporary register for the read barrier marking slow |
| 4490 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4491 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4492 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4495 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4496 | const FieldInfo& field_info) { |
| 4497 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4498 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4499 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4500 | Location base_loc = locations->InAt(0); |
| 4501 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4502 | Location out = locations->Out(); |
| 4503 | bool is_volatile = field_info.IsVolatile(); |
| 4504 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4505 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4506 | |
| 4507 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4508 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4509 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4510 | break; |
| 4511 | } |
| 4512 | |
| 4513 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4514 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4515 | break; |
| 4516 | } |
| 4517 | |
| 4518 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4519 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4520 | break; |
| 4521 | } |
| 4522 | |
| 4523 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4524 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4525 | break; |
| 4526 | } |
| 4527 | |
| 4528 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4529 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4530 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4531 | |
| 4532 | case Primitive::kPrimNot: { |
| 4533 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4534 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4535 | Location temp_loc = locations->GetTemp(0); |
| 4536 | // Note that a potential implicit null check is handled in this |
| 4537 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4538 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4539 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4540 | if (is_volatile) { |
| 4541 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4542 | } |
| 4543 | } else { |
| 4544 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4545 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4546 | if (is_volatile) { |
| 4547 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4548 | } |
| 4549 | // If read barriers are enabled, emit read barriers other than |
| 4550 | // Baker's using a slow path (and also unpoison the loaded |
| 4551 | // reference, if heap poisoning is enabled). |
| 4552 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4553 | } |
| 4554 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4558 | if (is_volatile) { |
| 4559 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4560 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4561 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4562 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4563 | __ psrlq(temp, Immediate(32)); |
| 4564 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4565 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4566 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4567 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4568 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4569 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4570 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4571 | break; |
| 4572 | } |
| 4573 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4574 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4575 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4576 | break; |
| 4577 | } |
| 4578 | |
| 4579 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4580 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4581 | break; |
| 4582 | } |
| 4583 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4584 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4585 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4586 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4587 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4589 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4590 | // Potential implicit null checks, in the case of reference or |
| 4591 | // long fields, are handled in the previous switch statement. |
| 4592 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4593 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4594 | } |
| 4595 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4596 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4597 | if (field_type == Primitive::kPrimNot) { |
| 4598 | // Memory barriers, in the case of references, are also handled |
| 4599 | // in the previous switch statement. |
| 4600 | } else { |
| 4601 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4602 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4603 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4607 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4608 | |
| 4609 | LocationSummary* locations = |
| 4610 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4611 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4612 | bool is_volatile = field_info.IsVolatile(); |
| 4613 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4614 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4615 | || (field_type == Primitive::kPrimByte); |
| 4616 | |
| 4617 | // The register allocator does not support multiple |
| 4618 | // inputs that die at entry with one in a specific register. |
| 4619 | if (is_byte_type) { |
| 4620 | // Ensure the value is in a byte register. |
| 4621 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4622 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4623 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4624 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4625 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4626 | } else { |
| 4627 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4628 | } |
| 4629 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4630 | // 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] | 4631 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4632 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4634 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4635 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4636 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4637 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4638 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4639 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4640 | } else { |
| 4641 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4642 | |
| 4643 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4644 | // Temporary registers for the write barrier. |
| 4645 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4646 | // Ensure the card is in a byte register. |
| 4647 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4648 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4649 | } |
| 4650 | } |
| 4651 | |
| 4652 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4653 | const FieldInfo& field_info, |
| 4654 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4655 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4656 | |
| 4657 | LocationSummary* locations = instruction->GetLocations(); |
| 4658 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4659 | Location value = locations->InAt(1); |
| 4660 | bool is_volatile = field_info.IsVolatile(); |
| 4661 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4662 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4663 | bool needs_write_barrier = |
| 4664 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4665 | |
| 4666 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4667 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4670 | bool maybe_record_implicit_null_check_done = false; |
| 4671 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | switch (field_type) { |
| 4673 | case Primitive::kPrimBoolean: |
| 4674 | case Primitive::kPrimByte: { |
| 4675 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4676 | break; |
| 4677 | } |
| 4678 | |
| 4679 | case Primitive::kPrimShort: |
| 4680 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4681 | if (value.IsConstant()) { |
| 4682 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4683 | __ movw(Address(base, offset), Immediate(v)); |
| 4684 | } else { |
| 4685 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4686 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | break; |
| 4688 | } |
| 4689 | |
| 4690 | case Primitive::kPrimInt: |
| 4691 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4692 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4693 | // Note that in the case where `value` is a null reference, |
| 4694 | // we do not enter this block, as the reference does not |
| 4695 | // need poisoning. |
| 4696 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4697 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4698 | __ movl(temp, value.AsRegister<Register>()); |
| 4699 | __ PoisonHeapReference(temp); |
| 4700 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4701 | } else if (value.IsConstant()) { |
| 4702 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4703 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4704 | } else { |
| 4705 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4706 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4707 | break; |
| 4708 | } |
| 4709 | |
| 4710 | case Primitive::kPrimLong: { |
| 4711 | if (is_volatile) { |
| 4712 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4713 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4714 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4715 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4716 | __ punpckldq(temp1, temp2); |
| 4717 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4718 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4719 | } else if (value.IsConstant()) { |
| 4720 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4721 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4722 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4723 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4724 | } else { |
| 4725 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4726 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4727 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4728 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4729 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4730 | break; |
| 4731 | } |
| 4732 | |
| 4733 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4734 | if (value.IsConstant()) { |
| 4735 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4736 | __ movl(Address(base, offset), Immediate(v)); |
| 4737 | } else { |
| 4738 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4739 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4740 | break; |
| 4741 | } |
| 4742 | |
| 4743 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4744 | if (value.IsConstant()) { |
| 4745 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4746 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4747 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4748 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4749 | maybe_record_implicit_null_check_done = true; |
| 4750 | } else { |
| 4751 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4752 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4753 | break; |
| 4754 | } |
| 4755 | |
| 4756 | case Primitive::kPrimVoid: |
| 4757 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4758 | UNREACHABLE(); |
| 4759 | } |
| 4760 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4761 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4762 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4763 | } |
| 4764 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4765 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4766 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4767 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4768 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4769 | } |
| 4770 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4771 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4772 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4777 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4778 | } |
| 4779 | |
| 4780 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4781 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4782 | } |
| 4783 | |
| 4784 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4785 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4786 | } |
| 4787 | |
| 4788 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4789 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4793 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4794 | } |
| 4795 | |
| 4796 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4797 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4801 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4802 | } |
| 4803 | |
| 4804 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4805 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4806 | } |
| 4807 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4808 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4809 | HUnresolvedInstanceFieldGet* instruction) { |
| 4810 | FieldAccessCallingConventionX86 calling_convention; |
| 4811 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4812 | instruction, instruction->GetFieldType(), calling_convention); |
| 4813 | } |
| 4814 | |
| 4815 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4816 | HUnresolvedInstanceFieldGet* instruction) { |
| 4817 | FieldAccessCallingConventionX86 calling_convention; |
| 4818 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4819 | instruction->GetFieldType(), |
| 4820 | instruction->GetFieldIndex(), |
| 4821 | instruction->GetDexPc(), |
| 4822 | calling_convention); |
| 4823 | } |
| 4824 | |
| 4825 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4826 | HUnresolvedInstanceFieldSet* instruction) { |
| 4827 | FieldAccessCallingConventionX86 calling_convention; |
| 4828 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4829 | instruction, instruction->GetFieldType(), calling_convention); |
| 4830 | } |
| 4831 | |
| 4832 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4833 | HUnresolvedInstanceFieldSet* instruction) { |
| 4834 | FieldAccessCallingConventionX86 calling_convention; |
| 4835 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4836 | instruction->GetFieldType(), |
| 4837 | instruction->GetFieldIndex(), |
| 4838 | instruction->GetDexPc(), |
| 4839 | calling_convention); |
| 4840 | } |
| 4841 | |
| 4842 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4843 | HUnresolvedStaticFieldGet* instruction) { |
| 4844 | FieldAccessCallingConventionX86 calling_convention; |
| 4845 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4846 | instruction, instruction->GetFieldType(), calling_convention); |
| 4847 | } |
| 4848 | |
| 4849 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4850 | HUnresolvedStaticFieldGet* instruction) { |
| 4851 | FieldAccessCallingConventionX86 calling_convention; |
| 4852 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4853 | instruction->GetFieldType(), |
| 4854 | instruction->GetFieldIndex(), |
| 4855 | instruction->GetDexPc(), |
| 4856 | calling_convention); |
| 4857 | } |
| 4858 | |
| 4859 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4860 | HUnresolvedStaticFieldSet* instruction) { |
| 4861 | FieldAccessCallingConventionX86 calling_convention; |
| 4862 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4863 | instruction, instruction->GetFieldType(), calling_convention); |
| 4864 | } |
| 4865 | |
| 4866 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4867 | HUnresolvedStaticFieldSet* instruction) { |
| 4868 | FieldAccessCallingConventionX86 calling_convention; |
| 4869 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4870 | instruction->GetFieldType(), |
| 4871 | instruction->GetFieldIndex(), |
| 4872 | instruction->GetDexPc(), |
| 4873 | calling_convention); |
| 4874 | } |
| 4875 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4876 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4877 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4878 | ? LocationSummary::kCallOnSlowPath |
| 4879 | : LocationSummary::kNoCall; |
| 4880 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4881 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4882 | ? Location::RequiresRegister() |
| 4883 | : Location::Any(); |
| 4884 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4885 | if (instruction->HasUses()) { |
| 4886 | locations->SetOut(Location::SameAsFirstInput()); |
| 4887 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4888 | } |
| 4889 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4890 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4891 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4892 | return; |
| 4893 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4894 | LocationSummary* locations = instruction->GetLocations(); |
| 4895 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4896 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4897 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4898 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4899 | } |
| 4900 | |
| 4901 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4902 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4903 | codegen_->AddSlowPath(slow_path); |
| 4904 | |
| 4905 | LocationSummary* locations = instruction->GetLocations(); |
| 4906 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4907 | |
| 4908 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4909 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4910 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4911 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4912 | } else { |
| 4913 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4914 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4915 | __ jmp(slow_path->GetEntryLabel()); |
| 4916 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4917 | } |
| 4918 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4919 | } |
| 4920 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4921 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4922 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4923 | GenerateImplicitNullCheck(instruction); |
| 4924 | } else { |
| 4925 | GenerateExplicitNullCheck(instruction); |
| 4926 | } |
| 4927 | } |
| 4928 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4929 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4930 | bool object_array_get_with_read_barrier = |
| 4931 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4932 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4933 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4934 | object_array_get_with_read_barrier ? |
| 4935 | LocationSummary::kCallOnSlowPath : |
| 4936 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4937 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4938 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4939 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4940 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4941 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4942 | // The output overlaps in case of long: we don't want the low move |
| 4943 | // to overwrite the array's location. Likewise, in the case of an |
| 4944 | // object array get with read barriers enabled, we do not want the |
| 4945 | // move to overwrite the array's location, as we need it to emit |
| 4946 | // the read barrier. |
| 4947 | locations->SetOut( |
| 4948 | Location::RequiresRegister(), |
| 4949 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4950 | Location::kOutputOverlap : |
| 4951 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4952 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4953 | // We need a temporary register for the read barrier marking slow |
| 4954 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4955 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4956 | locations->AddTemp(Location::RequiresRegister()); |
| 4957 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4958 | } |
| 4959 | |
| 4960 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4961 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4962 | Location obj_loc = locations->InAt(0); |
| 4963 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4964 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4965 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4966 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4967 | Primitive::Type type = instruction->GetType(); |
| 4968 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4969 | case Primitive::kPrimBoolean: { |
| 4970 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4971 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4972 | if (index.IsConstant()) { |
| 4973 | __ movzxb(out, Address(obj, |
| 4974 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4975 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4976 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4977 | } |
| 4978 | break; |
| 4979 | } |
| 4980 | |
| 4981 | case Primitive::kPrimByte: { |
| 4982 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4983 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4984 | if (index.IsConstant()) { |
| 4985 | __ movsxb(out, Address(obj, |
| 4986 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4987 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4988 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4989 | } |
| 4990 | break; |
| 4991 | } |
| 4992 | |
| 4993 | case Primitive::kPrimShort: { |
| 4994 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4995 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4996 | if (index.IsConstant()) { |
| 4997 | __ movsxw(out, Address(obj, |
| 4998 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4999 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5000 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5001 | } |
| 5002 | break; |
| 5003 | } |
| 5004 | |
| 5005 | case Primitive::kPrimChar: { |
| 5006 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5007 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5008 | if (index.IsConstant()) { |
| 5009 | __ movzxw(out, Address(obj, |
| 5010 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5011 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5012 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5013 | } |
| 5014 | break; |
| 5015 | } |
| 5016 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5017 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5018 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5019 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5020 | if (index.IsConstant()) { |
| 5021 | __ movl(out, Address(obj, |
| 5022 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5023 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5024 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5025 | } |
| 5026 | break; |
| 5027 | } |
| 5028 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5029 | case Primitive::kPrimNot: { |
| 5030 | static_assert( |
| 5031 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5032 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5033 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5034 | // /* HeapReference<Object> */ out = |
| 5035 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5036 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5037 | Location temp = locations->GetTemp(0); |
| 5038 | // Note that a potential implicit null check is handled in this |
| 5039 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5040 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5041 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5042 | } else { |
| 5043 | Register out = out_loc.AsRegister<Register>(); |
| 5044 | if (index.IsConstant()) { |
| 5045 | uint32_t offset = |
| 5046 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5047 | __ movl(out, Address(obj, offset)); |
| 5048 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5049 | // If read barriers are enabled, emit read barriers other than |
| 5050 | // Baker's using a slow path (and also unpoison the loaded |
| 5051 | // reference, if heap poisoning is enabled). |
| 5052 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5053 | } else { |
| 5054 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5055 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5056 | // If read barriers are enabled, emit read barriers other than |
| 5057 | // Baker's using a slow path (and also unpoison the loaded |
| 5058 | // reference, if heap poisoning is enabled). |
| 5059 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5060 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5061 | } |
| 5062 | } |
| 5063 | break; |
| 5064 | } |
| 5065 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | case Primitive::kPrimLong: { |
| 5067 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5068 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | if (index.IsConstant()) { |
| 5070 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5071 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5072 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5073 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5075 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5076 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5077 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5078 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5079 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5080 | } |
| 5081 | break; |
| 5082 | } |
| 5083 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5084 | case Primitive::kPrimFloat: { |
| 5085 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5086 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5087 | if (index.IsConstant()) { |
| 5088 | __ movss(out, Address(obj, |
| 5089 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5090 | } else { |
| 5091 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5092 | } |
| 5093 | break; |
| 5094 | } |
| 5095 | |
| 5096 | case Primitive::kPrimDouble: { |
| 5097 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5098 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5099 | if (index.IsConstant()) { |
| 5100 | __ movsd(out, Address(obj, |
| 5101 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5102 | } else { |
| 5103 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5104 | } |
| 5105 | break; |
| 5106 | } |
| 5107 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5108 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5109 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5110 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5112 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5113 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5114 | // Potential implicit null checks, in the case of reference or |
| 5115 | // long arrays, are handled in the previous switch statement. |
| 5116 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5117 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5118 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5122 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5123 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5124 | bool needs_write_barrier = |
| 5125 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5126 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5127 | bool object_array_set_with_read_barrier = |
| 5128 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5129 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5130 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5131 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5132 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5133 | LocationSummary::kCallOnSlowPath : |
| 5134 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5135 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5136 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5137 | || (value_type == Primitive::kPrimByte); |
| 5138 | // We need the inputs to be different than the output in case of long operation. |
| 5139 | // In case of a byte operation, the register allocator does not support multiple |
| 5140 | // inputs that die at entry with one in a specific register. |
| 5141 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5142 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5143 | if (is_byte_type) { |
| 5144 | // Ensure the value is in a byte register. |
| 5145 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5146 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5147 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5148 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5149 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5150 | } |
| 5151 | if (needs_write_barrier) { |
| 5152 | // Temporary registers for the write barrier. |
| 5153 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5154 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5155 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5156 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5160 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5161 | Location array_loc = locations->InAt(0); |
| 5162 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5163 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5164 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5165 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5166 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5167 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5168 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5169 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5170 | bool needs_write_barrier = |
| 5171 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5172 | |
| 5173 | switch (value_type) { |
| 5174 | case Primitive::kPrimBoolean: |
| 5175 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5176 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5177 | Address address = index.IsConstant() |
| 5178 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5179 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5180 | if (value.IsRegister()) { |
| 5181 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5182 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5183 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5184 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5185 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5186 | break; |
| 5187 | } |
| 5188 | |
| 5189 | case Primitive::kPrimShort: |
| 5190 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5191 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5192 | Address address = index.IsConstant() |
| 5193 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5194 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5195 | if (value.IsRegister()) { |
| 5196 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5197 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5198 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5199 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5200 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5201 | break; |
| 5202 | } |
| 5203 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5204 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5205 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5206 | Address address = index.IsConstant() |
| 5207 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5208 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5209 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5210 | if (!value.IsRegister()) { |
| 5211 | // Just setting null. |
| 5212 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5213 | DCHECK(value.IsConstant()) << value; |
| 5214 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5215 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5216 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5217 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5218 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5219 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5220 | |
| 5221 | DCHECK(needs_write_barrier); |
| 5222 | Register register_value = value.AsRegister<Register>(); |
| 5223 | NearLabel done, not_null, do_put; |
| 5224 | SlowPathCode* slow_path = nullptr; |
| 5225 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5226 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5227 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5228 | codegen_->AddSlowPath(slow_path); |
| 5229 | if (instruction->GetValueCanBeNull()) { |
| 5230 | __ testl(register_value, register_value); |
| 5231 | __ j(kNotEqual, ¬_null); |
| 5232 | __ movl(address, Immediate(0)); |
| 5233 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5234 | __ jmp(&done); |
| 5235 | __ Bind(¬_null); |
| 5236 | } |
| 5237 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5238 | if (kEmitCompilerReadBarrier) { |
| 5239 | // When read barriers are enabled, the type checking |
| 5240 | // instrumentation requires two read barriers: |
| 5241 | // |
| 5242 | // __ movl(temp2, temp); |
| 5243 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5244 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5245 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5246 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5247 | // |
| 5248 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5249 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5250 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5251 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5252 | // |
| 5253 | // __ cmpl(temp, temp2); |
| 5254 | // |
| 5255 | // However, the second read barrier may trash `temp`, as it |
| 5256 | // is a temporary register, and as such would not be saved |
| 5257 | // along with live registers before calling the runtime (nor |
| 5258 | // restored afterwards). So in this case, we bail out and |
| 5259 | // delegate the work to the array set slow path. |
| 5260 | // |
| 5261 | // TODO: Extend the register allocator to support a new |
| 5262 | // "(locally) live temp" location so as to avoid always |
| 5263 | // going into the slow path when read barriers are enabled. |
| 5264 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5265 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5266 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5267 | __ movl(temp, Address(array, class_offset)); |
| 5268 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5269 | __ MaybeUnpoisonHeapReference(temp); |
| 5270 | |
| 5271 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5272 | __ movl(temp, Address(temp, component_offset)); |
| 5273 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5274 | // nor the object reference in `register_value->klass`, as |
| 5275 | // we are comparing two poisoned references. |
| 5276 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5277 | |
| 5278 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5279 | __ j(kEqual, &do_put); |
| 5280 | // If heap poisoning is enabled, the `temp` reference has |
| 5281 | // not been unpoisoned yet; unpoison it now. |
| 5282 | __ MaybeUnpoisonHeapReference(temp); |
| 5283 | |
| 5284 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5285 | __ movl(temp, Address(temp, super_offset)); |
| 5286 | // If heap poisoning is enabled, no need to unpoison |
| 5287 | // `temp`, as we are comparing against null below. |
| 5288 | __ testl(temp, temp); |
| 5289 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5290 | __ Bind(&do_put); |
| 5291 | } else { |
| 5292 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5293 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | if (kPoisonHeapReferences) { |
| 5298 | __ movl(temp, register_value); |
| 5299 | __ PoisonHeapReference(temp); |
| 5300 | __ movl(address, temp); |
| 5301 | } else { |
| 5302 | __ movl(address, register_value); |
| 5303 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5304 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5305 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5306 | } |
| 5307 | |
| 5308 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5309 | codegen_->MarkGCCard( |
| 5310 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5311 | __ Bind(&done); |
| 5312 | |
| 5313 | if (slow_path != nullptr) { |
| 5314 | __ Bind(slow_path->GetExitLabel()); |
| 5315 | } |
| 5316 | |
| 5317 | break; |
| 5318 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5319 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5320 | case Primitive::kPrimInt: { |
| 5321 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5322 | Address address = index.IsConstant() |
| 5323 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5324 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5325 | if (value.IsRegister()) { |
| 5326 | __ movl(address, value.AsRegister<Register>()); |
| 5327 | } else { |
| 5328 | DCHECK(value.IsConstant()) << value; |
| 5329 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5330 | __ movl(address, Immediate(v)); |
| 5331 | } |
| 5332 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5333 | break; |
| 5334 | } |
| 5335 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5336 | case Primitive::kPrimLong: { |
| 5337 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5338 | if (index.IsConstant()) { |
| 5339 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5340 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5341 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5342 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5343 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5344 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5345 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5346 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5347 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5348 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5349 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5350 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5351 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5352 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5353 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5354 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5355 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5356 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5357 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5358 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5359 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5360 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5361 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5362 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5363 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5364 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5365 | Immediate(High32Bits(val))); |
| 5366 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5367 | } |
| 5368 | break; |
| 5369 | } |
| 5370 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5371 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5372 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5373 | Address address = index.IsConstant() |
| 5374 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5375 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5376 | if (value.IsFpuRegister()) { |
| 5377 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5378 | } else { |
| 5379 | DCHECK(value.IsConstant()); |
| 5380 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5381 | __ movl(address, Immediate(v)); |
| 5382 | } |
| 5383 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5384 | break; |
| 5385 | } |
| 5386 | |
| 5387 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5388 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5389 | Address address = index.IsConstant() |
| 5390 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5391 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5392 | if (value.IsFpuRegister()) { |
| 5393 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5394 | } else { |
| 5395 | DCHECK(value.IsConstant()); |
| 5396 | Address address_hi = index.IsConstant() ? |
| 5397 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5398 | offset + kX86WordSize) : |
| 5399 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5400 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5401 | __ movl(address, Immediate(Low32Bits(v))); |
| 5402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5403 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5404 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5405 | break; |
| 5406 | } |
| 5407 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5408 | case Primitive::kPrimVoid: |
| 5409 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5410 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5411 | } |
| 5412 | } |
| 5413 | |
| 5414 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5415 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5416 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5417 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5421 | LocationSummary* locations = instruction->GetLocations(); |
| 5422 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5423 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5424 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5425 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5430 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5431 | ? LocationSummary::kCallOnSlowPath |
| 5432 | : LocationSummary::kNoCall; |
| 5433 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5434 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5435 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5436 | if (instruction->HasUses()) { |
| 5437 | locations->SetOut(Location::SameAsFirstInput()); |
| 5438 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5442 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5443 | Location index_loc = locations->InAt(0); |
| 5444 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5445 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5446 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5447 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5448 | if (length_loc.IsConstant()) { |
| 5449 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5450 | if (index_loc.IsConstant()) { |
| 5451 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5452 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5453 | if (index < 0 || index >= length) { |
| 5454 | codegen_->AddSlowPath(slow_path); |
| 5455 | __ jmp(slow_path->GetEntryLabel()); |
| 5456 | } else { |
| 5457 | // Some optimization after BCE may have generated this, and we should not |
| 5458 | // generate a bounds check if it is a valid range. |
| 5459 | } |
| 5460 | return; |
| 5461 | } |
| 5462 | |
| 5463 | // We have to reverse the jump condition because the length is the constant. |
| 5464 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5465 | __ cmpl(index_reg, Immediate(length)); |
| 5466 | codegen_->AddSlowPath(slow_path); |
| 5467 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5468 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5469 | Register length = length_loc.AsRegister<Register>(); |
| 5470 | if (index_loc.IsConstant()) { |
| 5471 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5472 | __ cmpl(length, Immediate(value)); |
| 5473 | } else { |
| 5474 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5475 | } |
| 5476 | codegen_->AddSlowPath(slow_path); |
| 5477 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5478 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5479 | } |
| 5480 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5481 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5482 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5483 | } |
| 5484 | |
| 5485 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5486 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5487 | } |
| 5488 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5489 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5490 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5491 | } |
| 5492 | |
| 5493 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5494 | HBasicBlock* block = instruction->GetBlock(); |
| 5495 | if (block->GetLoopInformation() != nullptr) { |
| 5496 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5497 | // The back edge will generate the suspend check. |
| 5498 | return; |
| 5499 | } |
| 5500 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5501 | // The goto will generate the suspend check. |
| 5502 | return; |
| 5503 | } |
| 5504 | GenerateSuspendCheck(instruction, nullptr); |
| 5505 | } |
| 5506 | |
| 5507 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5508 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5509 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5510 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5511 | if (slow_path == nullptr) { |
| 5512 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5513 | instruction->SetSlowPath(slow_path); |
| 5514 | codegen_->AddSlowPath(slow_path); |
| 5515 | if (successor != nullptr) { |
| 5516 | DCHECK(successor->IsLoopHeader()); |
| 5517 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5518 | } |
| 5519 | } else { |
| 5520 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5521 | } |
| 5522 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5523 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5524 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5525 | if (successor == nullptr) { |
| 5526 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5527 | __ Bind(slow_path->GetReturnLabel()); |
| 5528 | } else { |
| 5529 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5530 | __ jmp(slow_path->GetEntryLabel()); |
| 5531 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5532 | } |
| 5533 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5534 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5535 | return codegen_->GetAssembler(); |
| 5536 | } |
| 5537 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5538 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5539 | ScratchRegisterScope ensure_scratch( |
| 5540 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5541 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5542 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5543 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5544 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5548 | ScratchRegisterScope ensure_scratch( |
| 5549 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5550 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5551 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5552 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5553 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5554 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5555 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5559 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5560 | Location source = move->GetSource(); |
| 5561 | Location destination = move->GetDestination(); |
| 5562 | |
| 5563 | if (source.IsRegister()) { |
| 5564 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5565 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5566 | } else if (destination.IsFpuRegister()) { |
| 5567 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5568 | } else { |
| 5569 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5570 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5571 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5572 | } else if (source.IsRegisterPair()) { |
| 5573 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5574 | // Create stack space for 2 elements. |
| 5575 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5576 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5577 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5578 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5579 | // And remove the temporary stack space we allocated. |
| 5580 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5581 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5582 | if (destination.IsRegister()) { |
| 5583 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5584 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5585 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5586 | } else if (destination.IsRegisterPair()) { |
| 5587 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5588 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5589 | __ psrlq(src_reg, Immediate(32)); |
| 5590 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5591 | } else if (destination.IsStackSlot()) { |
| 5592 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5593 | } else { |
| 5594 | DCHECK(destination.IsDoubleStackSlot()); |
| 5595 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5596 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5597 | } else if (source.IsStackSlot()) { |
| 5598 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5599 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5600 | } else if (destination.IsFpuRegister()) { |
| 5601 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5602 | } else { |
| 5603 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5604 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5605 | } |
| 5606 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5607 | if (destination.IsRegisterPair()) { |
| 5608 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5609 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5610 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5611 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5612 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5613 | } else { |
| 5614 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5615 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5616 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5617 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5618 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5619 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5620 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5621 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5622 | if (value == 0) { |
| 5623 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5624 | } else { |
| 5625 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5626 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5627 | } else { |
| 5628 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5629 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5630 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5631 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5632 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5633 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5634 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5635 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5636 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5637 | if (value == 0) { |
| 5638 | // Easy handling of 0.0. |
| 5639 | __ xorps(dest, dest); |
| 5640 | } else { |
| 5641 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5642 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5643 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5644 | __ movl(temp, Immediate(value)); |
| 5645 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5646 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5647 | } else { |
| 5648 | DCHECK(destination.IsStackSlot()) << destination; |
| 5649 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5650 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5651 | } else if (constant->IsLongConstant()) { |
| 5652 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5653 | int32_t low_value = Low32Bits(value); |
| 5654 | int32_t high_value = High32Bits(value); |
| 5655 | Immediate low(low_value); |
| 5656 | Immediate high(high_value); |
| 5657 | if (destination.IsDoubleStackSlot()) { |
| 5658 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5659 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5660 | } else { |
| 5661 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5662 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5663 | } |
| 5664 | } else { |
| 5665 | DCHECK(constant->IsDoubleConstant()); |
| 5666 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5667 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5668 | int32_t low_value = Low32Bits(value); |
| 5669 | int32_t high_value = High32Bits(value); |
| 5670 | Immediate low(low_value); |
| 5671 | Immediate high(high_value); |
| 5672 | if (destination.IsFpuRegister()) { |
| 5673 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5674 | if (value == 0) { |
| 5675 | // Easy handling of 0.0. |
| 5676 | __ xorpd(dest, dest); |
| 5677 | } else { |
| 5678 | __ pushl(high); |
| 5679 | __ pushl(low); |
| 5680 | __ movsd(dest, Address(ESP, 0)); |
| 5681 | __ addl(ESP, Immediate(8)); |
| 5682 | } |
| 5683 | } else { |
| 5684 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5685 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5686 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5687 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5688 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5689 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5690 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5691 | } |
| 5692 | } |
| 5693 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5694 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5695 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5696 | ScratchRegisterScope ensure_scratch( |
| 5697 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5698 | |
| 5699 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5700 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5701 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5702 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5703 | } |
| 5704 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5705 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5706 | ScratchRegisterScope ensure_scratch( |
| 5707 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5708 | |
| 5709 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5710 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5711 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5712 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5713 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5714 | } |
| 5715 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5716 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5717 | ScratchRegisterScope ensure_scratch1( |
| 5718 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5719 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5720 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5721 | ScratchRegisterScope ensure_scratch2( |
| 5722 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5723 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5724 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5725 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5726 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5727 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5728 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5729 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5730 | } |
| 5731 | |
| 5732 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5733 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5734 | Location source = move->GetSource(); |
| 5735 | Location destination = move->GetDestination(); |
| 5736 | |
| 5737 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5738 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5739 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5740 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5741 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5742 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5743 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5744 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5745 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5746 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5747 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5748 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5749 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5750 | // Use XOR Swap algorithm to avoid a temporary. |
| 5751 | DCHECK_NE(source.reg(), destination.reg()); |
| 5752 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5753 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5754 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5755 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5756 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5757 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5758 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5759 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5760 | // Take advantage of the 16 bytes in the XMM register. |
| 5761 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5762 | Address stack(ESP, destination.GetStackIndex()); |
| 5763 | // Load the double into the high doubleword. |
| 5764 | __ movhpd(reg, stack); |
| 5765 | |
| 5766 | // Store the low double into the destination. |
| 5767 | __ movsd(stack, reg); |
| 5768 | |
| 5769 | // Move the high double to the low double. |
| 5770 | __ psrldq(reg, Immediate(8)); |
| 5771 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5772 | // Take advantage of the 16 bytes in the XMM register. |
| 5773 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5774 | Address stack(ESP, source.GetStackIndex()); |
| 5775 | // Load the double into the high doubleword. |
| 5776 | __ movhpd(reg, stack); |
| 5777 | |
| 5778 | // Store the low double into the destination. |
| 5779 | __ movsd(stack, reg); |
| 5780 | |
| 5781 | // Move the high double to the low double. |
| 5782 | __ psrldq(reg, Immediate(8)); |
| 5783 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5784 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5785 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5786 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5787 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5788 | } |
| 5789 | } |
| 5790 | |
| 5791 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5792 | __ pushl(static_cast<Register>(reg)); |
| 5793 | } |
| 5794 | |
| 5795 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5796 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5797 | } |
| 5798 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5799 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5800 | InvokeRuntimeCallingConvention calling_convention; |
| 5801 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5802 | cls, |
| 5803 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5804 | Location::RegisterLocation(EAX), |
| 5805 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5809 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5810 | if (cls->NeedsAccessCheck()) { |
| 5811 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5812 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5813 | cls, |
| 5814 | cls->GetDexPc(), |
| 5815 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5816 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5817 | return; |
| 5818 | } |
| 5819 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5820 | Location out_loc = locations->Out(); |
| 5821 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5822 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5823 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5824 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5825 | DCHECK(!cls->CanCallRuntime()); |
| 5826 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5827 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5828 | GenerateGcRootFieldLoad( |
| 5829 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5830 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5831 | // /* GcRoot<mirror::Class>[] */ out = |
| 5832 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5833 | __ movl(out, Address(current_method, |
| 5834 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5835 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5836 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5837 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5838 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5839 | DCHECK(cls->CanCallRuntime()); |
| 5840 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5841 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5842 | codegen_->AddSlowPath(slow_path); |
| 5843 | |
| 5844 | if (!cls->IsInDexCache()) { |
| 5845 | __ testl(out, out); |
| 5846 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5847 | } |
| 5848 | |
| 5849 | if (cls->MustGenerateClinitCheck()) { |
| 5850 | GenerateClassInitializationCheck(slow_path, out); |
| 5851 | } else { |
| 5852 | __ Bind(slow_path->GetExitLabel()); |
| 5853 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5854 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5855 | } |
| 5856 | } |
| 5857 | |
| 5858 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5859 | LocationSummary* locations = |
| 5860 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5861 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5862 | if (check->HasUses()) { |
| 5863 | locations->SetOut(Location::SameAsFirstInput()); |
| 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5868 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5869 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5870 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5871 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5872 | GenerateClassInitializationCheck(slow_path, |
| 5873 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5874 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5875 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5876 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5877 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5878 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5879 | Immediate(mirror::Class::kStatusInitialized)); |
| 5880 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5881 | __ Bind(slow_path->GetExitLabel()); |
| 5882 | // No need for memory fence, thanks to the X86 memory model. |
| 5883 | } |
| 5884 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5885 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5886 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5887 | ? LocationSummary::kCallOnSlowPath |
| 5888 | : LocationSummary::kNoCall; |
| 5889 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5890 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5891 | locations->SetOut(Location::RequiresRegister()); |
| 5892 | } |
| 5893 | |
| 5894 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5895 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5896 | Location out_loc = locations->Out(); |
| 5897 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5898 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5899 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5900 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5901 | GenerateGcRootFieldLoad( |
| 5902 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5903 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5904 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5905 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5906 | GenerateGcRootFieldLoad( |
| 5907 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5908 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5909 | if (!load->IsInDexCache()) { |
| 5910 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5911 | codegen_->AddSlowPath(slow_path); |
| 5912 | __ testl(out, out); |
| 5913 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5914 | __ Bind(slow_path->GetExitLabel()); |
| 5915 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5916 | } |
| 5917 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5918 | static Address GetExceptionTlsAddress() { |
| 5919 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5920 | } |
| 5921 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5922 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5923 | LocationSummary* locations = |
| 5924 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5925 | locations->SetOut(Location::RequiresRegister()); |
| 5926 | } |
| 5927 | |
| 5928 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5929 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5930 | } |
| 5931 | |
| 5932 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5933 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5934 | } |
| 5935 | |
| 5936 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5937 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5938 | } |
| 5939 | |
| 5940 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5941 | LocationSummary* locations = |
| 5942 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5943 | InvokeRuntimeCallingConvention calling_convention; |
| 5944 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5945 | } |
| 5946 | |
| 5947 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5948 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5949 | instruction, |
| 5950 | instruction->GetDexPc(), |
| 5951 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5952 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5953 | } |
| 5954 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5955 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5956 | return kEmitCompilerReadBarrier && |
| 5957 | (kUseBakerReadBarrier || |
| 5958 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5959 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5960 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5961 | } |
| 5962 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5963 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5964 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5965 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5966 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5967 | case TypeCheckKind::kExactCheck: |
| 5968 | case TypeCheckKind::kAbstractClassCheck: |
| 5969 | case TypeCheckKind::kClassHierarchyCheck: |
| 5970 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5971 | call_kind = |
| 5972 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5973 | break; |
| 5974 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5975 | case TypeCheckKind::kUnresolvedCheck: |
| 5976 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5977 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5978 | break; |
| 5979 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5980 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5981 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5982 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5983 | locations->SetInAt(1, Location::Any()); |
| 5984 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5985 | locations->SetOut(Location::RequiresRegister()); |
| 5986 | // When read barriers are enabled, we need a temporary register for |
| 5987 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5988 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5989 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5990 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5991 | } |
| 5992 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5993 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5994 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5995 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5996 | Location obj_loc = locations->InAt(0); |
| 5997 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5998 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5999 | Location out_loc = locations->Out(); |
| 6000 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6001 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6002 | locations->GetTemp(0) : |
| 6003 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6004 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6005 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6006 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6007 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6008 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6009 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6010 | |
| 6011 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6012 | // Avoid null check if we know obj is not null. |
| 6013 | if (instruction->MustDoNullCheck()) { |
| 6014 | __ testl(obj, obj); |
| 6015 | __ j(kEqual, &zero); |
| 6016 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6017 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6018 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6019 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6020 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6021 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6022 | case TypeCheckKind::kExactCheck: { |
| 6023 | if (cls.IsRegister()) { |
| 6024 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6025 | } else { |
| 6026 | DCHECK(cls.IsStackSlot()) << cls; |
| 6027 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6028 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6029 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6030 | // Classes must be equal for the instanceof to succeed. |
| 6031 | __ j(kNotEqual, &zero); |
| 6032 | __ movl(out, Immediate(1)); |
| 6033 | __ jmp(&done); |
| 6034 | break; |
| 6035 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6036 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6037 | case TypeCheckKind::kAbstractClassCheck: { |
| 6038 | // If the class is abstract, we eagerly fetch the super class of the |
| 6039 | // object to avoid doing a comparison we know will fail. |
| 6040 | NearLabel loop; |
| 6041 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6042 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6043 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6044 | __ testl(out, out); |
| 6045 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6046 | __ j(kEqual, &done); |
| 6047 | if (cls.IsRegister()) { |
| 6048 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6049 | } else { |
| 6050 | DCHECK(cls.IsStackSlot()) << cls; |
| 6051 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6052 | } |
| 6053 | __ j(kNotEqual, &loop); |
| 6054 | __ movl(out, Immediate(1)); |
| 6055 | if (zero.IsLinked()) { |
| 6056 | __ jmp(&done); |
| 6057 | } |
| 6058 | break; |
| 6059 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6060 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6061 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6062 | // Walk over the class hierarchy to find a match. |
| 6063 | NearLabel loop, success; |
| 6064 | __ Bind(&loop); |
| 6065 | if (cls.IsRegister()) { |
| 6066 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6067 | } else { |
| 6068 | DCHECK(cls.IsStackSlot()) << cls; |
| 6069 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6070 | } |
| 6071 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6072 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6073 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6074 | __ testl(out, out); |
| 6075 | __ j(kNotEqual, &loop); |
| 6076 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6077 | __ jmp(&done); |
| 6078 | __ Bind(&success); |
| 6079 | __ movl(out, Immediate(1)); |
| 6080 | if (zero.IsLinked()) { |
| 6081 | __ jmp(&done); |
| 6082 | } |
| 6083 | break; |
| 6084 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6085 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6086 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6087 | // Do an exact check. |
| 6088 | NearLabel exact_check; |
| 6089 | if (cls.IsRegister()) { |
| 6090 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6091 | } else { |
| 6092 | DCHECK(cls.IsStackSlot()) << cls; |
| 6093 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6094 | } |
| 6095 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6096 | // 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] | 6097 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6098 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6099 | __ testl(out, out); |
| 6100 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6101 | __ j(kEqual, &done); |
| 6102 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6103 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6104 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6105 | __ movl(out, Immediate(1)); |
| 6106 | __ jmp(&done); |
| 6107 | break; |
| 6108 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6109 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6110 | case TypeCheckKind::kArrayCheck: { |
| 6111 | if (cls.IsRegister()) { |
| 6112 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6113 | } else { |
| 6114 | DCHECK(cls.IsStackSlot()) << cls; |
| 6115 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6116 | } |
| 6117 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6118 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6119 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6120 | codegen_->AddSlowPath(slow_path); |
| 6121 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6122 | __ movl(out, Immediate(1)); |
| 6123 | if (zero.IsLinked()) { |
| 6124 | __ jmp(&done); |
| 6125 | } |
| 6126 | break; |
| 6127 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6128 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6129 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6130 | case TypeCheckKind::kInterfaceCheck: { |
| 6131 | // 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] | 6132 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6133 | // cases. |
| 6134 | // |
| 6135 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6136 | // entry point without resorting to a type checking slow path |
| 6137 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6138 | // require to assign fixed registers for the inputs of this |
| 6139 | // HInstanceOf instruction (following the runtime calling |
| 6140 | // convention), which might be cluttered by the potential first |
| 6141 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6142 | // |
| 6143 | // TODO: Introduce a new runtime entry point taking the object |
| 6144 | // to test (instead of its class) as argument, and let it deal |
| 6145 | // with the read barrier issues. This will let us refactor this |
| 6146 | // case of the `switch` code as it was previously (with a direct |
| 6147 | // call to the runtime not using a type checking slow path). |
| 6148 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6149 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6150 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6151 | /* is_fatal */ false); |
| 6152 | codegen_->AddSlowPath(slow_path); |
| 6153 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6154 | if (zero.IsLinked()) { |
| 6155 | __ jmp(&done); |
| 6156 | } |
| 6157 | break; |
| 6158 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6159 | } |
| 6160 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6161 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6162 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6163 | __ xorl(out, out); |
| 6164 | } |
| 6165 | |
| 6166 | if (done.IsLinked()) { |
| 6167 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6168 | } |
| 6169 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6170 | if (slow_path != nullptr) { |
| 6171 | __ Bind(slow_path->GetExitLabel()); |
| 6172 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6173 | } |
| 6174 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6175 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6176 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6177 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6178 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6179 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6180 | case TypeCheckKind::kExactCheck: |
| 6181 | case TypeCheckKind::kAbstractClassCheck: |
| 6182 | case TypeCheckKind::kClassHierarchyCheck: |
| 6183 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6184 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6185 | LocationSummary::kCallOnSlowPath : |
| 6186 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6187 | break; |
| 6188 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6189 | case TypeCheckKind::kUnresolvedCheck: |
| 6190 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6191 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6192 | break; |
| 6193 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6194 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6195 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6196 | locations->SetInAt(1, Location::Any()); |
| 6197 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6198 | locations->AddTemp(Location::RequiresRegister()); |
| 6199 | // When read barriers are enabled, we need an additional temporary |
| 6200 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6201 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6202 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6207 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6208 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6209 | Location obj_loc = locations->InAt(0); |
| 6210 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6211 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6212 | Location temp_loc = locations->GetTemp(0); |
| 6213 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6214 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6215 | locations->GetTemp(1) : |
| 6216 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6217 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6218 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6219 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6220 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6221 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6222 | bool is_type_check_slow_path_fatal = |
| 6223 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6224 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6225 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6226 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6227 | !instruction->CanThrowIntoCatchBlock(); |
| 6228 | SlowPathCode* type_check_slow_path = |
| 6229 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6230 | is_type_check_slow_path_fatal); |
| 6231 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6232 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6233 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6234 | // Avoid null check if we know obj is not null. |
| 6235 | if (instruction->MustDoNullCheck()) { |
| 6236 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6237 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6238 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6240 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6241 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6242 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6243 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6244 | case TypeCheckKind::kExactCheck: |
| 6245 | case TypeCheckKind::kArrayCheck: { |
| 6246 | if (cls.IsRegister()) { |
| 6247 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6248 | } else { |
| 6249 | DCHECK(cls.IsStackSlot()) << cls; |
| 6250 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6251 | } |
| 6252 | // Jump to slow path for throwing the exception or doing a |
| 6253 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6254 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6255 | break; |
| 6256 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6257 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6258 | case TypeCheckKind::kAbstractClassCheck: { |
| 6259 | // If the class is abstract, we eagerly fetch the super class of the |
| 6260 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6261 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6262 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6263 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6264 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6265 | |
| 6266 | // If the class reference currently in `temp` is not null, jump |
| 6267 | // to the `compare_classes` label to compare it with the checked |
| 6268 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6269 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6270 | __ j(kNotEqual, &compare_classes); |
| 6271 | // Otherwise, jump to the slow path to throw the exception. |
| 6272 | // |
| 6273 | // But before, move back the object's class into `temp` before |
| 6274 | // going into the slow path, as it has been overwritten in the |
| 6275 | // meantime. |
| 6276 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6277 | GenerateReferenceLoadTwoRegisters( |
| 6278 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6279 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6280 | |
| 6281 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6282 | if (cls.IsRegister()) { |
| 6283 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6284 | } else { |
| 6285 | DCHECK(cls.IsStackSlot()) << cls; |
| 6286 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6287 | } |
| 6288 | __ j(kNotEqual, &loop); |
| 6289 | break; |
| 6290 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6291 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6292 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6293 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6294 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6295 | __ Bind(&loop); |
| 6296 | if (cls.IsRegister()) { |
| 6297 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6298 | } else { |
| 6299 | DCHECK(cls.IsStackSlot()) << cls; |
| 6300 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6301 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6302 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6303 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6304 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6305 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6306 | |
| 6307 | // If the class reference currently in `temp` is not null, jump |
| 6308 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6309 | __ testl(temp, temp); |
| 6310 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6311 | // Otherwise, jump to the slow path to throw the exception. |
| 6312 | // |
| 6313 | // But before, move back the object's class into `temp` before |
| 6314 | // going into the slow path, as it has been overwritten in the |
| 6315 | // meantime. |
| 6316 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6317 | GenerateReferenceLoadTwoRegisters( |
| 6318 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6319 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6320 | break; |
| 6321 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6322 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6324 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6325 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6326 | if (cls.IsRegister()) { |
| 6327 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6328 | } else { |
| 6329 | DCHECK(cls.IsStackSlot()) << cls; |
| 6330 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6331 | } |
| 6332 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6333 | |
| 6334 | // 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] | 6335 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6336 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | |
| 6338 | // If the component type is not null (i.e. the object is indeed |
| 6339 | // an array), jump to label `check_non_primitive_component_type` |
| 6340 | // to further check that this component type is not a primitive |
| 6341 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6342 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6343 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6344 | // Otherwise, jump to the slow path to throw the exception. |
| 6345 | // |
| 6346 | // But before, move back the object's class into `temp` before |
| 6347 | // going into the slow path, as it has been overwritten in the |
| 6348 | // meantime. |
| 6349 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6350 | GenerateReferenceLoadTwoRegisters( |
| 6351 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6352 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6353 | |
| 6354 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6355 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6356 | __ j(kEqual, &done); |
| 6357 | // Same comment as above regarding `temp` and the slow path. |
| 6358 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6359 | GenerateReferenceLoadTwoRegisters( |
| 6360 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6361 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6362 | break; |
| 6363 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6364 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6365 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6366 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6367 | // We always go into the type check slow path for the unresolved |
| 6368 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6369 | // |
| 6370 | // We cannot directly call the CheckCast runtime entry point |
| 6371 | // without resorting to a type checking slow path here (i.e. by |
| 6372 | // calling InvokeRuntime directly), as it would require to |
| 6373 | // assign fixed registers for the inputs of this HInstanceOf |
| 6374 | // instruction (following the runtime calling convention), which |
| 6375 | // might be cluttered by the potential first read barrier |
| 6376 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6377 | // |
| 6378 | // TODO: Introduce a new runtime entry point taking the object |
| 6379 | // to test (instead of its class) as argument, and let it deal |
| 6380 | // with the read barrier issues. This will let us refactor this |
| 6381 | // case of the `switch` code as it was previously (with a direct |
| 6382 | // call to the runtime not using a type checking slow path). |
| 6383 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6385 | break; |
| 6386 | } |
| 6387 | __ Bind(&done); |
| 6388 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6389 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6390 | } |
| 6391 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6392 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6393 | LocationSummary* locations = |
| 6394 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6395 | InvokeRuntimeCallingConvention calling_convention; |
| 6396 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6397 | } |
| 6398 | |
| 6399 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6400 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6401 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6402 | instruction, |
| 6403 | instruction->GetDexPc(), |
| 6404 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6405 | if (instruction->IsEnter()) { |
| 6406 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6407 | } else { |
| 6408 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6409 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6410 | } |
| 6411 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6412 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6413 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6414 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6415 | |
| 6416 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6417 | LocationSummary* locations = |
| 6418 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6419 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6420 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6421 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6422 | locations->SetInAt(1, Location::Any()); |
| 6423 | locations->SetOut(Location::SameAsFirstInput()); |
| 6424 | } |
| 6425 | |
| 6426 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6427 | HandleBitwiseOperation(instruction); |
| 6428 | } |
| 6429 | |
| 6430 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6431 | HandleBitwiseOperation(instruction); |
| 6432 | } |
| 6433 | |
| 6434 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6435 | HandleBitwiseOperation(instruction); |
| 6436 | } |
| 6437 | |
| 6438 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6439 | LocationSummary* locations = instruction->GetLocations(); |
| 6440 | Location first = locations->InAt(0); |
| 6441 | Location second = locations->InAt(1); |
| 6442 | DCHECK(first.Equals(locations->Out())); |
| 6443 | |
| 6444 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6445 | if (second.IsRegister()) { |
| 6446 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6447 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6448 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6449 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6450 | } else { |
| 6451 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6452 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6453 | } |
| 6454 | } else if (second.IsConstant()) { |
| 6455 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6456 | __ andl(first.AsRegister<Register>(), |
| 6457 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6458 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6459 | __ orl(first.AsRegister<Register>(), |
| 6460 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6461 | } else { |
| 6462 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6463 | __ xorl(first.AsRegister<Register>(), |
| 6464 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6465 | } |
| 6466 | } else { |
| 6467 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6468 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6469 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6470 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6471 | } else { |
| 6472 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6473 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6474 | } |
| 6475 | } |
| 6476 | } else { |
| 6477 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6478 | if (second.IsRegisterPair()) { |
| 6479 | if (instruction->IsAnd()) { |
| 6480 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6481 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6482 | } else if (instruction->IsOr()) { |
| 6483 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6484 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6485 | } else { |
| 6486 | DCHECK(instruction->IsXor()); |
| 6487 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6488 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6489 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6490 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6491 | if (instruction->IsAnd()) { |
| 6492 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6493 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6494 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6495 | } else if (instruction->IsOr()) { |
| 6496 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6497 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6498 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6499 | } else { |
| 6500 | DCHECK(instruction->IsXor()); |
| 6501 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6502 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6503 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6504 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6505 | } else { |
| 6506 | DCHECK(second.IsConstant()) << second; |
| 6507 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6508 | int32_t low_value = Low32Bits(value); |
| 6509 | int32_t high_value = High32Bits(value); |
| 6510 | Immediate low(low_value); |
| 6511 | Immediate high(high_value); |
| 6512 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6513 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6514 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6515 | if (low_value == 0) { |
| 6516 | __ xorl(first_low, first_low); |
| 6517 | } else if (low_value != -1) { |
| 6518 | __ andl(first_low, low); |
| 6519 | } |
| 6520 | if (high_value == 0) { |
| 6521 | __ xorl(first_high, first_high); |
| 6522 | } else if (high_value != -1) { |
| 6523 | __ andl(first_high, high); |
| 6524 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6525 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6526 | if (low_value != 0) { |
| 6527 | __ orl(first_low, low); |
| 6528 | } |
| 6529 | if (high_value != 0) { |
| 6530 | __ orl(first_high, high); |
| 6531 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6532 | } else { |
| 6533 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6534 | if (low_value != 0) { |
| 6535 | __ xorl(first_low, low); |
| 6536 | } |
| 6537 | if (high_value != 0) { |
| 6538 | __ xorl(first_high, high); |
| 6539 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6540 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6541 | } |
| 6542 | } |
| 6543 | } |
| 6544 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6545 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6546 | Location out, |
| 6547 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6548 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6549 | Register out_reg = out.AsRegister<Register>(); |
| 6550 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6551 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6552 | if (kUseBakerReadBarrier) { |
| 6553 | // Load with fast path based Baker's read barrier. |
| 6554 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6555 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6556 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6557 | } else { |
| 6558 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6559 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6560 | // in the following move operation, as we will need it for the |
| 6561 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6562 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6563 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6564 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6565 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6566 | } |
| 6567 | } else { |
| 6568 | // Plain load with no read barrier. |
| 6569 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6570 | __ movl(out_reg, Address(out_reg, offset)); |
| 6571 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6572 | } |
| 6573 | } |
| 6574 | |
| 6575 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6576 | Location out, |
| 6577 | Location obj, |
| 6578 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6579 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6580 | Register out_reg = out.AsRegister<Register>(); |
| 6581 | Register obj_reg = obj.AsRegister<Register>(); |
| 6582 | if (kEmitCompilerReadBarrier) { |
| 6583 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6584 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6585 | // Load with fast path based Baker's read barrier. |
| 6586 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6587 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6588 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6589 | } else { |
| 6590 | // Load with slow path based read barrier. |
| 6591 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6592 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6593 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6594 | } |
| 6595 | } else { |
| 6596 | // Plain load with no read barrier. |
| 6597 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6598 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6599 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6604 | Location root, |
| 6605 | Register obj, |
| 6606 | uint32_t offset) { |
| 6607 | Register root_reg = root.AsRegister<Register>(); |
| 6608 | if (kEmitCompilerReadBarrier) { |
| 6609 | if (kUseBakerReadBarrier) { |
| 6610 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6611 | // Baker's read barrier are used: |
| 6612 | // |
| 6613 | // root = obj.field; |
| 6614 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6615 | // root = ReadBarrier::Mark(root) |
| 6616 | // } |
| 6617 | |
| 6618 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6619 | __ movl(root_reg, Address(obj, offset)); |
| 6620 | static_assert( |
| 6621 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6622 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6623 | "have different sizes."); |
| 6624 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6625 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6626 | "have different sizes."); |
| 6627 | |
| 6628 | // Slow path used to mark the GC root `root`. |
| 6629 | SlowPathCode* slow_path = |
| 6630 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6631 | codegen_->AddSlowPath(slow_path); |
| 6632 | |
| 6633 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6634 | Immediate(0)); |
| 6635 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6636 | __ Bind(slow_path->GetExitLabel()); |
| 6637 | } else { |
| 6638 | // GC root loaded through a slow path for read barriers other |
| 6639 | // than Baker's. |
| 6640 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6641 | __ leal(root_reg, Address(obj, offset)); |
| 6642 | // /* mirror::Object* */ root = root->Read() |
| 6643 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6644 | } |
| 6645 | } else { |
| 6646 | // Plain GC root load with no read barrier. |
| 6647 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6648 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6649 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6650 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6651 | } |
| 6652 | } |
| 6653 | |
| 6654 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6655 | Location ref, |
| 6656 | Register obj, |
| 6657 | uint32_t offset, |
| 6658 | Location temp, |
| 6659 | bool needs_null_check) { |
| 6660 | DCHECK(kEmitCompilerReadBarrier); |
| 6661 | DCHECK(kUseBakerReadBarrier); |
| 6662 | |
| 6663 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6664 | Address src(obj, offset); |
| 6665 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6666 | } |
| 6667 | |
| 6668 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6669 | Location ref, |
| 6670 | Register obj, |
| 6671 | uint32_t data_offset, |
| 6672 | Location index, |
| 6673 | Location temp, |
| 6674 | bool needs_null_check) { |
| 6675 | DCHECK(kEmitCompilerReadBarrier); |
| 6676 | DCHECK(kUseBakerReadBarrier); |
| 6677 | |
| 6678 | // /* HeapReference<Object> */ ref = |
| 6679 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6680 | Address src = index.IsConstant() ? |
| 6681 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6682 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6683 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6684 | } |
| 6685 | |
| 6686 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6687 | Location ref, |
| 6688 | Register obj, |
| 6689 | const Address& src, |
| 6690 | Location temp, |
| 6691 | bool needs_null_check) { |
| 6692 | DCHECK(kEmitCompilerReadBarrier); |
| 6693 | DCHECK(kUseBakerReadBarrier); |
| 6694 | |
| 6695 | // In slow path based read barriers, the read barrier call is |
| 6696 | // inserted after the original load. However, in fast path based |
| 6697 | // Baker's read barriers, we need to perform the load of |
| 6698 | // mirror::Object::monitor_ *before* the original reference load. |
| 6699 | // This load-load ordering is required by the read barrier. |
| 6700 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6701 | // |
| 6702 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6703 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6704 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6705 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6706 | // if (is_gray) { |
| 6707 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6708 | // } |
| 6709 | // |
| 6710 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6711 | // slightly more complex as: |
| 6712 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6713 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6714 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6715 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6716 | // - it performs additional checks that we do not do here for |
| 6717 | // performance reasons. |
| 6718 | |
| 6719 | Register ref_reg = ref.AsRegister<Register>(); |
| 6720 | Register temp_reg = temp.AsRegister<Register>(); |
| 6721 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6722 | |
| 6723 | // /* int32_t */ monitor = obj->monitor_ |
| 6724 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6725 | if (needs_null_check) { |
| 6726 | MaybeRecordImplicitNullCheck(instruction); |
| 6727 | } |
| 6728 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6729 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6730 | "art::LockWord and int32_t have different sizes."); |
| 6731 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6732 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6733 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6734 | static_assert( |
| 6735 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6736 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6737 | |
| 6738 | // Load fence to prevent load-load reordering. |
| 6739 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6740 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6741 | |
| 6742 | // The actual reference load. |
| 6743 | // /* HeapReference<Object> */ ref = *src |
| 6744 | __ movl(ref_reg, src); |
| 6745 | |
| 6746 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6747 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6748 | |
| 6749 | // Slow path used to mark the object `ref` when it is gray. |
| 6750 | SlowPathCode* slow_path = |
| 6751 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6752 | AddSlowPath(slow_path); |
| 6753 | |
| 6754 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6755 | // ref = ReadBarrier::Mark(ref); |
| 6756 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6757 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6758 | __ Bind(slow_path->GetExitLabel()); |
| 6759 | } |
| 6760 | |
| 6761 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6762 | Location out, |
| 6763 | Location ref, |
| 6764 | Location obj, |
| 6765 | uint32_t offset, |
| 6766 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6767 | DCHECK(kEmitCompilerReadBarrier); |
| 6768 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6769 | // Insert a slow path based read barrier *after* the reference load. |
| 6770 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6771 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6772 | // reference will be carried out by the runtime within the slow |
| 6773 | // path. |
| 6774 | // |
| 6775 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6776 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6777 | // not used by the artReadBarrierSlow entry point. |
| 6778 | // |
| 6779 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6780 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6781 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6782 | AddSlowPath(slow_path); |
| 6783 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6784 | __ jmp(slow_path->GetEntryLabel()); |
| 6785 | __ Bind(slow_path->GetExitLabel()); |
| 6786 | } |
| 6787 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6788 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6789 | Location out, |
| 6790 | Location ref, |
| 6791 | Location obj, |
| 6792 | uint32_t offset, |
| 6793 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6794 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6795 | // Baker's read barriers shall be handled by the fast path |
| 6796 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6797 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6798 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6799 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6800 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6801 | } else if (kPoisonHeapReferences) { |
| 6802 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6803 | } |
| 6804 | } |
| 6805 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6806 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6807 | Location out, |
| 6808 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6809 | DCHECK(kEmitCompilerReadBarrier); |
| 6810 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6811 | // Insert a slow path based read barrier *after* the GC root load. |
| 6812 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6813 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6814 | // not need to do anything special for this here. |
| 6815 | SlowPathCode* slow_path = |
| 6816 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6817 | AddSlowPath(slow_path); |
| 6818 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6819 | __ jmp(slow_path->GetEntryLabel()); |
| 6820 | __ Bind(slow_path->GetExitLabel()); |
| 6821 | } |
| 6822 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6823 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6824 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6825 | LOG(FATAL) << "Unreachable"; |
| 6826 | } |
| 6827 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6828 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6829 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6830 | LOG(FATAL) << "Unreachable"; |
| 6831 | } |
| 6832 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6833 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6834 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6835 | LocationSummary* locations = |
| 6836 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6838 | } |
| 6839 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6840 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6841 | int32_t lower_bound, |
| 6842 | uint32_t num_entries, |
| 6843 | HBasicBlock* switch_block, |
| 6844 | HBasicBlock* default_block) { |
| 6845 | // Figure out the correct compare values and jump conditions. |
| 6846 | // Handle the first compare/branch as a special case because it might |
| 6847 | // jump to the default case. |
| 6848 | DCHECK_GT(num_entries, 2u); |
| 6849 | Condition first_condition; |
| 6850 | uint32_t index; |
| 6851 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6852 | if (lower_bound != 0) { |
| 6853 | first_condition = kLess; |
| 6854 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6855 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6856 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6857 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6858 | index = 1; |
| 6859 | } else { |
| 6860 | // Handle all the compare/jumps below. |
| 6861 | first_condition = kBelow; |
| 6862 | index = 0; |
| 6863 | } |
| 6864 | |
| 6865 | // Handle the rest of the compare/jumps. |
| 6866 | for (; index + 1 < num_entries; index += 2) { |
| 6867 | int32_t compare_to_value = lower_bound + index + 1; |
| 6868 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6869 | // Jump to successors[index] if value < case_value[index]. |
| 6870 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6871 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6872 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6873 | } |
| 6874 | |
| 6875 | if (index != num_entries) { |
| 6876 | // There are an odd number of entries. Handle the last one. |
| 6877 | DCHECK_EQ(index + 1, num_entries); |
| 6878 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6879 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6883 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6884 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6885 | } |
| 6886 | } |
| 6887 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6888 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6889 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6890 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6891 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6892 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6893 | |
| 6894 | GenPackedSwitchWithCompares(value_reg, |
| 6895 | lower_bound, |
| 6896 | num_entries, |
| 6897 | switch_instr->GetBlock(), |
| 6898 | switch_instr->GetDefaultBlock()); |
| 6899 | } |
| 6900 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6901 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6902 | LocationSummary* locations = |
| 6903 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6904 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6905 | |
| 6906 | // Constant area pointer. |
| 6907 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6908 | |
| 6909 | // And the temporary we need. |
| 6910 | locations->AddTemp(Location::RequiresRegister()); |
| 6911 | } |
| 6912 | |
| 6913 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6914 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6915 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6916 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6917 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6918 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6919 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6920 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6921 | GenPackedSwitchWithCompares(value_reg, |
| 6922 | lower_bound, |
| 6923 | num_entries, |
| 6924 | switch_instr->GetBlock(), |
| 6925 | default_block); |
| 6926 | return; |
| 6927 | } |
| 6928 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6929 | // Optimizing has a jump area. |
| 6930 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6931 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6932 | |
| 6933 | // Remove the bias, if needed. |
| 6934 | if (lower_bound != 0) { |
| 6935 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6936 | value_reg = temp_reg; |
| 6937 | } |
| 6938 | |
| 6939 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6940 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6941 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6942 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6943 | |
| 6944 | // We are in the range of the table. |
| 6945 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6946 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6947 | |
| 6948 | // Compute the actual target address by adding in constant_area. |
| 6949 | __ addl(temp_reg, constant_area); |
| 6950 | |
| 6951 | // And jump. |
| 6952 | __ jmp(temp_reg); |
| 6953 | } |
| 6954 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6955 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6956 | HX86ComputeBaseMethodAddress* insn) { |
| 6957 | LocationSummary* locations = |
| 6958 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6959 | locations->SetOut(Location::RequiresRegister()); |
| 6960 | } |
| 6961 | |
| 6962 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6963 | HX86ComputeBaseMethodAddress* insn) { |
| 6964 | LocationSummary* locations = insn->GetLocations(); |
| 6965 | Register reg = locations->Out().AsRegister<Register>(); |
| 6966 | |
| 6967 | // Generate call to next instruction. |
| 6968 | Label next_instruction; |
| 6969 | __ call(&next_instruction); |
| 6970 | __ Bind(&next_instruction); |
| 6971 | |
| 6972 | // Remember this offset for later use with constant area. |
| 6973 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6974 | |
| 6975 | // Grab the return address off the stack. |
| 6976 | __ popl(reg); |
| 6977 | } |
| 6978 | |
| 6979 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6980 | HX86LoadFromConstantTable* insn) { |
| 6981 | LocationSummary* locations = |
| 6982 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6983 | |
| 6984 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6985 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6986 | |
| 6987 | // 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] | 6988 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6989 | return; |
| 6990 | } |
| 6991 | |
| 6992 | switch (insn->GetType()) { |
| 6993 | case Primitive::kPrimFloat: |
| 6994 | case Primitive::kPrimDouble: |
| 6995 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6996 | break; |
| 6997 | |
| 6998 | case Primitive::kPrimInt: |
| 6999 | locations->SetOut(Location::RequiresRegister()); |
| 7000 | break; |
| 7001 | |
| 7002 | default: |
| 7003 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7004 | } |
| 7005 | } |
| 7006 | |
| 7007 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7008 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7009 | return; |
| 7010 | } |
| 7011 | |
| 7012 | LocationSummary* locations = insn->GetLocations(); |
| 7013 | Location out = locations->Out(); |
| 7014 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7015 | HConstant *value = insn->GetConstant(); |
| 7016 | |
| 7017 | switch (insn->GetType()) { |
| 7018 | case Primitive::kPrimFloat: |
| 7019 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7020 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7021 | break; |
| 7022 | |
| 7023 | case Primitive::kPrimDouble: |
| 7024 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7025 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7026 | break; |
| 7027 | |
| 7028 | case Primitive::kPrimInt: |
| 7029 | __ movl(out.AsRegister<Register>(), |
| 7030 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7031 | break; |
| 7032 | |
| 7033 | default: |
| 7034 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7035 | } |
| 7036 | } |
| 7037 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7038 | /** |
| 7039 | * Class to handle late fixup of offsets into constant area. |
| 7040 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7041 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7042 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7043 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7044 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7045 | |
| 7046 | protected: |
| 7047 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7048 | |
| 7049 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7050 | |
| 7051 | private: |
| 7052 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7053 | // Patch the correct offset for the instruction. The place to patch is the |
| 7054 | // last 4 bytes of the instruction. |
| 7055 | // The value to patch is the distance from the offset in the constant area |
| 7056 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7057 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7058 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7059 | |
| 7060 | // Patch in the right value. |
| 7061 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7062 | } |
| 7063 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7064 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7065 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7066 | }; |
| 7067 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7068 | /** |
| 7069 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7070 | * constant area. |
| 7071 | */ |
| 7072 | class JumpTableRIPFixup : public RIPFixup { |
| 7073 | public: |
| 7074 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7075 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7076 | |
| 7077 | void CreateJumpTable() { |
| 7078 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7079 | |
| 7080 | // Ensure that the reference to the jump table has the correct offset. |
| 7081 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7082 | SetOffset(offset_in_constant_table); |
| 7083 | |
| 7084 | // The label values in the jump table are computed relative to the |
| 7085 | // instruction addressing the constant area. |
| 7086 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7087 | |
| 7088 | // Populate the jump table with the correct values for the jump table. |
| 7089 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7090 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7091 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7092 | // The value that we want is the target offset - the position of the table. |
| 7093 | for (int32_t i = 0; i < num_entries; i++) { |
| 7094 | HBasicBlock* b = successors[i]; |
| 7095 | Label* l = codegen_->GetLabelOf(b); |
| 7096 | DCHECK(l->IsBound()); |
| 7097 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7098 | assembler->AppendInt32(offset_to_block); |
| 7099 | } |
| 7100 | } |
| 7101 | |
| 7102 | private: |
| 7103 | const HX86PackedSwitch* switch_instr_; |
| 7104 | }; |
| 7105 | |
| 7106 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7107 | // Generate the constant area if needed. |
| 7108 | X86Assembler* assembler = GetAssembler(); |
| 7109 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7110 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7111 | // byte values. |
| 7112 | assembler->Align(4, 0); |
| 7113 | constant_area_start_ = assembler->CodeSize(); |
| 7114 | |
| 7115 | // Populate any jump tables. |
| 7116 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7117 | jump_table->CreateJumpTable(); |
| 7118 | } |
| 7119 | |
| 7120 | // And now add the constant area to the generated code. |
| 7121 | assembler->AddConstantArea(); |
| 7122 | } |
| 7123 | |
| 7124 | // And finish up. |
| 7125 | CodeGenerator::Finalize(allocator); |
| 7126 | } |
| 7127 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7128 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7129 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7130 | return Address(reg, kDummy32BitOffset, fixup); |
| 7131 | } |
| 7132 | |
| 7133 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7134 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7135 | return Address(reg, kDummy32BitOffset, fixup); |
| 7136 | } |
| 7137 | |
| 7138 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7139 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7140 | return Address(reg, kDummy32BitOffset, fixup); |
| 7141 | } |
| 7142 | |
| 7143 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7144 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7145 | return Address(reg, kDummy32BitOffset, fixup); |
| 7146 | } |
| 7147 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7148 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7149 | if (value == 0) { |
| 7150 | __ xorl(dest, dest); |
| 7151 | } else { |
| 7152 | __ movl(dest, Immediate(value)); |
| 7153 | } |
| 7154 | } |
| 7155 | |
| 7156 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7157 | if (value == 0) { |
| 7158 | __ testl(dest, dest); |
| 7159 | } else { |
| 7160 | __ cmpl(dest, Immediate(value)); |
| 7161 | } |
| 7162 | } |
| 7163 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7164 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7165 | Register reg, |
| 7166 | Register value) { |
| 7167 | // Create a fixup to be used to create and address the jump table. |
| 7168 | JumpTableRIPFixup* table_fixup = |
| 7169 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7170 | |
| 7171 | // We have to populate the jump tables. |
| 7172 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7173 | |
| 7174 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7175 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7176 | } |
| 7177 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7178 | // TODO: target as memory. |
| 7179 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7180 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7181 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7182 | return; |
| 7183 | } |
| 7184 | |
| 7185 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7186 | |
| 7187 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7188 | if (target.Equals(return_loc)) { |
| 7189 | return; |
| 7190 | } |
| 7191 | |
| 7192 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7193 | // with the else branch. |
| 7194 | if (type == Primitive::kPrimLong) { |
| 7195 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7196 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7197 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7198 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7199 | } else { |
| 7200 | // Let the parallel move resolver take care of all of this. |
| 7201 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7202 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7203 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7204 | } |
| 7205 | } |
| 7206 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7207 | #undef __ |
| 7208 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7209 | } // namespace x86 |
| 7210 | } // namespace art |