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" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; |
| 47 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 53 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 55 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 60 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 61 | // Live registers will be restored in the catch block if caught. |
| 62 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 63 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 64 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 65 | instruction_, |
| 66 | instruction_->GetDexPc(), |
| 67 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 68 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | } |
| 70 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 71 | bool IsFatal() const OVERRIDE { return true; } |
| 72 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 73 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 74 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 77 | }; |
| 78 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 79 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 81 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 83 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 84 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 86 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 87 | // Live registers will be restored in the catch block if caught. |
| 88 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 89 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 90 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 91 | instruction_, |
| 92 | instruction_->GetDexPc(), |
| 93 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 94 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 97 | bool IsFatal() const OVERRIDE { return true; } |
| 98 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 99 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 100 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 103 | }; |
| 104 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 105 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 107 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 108 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 110 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 112 | if (is_div_) { |
| 113 | __ negl(reg_); |
| 114 | } else { |
| 115 | __ movl(reg_, Immediate(0)); |
| 116 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | __ jmp(GetExitLabel()); |
| 118 | } |
| 119 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 120 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 121 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | private: |
| 123 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 124 | bool is_div_; |
| 125 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 128 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 130 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 132 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 134 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 135 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 136 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 137 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 138 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 139 | // Live registers will be restored in the catch block if caught. |
| 140 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 141 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 143 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 144 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 145 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 146 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 147 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 148 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 149 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 150 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 151 | instruction_, |
| 152 | instruction_->GetDexPc(), |
| 153 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 154 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 157 | bool IsFatal() const OVERRIDE { return true; } |
| 158 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 159 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 160 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 163 | }; |
| 164 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 165 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 167 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 168 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 170 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 171 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 172 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 173 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 174 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 175 | instruction_, |
| 176 | instruction_->GetDexPc(), |
| 177 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 178 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 179 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 180 | if (successor_ == nullptr) { |
| 181 | __ jmp(GetReturnLabel()); |
| 182 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 183 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 184 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 187 | Label* GetReturnLabel() { |
| 188 | DCHECK(successor_ == nullptr); |
| 189 | return &return_label_; |
| 190 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 192 | HBasicBlock* GetSuccessor() const { |
| 193 | return successor_; |
| 194 | } |
| 195 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 196 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 197 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 198 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 199 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 200 | Label return_label_; |
| 201 | |
| 202 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 203 | }; |
| 204 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 205 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 206 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 207 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 208 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 209 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 210 | LocationSummary* locations = instruction_->GetLocations(); |
| 211 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 212 | |
| 213 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 214 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 215 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 216 | |
| 217 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 218 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 219 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 220 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 221 | instruction_, |
| 222 | instruction_->GetDexPc(), |
| 223 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 224 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 225 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 226 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 227 | |
| 228 | __ jmp(GetExitLabel()); |
| 229 | } |
| 230 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 231 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 232 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 233 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 234 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 235 | }; |
| 236 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 237 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 | public: |
| 239 | LoadClassSlowPathX86(HLoadClass* cls, |
| 240 | HInstruction* at, |
| 241 | uint32_t dex_pc, |
| 242 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 243 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 245 | } |
| 246 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 247 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 248 | LocationSummary* locations = at_->GetLocations(); |
| 249 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 250 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 251 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 | |
| 253 | InvokeRuntimeCallingConvention calling_convention; |
| 254 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 255 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 256 | : QUICK_ENTRY_POINT(pInitializeType), |
| 257 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 258 | if (do_clinit_) { |
| 259 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 260 | } else { |
| 261 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 262 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 | |
| 264 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 265 | Location out = locations->Out(); |
| 266 | if (out.IsValid()) { |
| 267 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 268 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 271 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 272 | __ jmp(GetExitLabel()); |
| 273 | } |
| 274 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 275 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 276 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 | private: |
| 278 | // The class this slow path will load. |
| 279 | HLoadClass* const cls_; |
| 280 | |
| 281 | // The instruction where this slow path is happening. |
| 282 | // (Might be the load class or an initialization check). |
| 283 | HInstruction* const at_; |
| 284 | |
| 285 | // The dex PC of `at_`. |
| 286 | const uint32_t dex_pc_; |
| 287 | |
| 288 | // Whether to initialize the class. |
| 289 | const bool do_clinit_; |
| 290 | |
| 291 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 292 | }; |
| 293 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 294 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 296 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 297 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 299 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 300 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 301 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 302 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 303 | DCHECK(instruction_->IsCheckCast() |
| 304 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 | |
| 306 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 307 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 308 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 309 | if (!is_fatal_) { |
| 310 | SaveLiveRegisters(codegen, locations); |
| 311 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 | |
| 313 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 314 | // move resolver. |
| 315 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 316 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 317 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 318 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 319 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 320 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 321 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 322 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 324 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 325 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 326 | instruction_, |
| 327 | instruction_->GetDexPc(), |
| 328 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 329 | CheckEntrypointTypes< |
| 330 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 331 | } else { |
| 332 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 333 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 334 | instruction_, |
| 335 | instruction_->GetDexPc(), |
| 336 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 337 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 | if (!is_fatal_) { |
| 341 | if (instruction_->IsInstanceOf()) { |
| 342 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 343 | } |
| 344 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | __ jmp(GetExitLabel()); |
| 347 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 350 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 352 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 354 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 355 | |
| 356 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 357 | }; |
| 358 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 359 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 360 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 361 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 362 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 363 | |
| 364 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 365 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 366 | __ Bind(GetEntryLabel()); |
| 367 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 368 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 369 | instruction_, |
| 370 | instruction_->GetDexPc(), |
| 371 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 372 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 375 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 376 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 377 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 379 | }; |
| 380 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 381 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 382 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 383 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 384 | |
| 385 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 386 | LocationSummary* locations = instruction_->GetLocations(); |
| 387 | __ Bind(GetEntryLabel()); |
| 388 | SaveLiveRegisters(codegen, locations); |
| 389 | |
| 390 | InvokeRuntimeCallingConvention calling_convention; |
| 391 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 392 | parallel_move.AddMove( |
| 393 | locations->InAt(0), |
| 394 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 395 | Primitive::kPrimNot, |
| 396 | nullptr); |
| 397 | parallel_move.AddMove( |
| 398 | locations->InAt(1), |
| 399 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 400 | Primitive::kPrimInt, |
| 401 | nullptr); |
| 402 | parallel_move.AddMove( |
| 403 | locations->InAt(2), |
| 404 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 405 | Primitive::kPrimNot, |
| 406 | nullptr); |
| 407 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 408 | |
| 409 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 410 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 411 | instruction_, |
| 412 | instruction_->GetDexPc(), |
| 413 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 414 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 415 | RestoreLiveRegisters(codegen, locations); |
| 416 | __ jmp(GetExitLabel()); |
| 417 | } |
| 418 | |
| 419 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 420 | |
| 421 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 423 | }; |
| 424 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 425 | // Slow path marking an object during a read barrier. |
| 426 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 427 | public: |
| 428 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 429 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 430 | DCHECK(kEmitCompilerReadBarrier); |
| 431 | } |
| 432 | |
| 433 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 434 | |
| 435 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 436 | LocationSummary* locations = instruction_->GetLocations(); |
| 437 | Register reg_out = out_.AsRegister<Register>(); |
| 438 | DCHECK(locations->CanCall()); |
| 439 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 440 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 441 | instruction_->IsStaticFieldGet() || |
| 442 | instruction_->IsArrayGet() || |
| 443 | instruction_->IsLoadClass() || |
| 444 | instruction_->IsLoadString() || |
| 445 | instruction_->IsInstanceOf() || |
| 446 | instruction_->IsCheckCast()) |
| 447 | << "Unexpected instruction in read barrier marking slow path: " |
| 448 | << instruction_->DebugName(); |
| 449 | |
| 450 | __ Bind(GetEntryLabel()); |
| 451 | SaveLiveRegisters(codegen, locations); |
| 452 | |
| 453 | InvokeRuntimeCallingConvention calling_convention; |
| 454 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 455 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 456 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 457 | instruction_, |
| 458 | instruction_->GetDexPc(), |
| 459 | this); |
| 460 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 461 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 462 | |
| 463 | RestoreLiveRegisters(codegen, locations); |
| 464 | __ jmp(GetExitLabel()); |
| 465 | } |
| 466 | |
| 467 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 | const Location out_; |
| 469 | const Location obj_; |
| 470 | |
| 471 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 472 | }; |
| 473 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 474 | // Slow path generating a read barrier for a heap reference. |
| 475 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 476 | public: |
| 477 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 478 | Location out, |
| 479 | Location ref, |
| 480 | Location obj, |
| 481 | uint32_t offset, |
| 482 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 483 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 484 | out_(out), |
| 485 | ref_(ref), |
| 486 | obj_(obj), |
| 487 | offset_(offset), |
| 488 | index_(index) { |
| 489 | DCHECK(kEmitCompilerReadBarrier); |
| 490 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 491 | // has been overwritten by (or after) the heap object reference load |
| 492 | // to be instrumented, e.g.: |
| 493 | // |
| 494 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 495 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 496 | // |
| 497 | // In that case, we have lost the information about the original |
| 498 | // object, and the emitted read barrier cannot work properly. |
| 499 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 500 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 501 | } |
| 502 | |
| 503 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 504 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 505 | LocationSummary* locations = instruction_->GetLocations(); |
| 506 | Register reg_out = out_.AsRegister<Register>(); |
| 507 | DCHECK(locations->CanCall()); |
| 508 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 509 | DCHECK(!instruction_->IsInvoke() || |
| 510 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 511 | instruction_->GetLocations()->Intrinsified())) |
| 512 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 513 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 514 | |
| 515 | __ Bind(GetEntryLabel()); |
| 516 | SaveLiveRegisters(codegen, locations); |
| 517 | |
| 518 | // We may have to change the index's value, but as `index_` is a |
| 519 | // constant member (like other "inputs" of this slow path), |
| 520 | // introduce a copy of it, `index`. |
| 521 | Location index = index_; |
| 522 | if (index_.IsValid()) { |
| 523 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 524 | if (instruction_->IsArrayGet()) { |
| 525 | // Compute the actual memory offset and store it in `index`. |
| 526 | Register index_reg = index_.AsRegister<Register>(); |
| 527 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 528 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 529 | // We are about to change the value of `index_reg` (see the |
| 530 | // calls to art::x86::X86Assembler::shll and |
| 531 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 532 | // not been saved by the previous call to |
| 533 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 534 | // callee-save register -- |
| 535 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 536 | // callee-save registers, as it has been designed with the |
| 537 | // assumption that callee-save registers are supposed to be |
| 538 | // handled by the called function. So, as a callee-save |
| 539 | // register, `index_reg` _would_ eventually be saved onto |
| 540 | // the stack, but it would be too late: we would have |
| 541 | // changed its value earlier. Therefore, we manually save |
| 542 | // it here into another freely available register, |
| 543 | // `free_reg`, chosen of course among the caller-save |
| 544 | // registers (as a callee-save `free_reg` register would |
| 545 | // exhibit the same problem). |
| 546 | // |
| 547 | // Note we could have requested a temporary register from |
| 548 | // the register allocator instead; but we prefer not to, as |
| 549 | // this is a slow path, and we know we can find a |
| 550 | // caller-save register that is available. |
| 551 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 552 | __ movl(free_reg, index_reg); |
| 553 | index_reg = free_reg; |
| 554 | index = Location::RegisterLocation(index_reg); |
| 555 | } else { |
| 556 | // The initial register stored in `index_` has already been |
| 557 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 558 | // (as it is not a callee-save register), so we can freely |
| 559 | // use it. |
| 560 | } |
| 561 | // Shifting the index value contained in `index_reg` by the scale |
| 562 | // factor (2) cannot overflow in practice, as the runtime is |
| 563 | // unable to allocate object arrays with a size larger than |
| 564 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 565 | __ shll(index_reg, Immediate(TIMES_4)); |
| 566 | static_assert( |
| 567 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 568 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 569 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 570 | } else { |
| 571 | DCHECK(instruction_->IsInvoke()); |
| 572 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 573 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 574 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 575 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 576 | DCHECK_EQ(offset_, 0U); |
| 577 | DCHECK(index_.IsRegisterPair()); |
| 578 | // UnsafeGet's offset location is a register pair, the low |
| 579 | // part contains the correct offset. |
| 580 | index = index_.ToLow(); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | // We're moving two or three locations to locations that could |
| 585 | // overlap, so we need a parallel move resolver. |
| 586 | InvokeRuntimeCallingConvention calling_convention; |
| 587 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 588 | parallel_move.AddMove(ref_, |
| 589 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 590 | Primitive::kPrimNot, |
| 591 | nullptr); |
| 592 | parallel_move.AddMove(obj_, |
| 593 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 594 | Primitive::kPrimNot, |
| 595 | nullptr); |
| 596 | if (index.IsValid()) { |
| 597 | parallel_move.AddMove(index, |
| 598 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 599 | Primitive::kPrimInt, |
| 600 | nullptr); |
| 601 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 602 | } else { |
| 603 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 604 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 605 | } |
| 606 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 607 | instruction_, |
| 608 | instruction_->GetDexPc(), |
| 609 | this); |
| 610 | CheckEntrypointTypes< |
| 611 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 612 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 613 | |
| 614 | RestoreLiveRegisters(codegen, locations); |
| 615 | __ jmp(GetExitLabel()); |
| 616 | } |
| 617 | |
| 618 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 619 | |
| 620 | private: |
| 621 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 622 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 623 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 624 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 625 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 626 | return static_cast<Register>(i); |
| 627 | } |
| 628 | } |
| 629 | // We shall never fail to find a free caller-save register, as |
| 630 | // there are more than two core caller-save registers on x86 |
| 631 | // (meaning it is possible to find one which is different from |
| 632 | // `ref` and `obj`). |
| 633 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 634 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 635 | UNREACHABLE(); |
| 636 | } |
| 637 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 638 | const Location out_; |
| 639 | const Location ref_; |
| 640 | const Location obj_; |
| 641 | const uint32_t offset_; |
| 642 | // An additional location containing an index to an array. |
| 643 | // Only used for HArrayGet and the UnsafeGetObject & |
| 644 | // UnsafeGetObjectVolatile intrinsics. |
| 645 | const Location index_; |
| 646 | |
| 647 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 648 | }; |
| 649 | |
| 650 | // Slow path generating a read barrier for a GC root. |
| 651 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 652 | public: |
| 653 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 654 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 655 | DCHECK(kEmitCompilerReadBarrier); |
| 656 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 657 | |
| 658 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 659 | LocationSummary* locations = instruction_->GetLocations(); |
| 660 | Register reg_out = out_.AsRegister<Register>(); |
| 661 | DCHECK(locations->CanCall()); |
| 662 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 663 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 664 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 665 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 666 | |
| 667 | __ Bind(GetEntryLabel()); |
| 668 | SaveLiveRegisters(codegen, locations); |
| 669 | |
| 670 | InvokeRuntimeCallingConvention calling_convention; |
| 671 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 672 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 673 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 674 | instruction_, |
| 675 | instruction_->GetDexPc(), |
| 676 | this); |
| 677 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 678 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 679 | |
| 680 | RestoreLiveRegisters(codegen, locations); |
| 681 | __ jmp(GetExitLabel()); |
| 682 | } |
| 683 | |
| 684 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 685 | |
| 686 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 687 | const Location out_; |
| 688 | const Location root_; |
| 689 | |
| 690 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 691 | }; |
| 692 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 693 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 694 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 695 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 696 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 697 | switch (cond) { |
| 698 | case kCondEQ: return kEqual; |
| 699 | case kCondNE: return kNotEqual; |
| 700 | case kCondLT: return kLess; |
| 701 | case kCondLE: return kLessEqual; |
| 702 | case kCondGT: return kGreater; |
| 703 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 704 | case kCondB: return kBelow; |
| 705 | case kCondBE: return kBelowEqual; |
| 706 | case kCondA: return kAbove; |
| 707 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 708 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 709 | LOG(FATAL) << "Unreachable"; |
| 710 | UNREACHABLE(); |
| 711 | } |
| 712 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 713 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 714 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 715 | switch (cond) { |
| 716 | case kCondEQ: return kEqual; |
| 717 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 718 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 719 | case kCondLT: return kBelow; |
| 720 | case kCondLE: return kBelowEqual; |
| 721 | case kCondGT: return kAbove; |
| 722 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 723 | // Unsigned remain unchanged. |
| 724 | case kCondB: return kBelow; |
| 725 | case kCondBE: return kBelowEqual; |
| 726 | case kCondA: return kAbove; |
| 727 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 728 | } |
| 729 | LOG(FATAL) << "Unreachable"; |
| 730 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 733 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 734 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 738 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 739 | } |
| 740 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 741 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 742 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 743 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 746 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 747 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 748 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 749 | } |
| 750 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 751 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 752 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 753 | return GetFloatingPointSpillSlotSize(); |
| 754 | } |
| 755 | |
| 756 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 757 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 758 | return GetFloatingPointSpillSlotSize(); |
| 759 | } |
| 760 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 761 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 762 | HInstruction* instruction, |
| 763 | uint32_t dex_pc, |
| 764 | SlowPathCode* slow_path) { |
| 765 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 766 | instruction, |
| 767 | dex_pc, |
| 768 | slow_path); |
| 769 | } |
| 770 | |
| 771 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 772 | HInstruction* instruction, |
| 773 | uint32_t dex_pc, |
| 774 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 775 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 776 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 777 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 780 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 781 | const X86InstructionSetFeatures& isa_features, |
| 782 | const CompilerOptions& compiler_options, |
| 783 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 784 | : CodeGenerator(graph, |
| 785 | kNumberOfCpuRegisters, |
| 786 | kNumberOfXmmRegisters, |
| 787 | kNumberOfRegisterPairs, |
| 788 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 789 | arraysize(kCoreCalleeSaves)) |
| 790 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 791 | 0, |
| 792 | compiler_options, |
| 793 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 794 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 795 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 796 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 797 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 798 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 799 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 800 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 801 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 802 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 803 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 804 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 805 | constant_area_start_(-1), |
| 806 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 807 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 808 | // Use a fake return address register to mimic Quick. |
| 809 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 810 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 811 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 812 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 813 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 814 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 815 | |
| 816 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 817 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 818 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 819 | UpdateBlockedPairRegisters(); |
| 820 | } |
| 821 | |
| 822 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 823 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 824 | X86ManagedRegister current = |
| 825 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 826 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 827 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 828 | blocked_register_pairs_[i] = true; |
| 829 | } |
| 830 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 833 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 834 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 835 | assembler_(codegen->GetAssembler()), |
| 836 | codegen_(codegen) {} |
| 837 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 838 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 839 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 840 | } |
| 841 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 842 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 843 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 844 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 845 | bool skip_overflow_check = |
| 846 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 847 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 848 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 849 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 850 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 851 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 852 | } |
| 853 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 854 | if (HasEmptyFrame()) { |
| 855 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 856 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 857 | |
| 858 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 859 | Register reg = kCoreCalleeSaves[i]; |
| 860 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 861 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 862 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 863 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 864 | } |
| 865 | } |
| 866 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 867 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 868 | __ subl(ESP, Immediate(adjust)); |
| 869 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 870 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 874 | __ cfi().RememberState(); |
| 875 | if (!HasEmptyFrame()) { |
| 876 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 877 | __ addl(ESP, Immediate(adjust)); |
| 878 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 879 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 880 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 881 | Register reg = kCoreCalleeSaves[i]; |
| 882 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 883 | __ popl(reg); |
| 884 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 885 | __ cfi().Restore(DWARFReg(reg)); |
| 886 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 887 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 888 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 889 | __ ret(); |
| 890 | __ cfi().RestoreState(); |
| 891 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 894 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 895 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 898 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 899 | switch (type) { |
| 900 | case Primitive::kPrimBoolean: |
| 901 | case Primitive::kPrimByte: |
| 902 | case Primitive::kPrimChar: |
| 903 | case Primitive::kPrimShort: |
| 904 | case Primitive::kPrimInt: |
| 905 | case Primitive::kPrimNot: |
| 906 | return Location::RegisterLocation(EAX); |
| 907 | |
| 908 | case Primitive::kPrimLong: |
| 909 | return Location::RegisterPairLocation(EAX, EDX); |
| 910 | |
| 911 | case Primitive::kPrimVoid: |
| 912 | return Location::NoLocation(); |
| 913 | |
| 914 | case Primitive::kPrimDouble: |
| 915 | case Primitive::kPrimFloat: |
| 916 | return Location::FpuRegisterLocation(XMM0); |
| 917 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 918 | |
| 919 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 923 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 924 | } |
| 925 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 926 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 927 | switch (type) { |
| 928 | case Primitive::kPrimBoolean: |
| 929 | case Primitive::kPrimByte: |
| 930 | case Primitive::kPrimChar: |
| 931 | case Primitive::kPrimShort: |
| 932 | case Primitive::kPrimInt: |
| 933 | case Primitive::kPrimNot: { |
| 934 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 935 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 936 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 937 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 938 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 939 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 940 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 941 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 942 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 943 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 944 | uint32_t index = gp_index_; |
| 945 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 946 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 947 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 948 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 949 | calling_convention.GetRegisterPairAt(index)); |
| 950 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 951 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 952 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 957 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 958 | stack_index_++; |
| 959 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 960 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 961 | } else { |
| 962 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 967 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 968 | stack_index_ += 2; |
| 969 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 970 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 971 | } else { |
| 972 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 976 | case Primitive::kPrimVoid: |
| 977 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 978 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 979 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 980 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 981 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 982 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 983 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 984 | if (source.Equals(destination)) { |
| 985 | return; |
| 986 | } |
| 987 | if (destination.IsRegister()) { |
| 988 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 989 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 990 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 991 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 992 | } else { |
| 993 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 994 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 995 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 996 | } else if (destination.IsFpuRegister()) { |
| 997 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 998 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 999 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1000 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1001 | } else { |
| 1002 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1003 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1004 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1005 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1006 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1007 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1008 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1009 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1010 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1011 | } else if (source.IsConstant()) { |
| 1012 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1013 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1014 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1015 | } else { |
| 1016 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1017 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1018 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1024 | if (source.Equals(destination)) { |
| 1025 | return; |
| 1026 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1027 | if (destination.IsRegisterPair()) { |
| 1028 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1029 | EmitParallelMoves( |
| 1030 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1031 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1032 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1033 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1034 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1035 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1036 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1037 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1038 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1039 | __ psrlq(src_reg, Immediate(32)); |
| 1040 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1041 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1042 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1043 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1044 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1045 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1046 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1047 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1048 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1049 | if (source.IsFpuRegister()) { |
| 1050 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1051 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1052 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1053 | } else if (source.IsRegisterPair()) { |
| 1054 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1055 | // Create stack space for 2 elements. |
| 1056 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1057 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1058 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1059 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1060 | // And remove the temporary stack space we allocated. |
| 1061 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1062 | } else { |
| 1063 | LOG(FATAL) << "Unimplemented"; |
| 1064 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1065 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1066 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1067 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1068 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1069 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1070 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1071 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1072 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1073 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1074 | } else if (source.IsConstant()) { |
| 1075 | HConstant* constant = source.GetConstant(); |
| 1076 | int64_t value; |
| 1077 | if (constant->IsLongConstant()) { |
| 1078 | value = constant->AsLongConstant()->GetValue(); |
| 1079 | } else { |
| 1080 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1081 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1082 | } |
| 1083 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1084 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1085 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1086 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1087 | EmitParallelMoves( |
| 1088 | Location::StackSlot(source.GetStackIndex()), |
| 1089 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1090 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1091 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1092 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1093 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1098 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1099 | DCHECK(location.IsRegister()); |
| 1100 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1101 | } |
| 1102 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1103 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1104 | HParallelMove move(GetGraph()->GetArena()); |
| 1105 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1106 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1107 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1108 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1109 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1110 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1111 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1115 | if (location.IsRegister()) { |
| 1116 | locations->AddTemp(location); |
| 1117 | } else if (location.IsRegisterPair()) { |
| 1118 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1119 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1120 | } else { |
| 1121 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1122 | } |
| 1123 | } |
| 1124 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1125 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1126 | DCHECK(!successor->IsExitBlock()); |
| 1127 | |
| 1128 | HBasicBlock* block = got->GetBlock(); |
| 1129 | HInstruction* previous = got->GetPrevious(); |
| 1130 | |
| 1131 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1132 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1133 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1138 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1139 | } |
| 1140 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1141 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1145 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1146 | got->SetLocations(nullptr); |
| 1147 | } |
| 1148 | |
| 1149 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1150 | HandleGoto(got, got->GetSuccessor()); |
| 1151 | } |
| 1152 | |
| 1153 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1154 | try_boundary->SetLocations(nullptr); |
| 1155 | } |
| 1156 | |
| 1157 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1158 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1159 | if (!successor->IsExitBlock()) { |
| 1160 | HandleGoto(try_boundary, successor); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1164 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1165 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1168 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1171 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1172 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1173 | LabelType* true_label, |
| 1174 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1175 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1176 | __ j(kUnordered, true_label); |
| 1177 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1178 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1179 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1180 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1183 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1184 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1185 | LabelType* true_label, |
| 1186 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1187 | LocationSummary* locations = cond->GetLocations(); |
| 1188 | Location left = locations->InAt(0); |
| 1189 | Location right = locations->InAt(1); |
| 1190 | IfCondition if_cond = cond->GetCondition(); |
| 1191 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1192 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1193 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1194 | IfCondition true_high_cond = if_cond; |
| 1195 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1196 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1197 | |
| 1198 | // Set the conditions for the test, remembering that == needs to be |
| 1199 | // decided using the low words. |
| 1200 | switch (if_cond) { |
| 1201 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1202 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1203 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | break; |
| 1205 | case kCondLT: |
| 1206 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1207 | break; |
| 1208 | case kCondLE: |
| 1209 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1210 | break; |
| 1211 | case kCondGT: |
| 1212 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1213 | break; |
| 1214 | case kCondGE: |
| 1215 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1216 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1217 | case kCondB: |
| 1218 | false_high_cond = kCondA; |
| 1219 | break; |
| 1220 | case kCondBE: |
| 1221 | true_high_cond = kCondB; |
| 1222 | break; |
| 1223 | case kCondA: |
| 1224 | false_high_cond = kCondB; |
| 1225 | break; |
| 1226 | case kCondAE: |
| 1227 | true_high_cond = kCondA; |
| 1228 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | if (right.IsConstant()) { |
| 1232 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1233 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1234 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1235 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1236 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1237 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1238 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1239 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1240 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1241 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1242 | __ j(X86Condition(true_high_cond), true_label); |
| 1243 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1244 | } |
| 1245 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1246 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1247 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1248 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1249 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1250 | |
| 1251 | __ cmpl(left_high, right_high); |
| 1252 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1253 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1254 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1255 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1256 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1257 | __ j(X86Condition(true_high_cond), true_label); |
| 1258 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1259 | } |
| 1260 | // Must be equal high, so compare the lows. |
| 1261 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1262 | } else { |
| 1263 | DCHECK(right.IsDoubleStackSlot()); |
| 1264 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1265 | if (if_cond == kCondNE) { |
| 1266 | __ j(X86Condition(true_high_cond), true_label); |
| 1267 | } else if (if_cond == kCondEQ) { |
| 1268 | __ j(X86Condition(false_high_cond), false_label); |
| 1269 | } else { |
| 1270 | __ j(X86Condition(true_high_cond), true_label); |
| 1271 | __ j(X86Condition(false_high_cond), false_label); |
| 1272 | } |
| 1273 | // Must be equal high, so compare the lows. |
| 1274 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | } |
| 1276 | // The last comparison might be unsigned. |
| 1277 | __ j(final_condition, true_label); |
| 1278 | } |
| 1279 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1280 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1281 | Location rhs, |
| 1282 | HInstruction* insn, |
| 1283 | bool is_double) { |
| 1284 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1285 | if (is_double) { |
| 1286 | if (rhs.IsFpuRegister()) { |
| 1287 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1288 | } else if (const_area != nullptr) { |
| 1289 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1290 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1291 | codegen_->LiteralDoubleAddress( |
| 1292 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1293 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1294 | } else { |
| 1295 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1296 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1297 | } |
| 1298 | } else { |
| 1299 | if (rhs.IsFpuRegister()) { |
| 1300 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1301 | } else if (const_area != nullptr) { |
| 1302 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1303 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1304 | codegen_->LiteralFloatAddress( |
| 1305 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1306 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1307 | } else { |
| 1308 | DCHECK(rhs.IsStackSlot()); |
| 1309 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1314 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1315 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1316 | LabelType* true_target_in, |
| 1317 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1318 | // Generated branching requires both targets to be explicit. If either of the |
| 1319 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1320 | LabelType fallthrough_target; |
| 1321 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1322 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1323 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1324 | LocationSummary* locations = condition->GetLocations(); |
| 1325 | Location left = locations->InAt(0); |
| 1326 | Location right = locations->InAt(1); |
| 1327 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1328 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1329 | switch (type) { |
| 1330 | case Primitive::kPrimLong: |
| 1331 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1332 | break; |
| 1333 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1334 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1335 | GenerateFPJumps(condition, true_target, false_target); |
| 1336 | break; |
| 1337 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1338 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1339 | GenerateFPJumps(condition, true_target, false_target); |
| 1340 | break; |
| 1341 | default: |
| 1342 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1343 | } |
| 1344 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1345 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1346 | __ jmp(false_target); |
| 1347 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1348 | |
| 1349 | if (fallthrough_target.IsLinked()) { |
| 1350 | __ Bind(&fallthrough_target); |
| 1351 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1354 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1355 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1356 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1357 | // conditions if they are materialized due to the complex branching. |
| 1358 | return cond->IsCondition() && |
| 1359 | cond->GetNext() == branch && |
| 1360 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1361 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1362 | } |
| 1363 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1364 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1365 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1366 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1367 | LabelType* true_target, |
| 1368 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1369 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1370 | |
| 1371 | if (true_target == nullptr && false_target == nullptr) { |
| 1372 | // Nothing to do. The code always falls through. |
| 1373 | return; |
| 1374 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1375 | // Constant condition, statically compared against "true" (integer value 1). |
| 1376 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1377 | if (true_target != nullptr) { |
| 1378 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1379 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1380 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1381 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1382 | if (false_target != nullptr) { |
| 1383 | __ jmp(false_target); |
| 1384 | } |
| 1385 | } |
| 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | // The following code generates these patterns: |
| 1390 | // (1) true_target == nullptr && false_target != nullptr |
| 1391 | // - opposite condition true => branch to false_target |
| 1392 | // (2) true_target != nullptr && false_target == nullptr |
| 1393 | // - condition true => branch to true_target |
| 1394 | // (3) true_target != nullptr && false_target != nullptr |
| 1395 | // - condition true => branch to true_target |
| 1396 | // - branch to false_target |
| 1397 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1398 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1399 | if (true_target == nullptr) { |
| 1400 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1401 | } else { |
| 1402 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1403 | } |
| 1404 | } else { |
| 1405 | // Materialized condition, compare against 0. |
| 1406 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1407 | if (lhs.IsRegister()) { |
| 1408 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1409 | } else { |
| 1410 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1411 | } |
| 1412 | if (true_target == nullptr) { |
| 1413 | __ j(kEqual, false_target); |
| 1414 | } else { |
| 1415 | __ j(kNotEqual, true_target); |
| 1416 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1417 | } |
| 1418 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1419 | // Condition has not been materialized, use its inputs as the comparison and |
| 1420 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1421 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1422 | |
| 1423 | // If this is a long or FP comparison that has been folded into |
| 1424 | // the HCondition, generate the comparison directly. |
| 1425 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1426 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1427 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1428 | return; |
| 1429 | } |
| 1430 | |
| 1431 | Location lhs = condition->GetLocations()->InAt(0); |
| 1432 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1433 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1434 | if (rhs.IsRegister()) { |
| 1435 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1436 | } else if (rhs.IsConstant()) { |
| 1437 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1438 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1439 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1440 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1441 | } |
| 1442 | if (true_target == nullptr) { |
| 1443 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1444 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1445 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1446 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1447 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1448 | |
| 1449 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1450 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1451 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1452 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1453 | } |
| 1454 | } |
| 1455 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1456 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1457 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1458 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1459 | locations->SetInAt(0, Location::Any()); |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1464 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1465 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1466 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1467 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1468 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1469 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1470 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1474 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1475 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1476 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1477 | locations->SetInAt(0, Location::Any()); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1482 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1483 | GenerateTestAndBranch<Label>(deoptimize, |
| 1484 | /* condition_input_index */ 0, |
| 1485 | slow_path->GetEntryLabel(), |
| 1486 | /* false_target */ nullptr); |
| 1487 | } |
| 1488 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1489 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1490 | // There are no conditional move instructions for XMMs. |
| 1491 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1492 | return false; |
| 1493 | } |
| 1494 | |
| 1495 | // A FP condition doesn't generate the single CC that we need. |
| 1496 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1497 | HInstruction* condition = select->GetCondition(); |
| 1498 | if (condition->IsCondition()) { |
| 1499 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1500 | if (compare_type == Primitive::kPrimLong || |
| 1501 | Primitive::IsFloatingPointType(compare_type)) { |
| 1502 | return false; |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | // We can generate a CMOV for this Select. |
| 1507 | return true; |
| 1508 | } |
| 1509 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1510 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1511 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1512 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1513 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1514 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1515 | } else { |
| 1516 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1517 | if (SelectCanUseCMOV(select)) { |
| 1518 | if (select->InputAt(1)->IsConstant()) { |
| 1519 | // Cmov can't handle a constant value. |
| 1520 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1521 | } else { |
| 1522 | locations->SetInAt(1, Location::Any()); |
| 1523 | } |
| 1524 | } else { |
| 1525 | locations->SetInAt(1, Location::Any()); |
| 1526 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1527 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1528 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1529 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1530 | } |
| 1531 | locations->SetOut(Location::SameAsFirstInput()); |
| 1532 | } |
| 1533 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1534 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1535 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1536 | if (rhs.IsConstant()) { |
| 1537 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1538 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1539 | } else if (rhs.IsStackSlot()) { |
| 1540 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1541 | } else { |
| 1542 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1543 | } |
| 1544 | } |
| 1545 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1546 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1547 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1548 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1549 | if (SelectCanUseCMOV(select)) { |
| 1550 | // If both the condition and the source types are integer, we can generate |
| 1551 | // a CMOV to implement Select. |
| 1552 | |
| 1553 | HInstruction* select_condition = select->GetCondition(); |
| 1554 | Condition cond = kNotEqual; |
| 1555 | |
| 1556 | // Figure out how to test the 'condition'. |
| 1557 | if (select_condition->IsCondition()) { |
| 1558 | HCondition* condition = select_condition->AsCondition(); |
| 1559 | if (!condition->IsEmittedAtUseSite()) { |
| 1560 | // This was a previously materialized condition. |
| 1561 | // Can we use the existing condition code? |
| 1562 | if (AreEflagsSetFrom(condition, select)) { |
| 1563 | // Materialization was the previous instruction. Condition codes are right. |
| 1564 | cond = X86Condition(condition->GetCondition()); |
| 1565 | } else { |
| 1566 | // No, we have to recreate the condition code. |
| 1567 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1568 | __ testl(cond_reg, cond_reg); |
| 1569 | } |
| 1570 | } else { |
| 1571 | // We can't handle FP or long here. |
| 1572 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1573 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1574 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1575 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1576 | cond = X86Condition(condition->GetCondition()); |
| 1577 | } |
| 1578 | } else { |
| 1579 | // Must be a boolean condition, which needs to be compared to 0. |
| 1580 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1581 | __ testl(cond_reg, cond_reg); |
| 1582 | } |
| 1583 | |
| 1584 | // If the condition is true, overwrite the output, which already contains false. |
| 1585 | Location false_loc = locations->InAt(0); |
| 1586 | Location true_loc = locations->InAt(1); |
| 1587 | if (select->GetType() == Primitive::kPrimLong) { |
| 1588 | // 64 bit conditional move. |
| 1589 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1590 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1591 | if (true_loc.IsRegisterPair()) { |
| 1592 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1593 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1594 | } else { |
| 1595 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1596 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1597 | } |
| 1598 | } else { |
| 1599 | // 32 bit conditional move. |
| 1600 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1601 | if (true_loc.IsRegister()) { |
| 1602 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1603 | } else { |
| 1604 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1605 | } |
| 1606 | } |
| 1607 | } else { |
| 1608 | NearLabel false_target; |
| 1609 | GenerateTestAndBranch<NearLabel>( |
| 1610 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1611 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1612 | __ Bind(&false_target); |
| 1613 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1616 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1617 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1618 | } |
| 1619 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1620 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1621 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | void CodeGeneratorX86::GenerateNop() { |
| 1625 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1628 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1629 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1630 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1631 | // Handle the long/FP comparisons made in instruction simplification. |
| 1632 | switch (cond->InputAt(0)->GetType()) { |
| 1633 | case Primitive::kPrimLong: { |
| 1634 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1635 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1636 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1637 | locations->SetOut(Location::RequiresRegister()); |
| 1638 | } |
| 1639 | break; |
| 1640 | } |
| 1641 | case Primitive::kPrimFloat: |
| 1642 | case Primitive::kPrimDouble: { |
| 1643 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1644 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1645 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1646 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1647 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1648 | } else { |
| 1649 | locations->SetInAt(1, Location::Any()); |
| 1650 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1651 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1652 | locations->SetOut(Location::RequiresRegister()); |
| 1653 | } |
| 1654 | break; |
| 1655 | } |
| 1656 | default: |
| 1657 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1658 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1659 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1660 | // We need a byte register. |
| 1661 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1662 | } |
| 1663 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1664 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1667 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1668 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1669 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1670 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | |
| 1672 | LocationSummary* locations = cond->GetLocations(); |
| 1673 | Location lhs = locations->InAt(0); |
| 1674 | Location rhs = locations->InAt(1); |
| 1675 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1676 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1677 | |
| 1678 | switch (cond->InputAt(0)->GetType()) { |
| 1679 | default: { |
| 1680 | // Integer case. |
| 1681 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1682 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1683 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1684 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1685 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1686 | return; |
| 1687 | } |
| 1688 | case Primitive::kPrimLong: |
| 1689 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1690 | break; |
| 1691 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1692 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1693 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1694 | break; |
| 1695 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1696 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1697 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1698 | break; |
| 1699 | } |
| 1700 | |
| 1701 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1702 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1703 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1704 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1705 | __ Bind(&false_label); |
| 1706 | __ xorl(reg, reg); |
| 1707 | __ jmp(&done_label); |
| 1708 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1709 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1710 | __ Bind(&true_label); |
| 1711 | __ movl(reg, Immediate(1)); |
| 1712 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1716 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1720 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1724 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1728 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1732 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1736 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1740 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1744 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1748 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1752 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1756 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1760 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1763 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1764 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1795 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1796 | LocationSummary* locations = |
| 1797 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1798 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1799 | } |
| 1800 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1801 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1802 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1803 | } |
| 1804 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1805 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1806 | LocationSummary* locations = |
| 1807 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1808 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1809 | } |
| 1810 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1811 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1812 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1815 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1816 | LocationSummary* locations = |
| 1817 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1818 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1821 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1822 | // Will be generated at use site. |
| 1823 | } |
| 1824 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1825 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1826 | LocationSummary* locations = |
| 1827 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1828 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1829 | } |
| 1830 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1831 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1832 | // Will be generated at use site. |
| 1833 | } |
| 1834 | |
| 1835 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1836 | LocationSummary* locations = |
| 1837 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1838 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1839 | } |
| 1840 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1841 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1842 | // Will be generated at use site. |
| 1843 | } |
| 1844 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1845 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1846 | memory_barrier->SetLocations(nullptr); |
| 1847 | } |
| 1848 | |
| 1849 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1850 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1851 | } |
| 1852 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1853 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1854 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1857 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1858 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1861 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1862 | LocationSummary* locations = |
| 1863 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1864 | switch (ret->InputAt(0)->GetType()) { |
| 1865 | case Primitive::kPrimBoolean: |
| 1866 | case Primitive::kPrimByte: |
| 1867 | case Primitive::kPrimChar: |
| 1868 | case Primitive::kPrimShort: |
| 1869 | case Primitive::kPrimInt: |
| 1870 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1871 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1872 | break; |
| 1873 | |
| 1874 | case Primitive::kPrimLong: |
| 1875 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1876 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1877 | break; |
| 1878 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1879 | case Primitive::kPrimFloat: |
| 1880 | case Primitive::kPrimDouble: |
| 1881 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1882 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1883 | break; |
| 1884 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1885 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1886 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1887 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1890 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1891 | if (kIsDebugBuild) { |
| 1892 | switch (ret->InputAt(0)->GetType()) { |
| 1893 | case Primitive::kPrimBoolean: |
| 1894 | case Primitive::kPrimByte: |
| 1895 | case Primitive::kPrimChar: |
| 1896 | case Primitive::kPrimShort: |
| 1897 | case Primitive::kPrimInt: |
| 1898 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1899 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1900 | break; |
| 1901 | |
| 1902 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1903 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1904 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1905 | break; |
| 1906 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1907 | case Primitive::kPrimFloat: |
| 1908 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1909 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1910 | break; |
| 1911 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1912 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1913 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1914 | } |
| 1915 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1916 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1919 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1920 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1921 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1922 | // the method_idx. |
| 1923 | HandleInvoke(invoke); |
| 1924 | } |
| 1925 | |
| 1926 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1927 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1928 | } |
| 1929 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1930 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1931 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1932 | // art::PrepareForRegisterAllocation. |
| 1933 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1934 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1935 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1936 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1937 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1938 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1939 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1940 | return; |
| 1941 | } |
| 1942 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1943 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1944 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1945 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1946 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1947 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1948 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1949 | } |
| 1950 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1951 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1952 | if (invoke->GetLocations()->Intrinsified()) { |
| 1953 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1954 | intrinsic.Dispatch(invoke); |
| 1955 | return true; |
| 1956 | } |
| 1957 | return false; |
| 1958 | } |
| 1959 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1960 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1961 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1962 | // art::PrepareForRegisterAllocation. |
| 1963 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1964 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1965 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1966 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1967 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1968 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1969 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1970 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1971 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1972 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1976 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1977 | if (intrinsic.TryDispatch(invoke)) { |
| 1978 | return; |
| 1979 | } |
| 1980 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1981 | HandleInvoke(invoke); |
| 1982 | } |
| 1983 | |
| 1984 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1985 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1986 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1987 | } |
| 1988 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1989 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1990 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1991 | return; |
| 1992 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1993 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1994 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1995 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1996 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1997 | } |
| 1998 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1999 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2000 | // This call to HandleInvoke allocates a temporary (core) register |
| 2001 | // which is also used to transfer the hidden argument from FP to |
| 2002 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2003 | HandleInvoke(invoke); |
| 2004 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2005 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2009 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2010 | LocationSummary* locations = invoke->GetLocations(); |
| 2011 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2012 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2013 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2014 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2015 | Location receiver = locations->InAt(0); |
| 2016 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2017 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2018 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2019 | // won't be modified thereafter, before the `call` instruction. |
| 2020 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2021 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2022 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2023 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2024 | if (receiver.IsStackSlot()) { |
| 2025 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2026 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2027 | __ movl(temp, Address(temp, class_offset)); |
| 2028 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2029 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2030 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2031 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2032 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2033 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2034 | // emit a read barrier for the previous class reference load. |
| 2035 | // However this is not required in practice, as this is an |
| 2036 | // intermediate/temporary reference and because the current |
| 2037 | // concurrent copying collector keeps the from-space memory |
| 2038 | // intact/accessible until the end of the marking phase (the |
| 2039 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2040 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2041 | // temp = temp->GetImtEntryAt(method_offset); |
| 2042 | __ movl(temp, Address(temp, method_offset)); |
| 2043 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2044 | __ call(Address(temp, |
| 2045 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2046 | |
| 2047 | DCHECK(!codegen_->IsLeafMethod()); |
| 2048 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2049 | } |
| 2050 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2051 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2052 | LocationSummary* locations = |
| 2053 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2054 | switch (neg->GetResultType()) { |
| 2055 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2056 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2057 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2058 | locations->SetOut(Location::SameAsFirstInput()); |
| 2059 | break; |
| 2060 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2061 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2062 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2063 | locations->SetOut(Location::SameAsFirstInput()); |
| 2064 | locations->AddTemp(Location::RequiresRegister()); |
| 2065 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2066 | break; |
| 2067 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2068 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2069 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2070 | locations->SetOut(Location::SameAsFirstInput()); |
| 2071 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2072 | break; |
| 2073 | |
| 2074 | default: |
| 2075 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2080 | LocationSummary* locations = neg->GetLocations(); |
| 2081 | Location out = locations->Out(); |
| 2082 | Location in = locations->InAt(0); |
| 2083 | switch (neg->GetResultType()) { |
| 2084 | case Primitive::kPrimInt: |
| 2085 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2086 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2087 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2088 | break; |
| 2089 | |
| 2090 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2091 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2092 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2093 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2094 | // Negation is similar to subtraction from zero. The least |
| 2095 | // significant byte triggers a borrow when it is different from |
| 2096 | // zero; to take it into account, add 1 to the most significant |
| 2097 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2098 | // operation. |
| 2099 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2100 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2101 | break; |
| 2102 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2103 | case Primitive::kPrimFloat: { |
| 2104 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2105 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2106 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2107 | // Implement float negation with an exclusive or with value |
| 2108 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2109 | // single-precision floating-point number). |
| 2110 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2111 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2112 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2113 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2114 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2115 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2116 | case Primitive::kPrimDouble: { |
| 2117 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2118 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2119 | // Implement double negation with an exclusive or with value |
| 2120 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2121 | // a double-precision floating-point number). |
| 2122 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2123 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2124 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2125 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2126 | |
| 2127 | default: |
| 2128 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2129 | } |
| 2130 | } |
| 2131 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2132 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2133 | LocationSummary* locations = |
| 2134 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2135 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2136 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2137 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2138 | locations->SetOut(Location::SameAsFirstInput()); |
| 2139 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2140 | } |
| 2141 | |
| 2142 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2143 | LocationSummary* locations = neg->GetLocations(); |
| 2144 | Location out = locations->Out(); |
| 2145 | DCHECK(locations->InAt(0).Equals(out)); |
| 2146 | |
| 2147 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2148 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2149 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2150 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2151 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2152 | } else { |
| 2153 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2154 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2155 | } |
| 2156 | } |
| 2157 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2158 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2159 | Primitive::Type result_type = conversion->GetResultType(); |
| 2160 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2161 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2162 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2163 | // The float-to-long and double-to-long type conversions rely on a |
| 2164 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2165 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2166 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2167 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2168 | ? LocationSummary::kCall |
| 2169 | : LocationSummary::kNoCall; |
| 2170 | LocationSummary* locations = |
| 2171 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2172 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2173 | // The Java language does not allow treating boolean as an integral type but |
| 2174 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2175 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2176 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2177 | case Primitive::kPrimByte: |
| 2178 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimLong: { |
| 2180 | // Type conversion from long to byte is a result of code transformations. |
| 2181 | HInstruction* input = conversion->InputAt(0); |
| 2182 | Location input_location = input->IsConstant() |
| 2183 | ? Location::ConstantLocation(input->AsConstant()) |
| 2184 | : Location::RegisterPairLocation(EAX, EDX); |
| 2185 | locations->SetInAt(0, input_location); |
| 2186 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2187 | // the validation of the linear scan implementation |
| 2188 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2189 | break; |
| 2190 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2191 | case Primitive::kPrimBoolean: |
| 2192 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2193 | case Primitive::kPrimShort: |
| 2194 | case Primitive::kPrimInt: |
| 2195 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2196 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2197 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2198 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2199 | // the validation of the linear scan implementation |
| 2200 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | |
| 2203 | default: |
| 2204 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2205 | << " to " << result_type; |
| 2206 | } |
| 2207 | break; |
| 2208 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2209 | case Primitive::kPrimShort: |
| 2210 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2211 | case Primitive::kPrimLong: |
| 2212 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimBoolean: |
| 2214 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2215 | case Primitive::kPrimByte: |
| 2216 | case Primitive::kPrimInt: |
| 2217 | case Primitive::kPrimChar: |
| 2218 | // Processing a Dex `int-to-short' instruction. |
| 2219 | locations->SetInAt(0, Location::Any()); |
| 2220 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2221 | break; |
| 2222 | |
| 2223 | default: |
| 2224 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2225 | << " to " << result_type; |
| 2226 | } |
| 2227 | break; |
| 2228 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2229 | case Primitive::kPrimInt: |
| 2230 | switch (input_type) { |
| 2231 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2232 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2233 | locations->SetInAt(0, Location::Any()); |
| 2234 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2235 | break; |
| 2236 | |
| 2237 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2238 | // Processing a Dex `float-to-int' instruction. |
| 2239 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2240 | locations->SetOut(Location::RequiresRegister()); |
| 2241 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2242 | break; |
| 2243 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2244 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2245 | // Processing a Dex `double-to-int' instruction. |
| 2246 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2247 | locations->SetOut(Location::RequiresRegister()); |
| 2248 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2249 | break; |
| 2250 | |
| 2251 | default: |
| 2252 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2253 | << " to " << result_type; |
| 2254 | } |
| 2255 | break; |
| 2256 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2257 | case Primitive::kPrimLong: |
| 2258 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimBoolean: |
| 2260 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimByte: |
| 2262 | case Primitive::kPrimShort: |
| 2263 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2264 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2265 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2266 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2267 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2268 | break; |
| 2269 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2271 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2272 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2273 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2274 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2275 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2276 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2277 | // The runtime helper puts the result in EAX, EDX. |
| 2278 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2279 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2280 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2281 | |
| 2282 | default: |
| 2283 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2284 | << " to " << result_type; |
| 2285 | } |
| 2286 | break; |
| 2287 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2288 | case Primitive::kPrimChar: |
| 2289 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimLong: |
| 2291 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2292 | case Primitive::kPrimBoolean: |
| 2293 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2294 | case Primitive::kPrimByte: |
| 2295 | case Primitive::kPrimShort: |
| 2296 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2297 | // Processing a Dex `int-to-char' instruction. |
| 2298 | locations->SetInAt(0, Location::Any()); |
| 2299 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 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::kPrimFloat: |
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-float' instruction. |
| 2317 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2318 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2319 | break; |
| 2320 | |
| 2321 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2322 | // Processing a Dex `long-to-float' 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 | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2325 | break; |
| 2326 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2328 | // Processing a Dex `double-to-float' 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 | }; |
| 2337 | break; |
| 2338 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2339 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2340 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2341 | case Primitive::kPrimBoolean: |
| 2342 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimByte: |
| 2344 | case Primitive::kPrimShort: |
| 2345 | case Primitive::kPrimInt: |
| 2346 | case Primitive::kPrimChar: |
| 2347 | // Processing a Dex `int-to-double' instruction. |
| 2348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2349 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2350 | break; |
| 2351 | |
| 2352 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2353 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2354 | locations->SetInAt(0, Location::Any()); |
| 2355 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2356 | break; |
| 2357 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2359 | // Processing a Dex `float-to-double' instruction. |
| 2360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2361 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | |
| 2364 | default: |
| 2365 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2366 | << " to " << result_type; |
| 2367 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2368 | break; |
| 2369 | |
| 2370 | default: |
| 2371 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2372 | << " to " << result_type; |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2377 | LocationSummary* locations = conversion->GetLocations(); |
| 2378 | Location out = locations->Out(); |
| 2379 | Location in = locations->InAt(0); |
| 2380 | Primitive::Type result_type = conversion->GetResultType(); |
| 2381 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2382 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2383 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2384 | case Primitive::kPrimByte: |
| 2385 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2386 | case Primitive::kPrimLong: |
| 2387 | // Type conversion from long to byte is a result of code transformations. |
| 2388 | if (in.IsRegisterPair()) { |
| 2389 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2390 | } else { |
| 2391 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2392 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2393 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2394 | } |
| 2395 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2396 | case Primitive::kPrimBoolean: |
| 2397 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2398 | case Primitive::kPrimShort: |
| 2399 | case Primitive::kPrimInt: |
| 2400 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2401 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2402 | if (in.IsRegister()) { |
| 2403 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2404 | } else { |
| 2405 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2406 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2407 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2408 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2409 | break; |
| 2410 | |
| 2411 | default: |
| 2412 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2413 | << " to " << result_type; |
| 2414 | } |
| 2415 | break; |
| 2416 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2417 | case Primitive::kPrimShort: |
| 2418 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2419 | case Primitive::kPrimLong: |
| 2420 | // Type conversion from long to short is a result of code transformations. |
| 2421 | if (in.IsRegisterPair()) { |
| 2422 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2423 | } else if (in.IsDoubleStackSlot()) { |
| 2424 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2425 | } else { |
| 2426 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2427 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2428 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2429 | } |
| 2430 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2431 | case Primitive::kPrimBoolean: |
| 2432 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimByte: |
| 2434 | case Primitive::kPrimInt: |
| 2435 | case Primitive::kPrimChar: |
| 2436 | // Processing a Dex `int-to-short' instruction. |
| 2437 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2438 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2439 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2440 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2441 | } else { |
| 2442 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2443 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2444 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2445 | } |
| 2446 | break; |
| 2447 | |
| 2448 | default: |
| 2449 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2450 | << " to " << result_type; |
| 2451 | } |
| 2452 | break; |
| 2453 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2454 | case Primitive::kPrimInt: |
| 2455 | switch (input_type) { |
| 2456 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2457 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2458 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2459 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2460 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2461 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2462 | } else { |
| 2463 | DCHECK(in.IsConstant()); |
| 2464 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2465 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2466 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2467 | } |
| 2468 | break; |
| 2469 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2470 | case Primitive::kPrimFloat: { |
| 2471 | // Processing a Dex `float-to-int' instruction. |
| 2472 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2473 | Register output = out.AsRegister<Register>(); |
| 2474 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2475 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2476 | |
| 2477 | __ movl(output, Immediate(kPrimIntMax)); |
| 2478 | // temp = int-to-float(output) |
| 2479 | __ cvtsi2ss(temp, output); |
| 2480 | // if input >= temp goto done |
| 2481 | __ comiss(input, temp); |
| 2482 | __ j(kAboveEqual, &done); |
| 2483 | // if input == NaN goto nan |
| 2484 | __ j(kUnordered, &nan); |
| 2485 | // output = float-to-int-truncate(input) |
| 2486 | __ cvttss2si(output, input); |
| 2487 | __ jmp(&done); |
| 2488 | __ Bind(&nan); |
| 2489 | // output = 0 |
| 2490 | __ xorl(output, output); |
| 2491 | __ Bind(&done); |
| 2492 | break; |
| 2493 | } |
| 2494 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimDouble: { |
| 2496 | // Processing a Dex `double-to-int' instruction. |
| 2497 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2498 | Register output = out.AsRegister<Register>(); |
| 2499 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2500 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2501 | |
| 2502 | __ movl(output, Immediate(kPrimIntMax)); |
| 2503 | // temp = int-to-double(output) |
| 2504 | __ cvtsi2sd(temp, output); |
| 2505 | // if input >= temp goto done |
| 2506 | __ comisd(input, temp); |
| 2507 | __ j(kAboveEqual, &done); |
| 2508 | // if input == NaN goto nan |
| 2509 | __ j(kUnordered, &nan); |
| 2510 | // output = double-to-int-truncate(input) |
| 2511 | __ cvttsd2si(output, input); |
| 2512 | __ jmp(&done); |
| 2513 | __ Bind(&nan); |
| 2514 | // output = 0 |
| 2515 | __ xorl(output, output); |
| 2516 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2517 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2518 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2519 | |
| 2520 | default: |
| 2521 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2522 | << " to " << result_type; |
| 2523 | } |
| 2524 | break; |
| 2525 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2526 | case Primitive::kPrimLong: |
| 2527 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimBoolean: |
| 2529 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimByte: |
| 2531 | case Primitive::kPrimShort: |
| 2532 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2533 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2534 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2535 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2536 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2537 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2538 | __ cdq(); |
| 2539 | break; |
| 2540 | |
| 2541 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2542 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2543 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2544 | conversion, |
| 2545 | conversion->GetDexPc(), |
| 2546 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2547 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2548 | break; |
| 2549 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2550 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2551 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2552 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2553 | conversion, |
| 2554 | conversion->GetDexPc(), |
| 2555 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2556 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2557 | break; |
| 2558 | |
| 2559 | default: |
| 2560 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2561 | << " to " << result_type; |
| 2562 | } |
| 2563 | break; |
| 2564 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2565 | case Primitive::kPrimChar: |
| 2566 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimLong: |
| 2568 | // Type conversion from long to short is a result of code transformations. |
| 2569 | if (in.IsRegisterPair()) { |
| 2570 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2571 | } else if (in.IsDoubleStackSlot()) { |
| 2572 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2573 | } else { |
| 2574 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2575 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2576 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2577 | } |
| 2578 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2579 | case Primitive::kPrimBoolean: |
| 2580 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2581 | case Primitive::kPrimByte: |
| 2582 | case Primitive::kPrimShort: |
| 2583 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2584 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2585 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2586 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2587 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2588 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2589 | } else { |
| 2590 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2591 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2592 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2593 | } |
| 2594 | break; |
| 2595 | |
| 2596 | default: |
| 2597 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2598 | << " to " << result_type; |
| 2599 | } |
| 2600 | break; |
| 2601 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2602 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2603 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimBoolean: |
| 2605 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimByte: |
| 2607 | case Primitive::kPrimShort: |
| 2608 | case Primitive::kPrimInt: |
| 2609 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2610 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2611 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2614 | case Primitive::kPrimLong: { |
| 2615 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2616 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2617 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2618 | // Create stack space for the call to |
| 2619 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2620 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2621 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2622 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2623 | __ subl(ESP, Immediate(adjustment)); |
| 2624 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2625 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2626 | // Load the value to the FP stack, using temporaries if needed. |
| 2627 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2628 | |
| 2629 | if (out.IsStackSlot()) { |
| 2630 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2631 | } else { |
| 2632 | __ fstps(Address(ESP, 0)); |
| 2633 | Location stack_temp = Location::StackSlot(0); |
| 2634 | codegen_->Move32(out, stack_temp); |
| 2635 | } |
| 2636 | |
| 2637 | // Remove the temporary stack space we allocated. |
| 2638 | if (adjustment != 0) { |
| 2639 | __ addl(ESP, Immediate(adjustment)); |
| 2640 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2641 | break; |
| 2642 | } |
| 2643 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2644 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2645 | // Processing a Dex `double-to-float' instruction. |
| 2646 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2647 | break; |
| 2648 | |
| 2649 | default: |
| 2650 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2651 | << " to " << result_type; |
| 2652 | }; |
| 2653 | break; |
| 2654 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2655 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2656 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2657 | case Primitive::kPrimBoolean: |
| 2658 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimByte: |
| 2660 | case Primitive::kPrimShort: |
| 2661 | case Primitive::kPrimInt: |
| 2662 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2663 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2664 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2665 | break; |
| 2666 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2667 | case Primitive::kPrimLong: { |
| 2668 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2669 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2670 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2671 | // Create stack space for the call to |
| 2672 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2673 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2674 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2675 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2676 | __ subl(ESP, Immediate(adjustment)); |
| 2677 | } |
| 2678 | |
| 2679 | // Load the value to the FP stack, using temporaries if needed. |
| 2680 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2681 | |
| 2682 | if (out.IsDoubleStackSlot()) { |
| 2683 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2684 | } else { |
| 2685 | __ fstpl(Address(ESP, 0)); |
| 2686 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2687 | codegen_->Move64(out, stack_temp); |
| 2688 | } |
| 2689 | |
| 2690 | // Remove the temporary stack space we allocated. |
| 2691 | if (adjustment != 0) { |
| 2692 | __ addl(ESP, Immediate(adjustment)); |
| 2693 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | } |
| 2696 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2697 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2698 | // Processing a Dex `float-to-double' instruction. |
| 2699 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2700 | break; |
| 2701 | |
| 2702 | default: |
| 2703 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2704 | << " to " << result_type; |
| 2705 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2706 | break; |
| 2707 | |
| 2708 | default: |
| 2709 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2710 | << " to " << result_type; |
| 2711 | } |
| 2712 | } |
| 2713 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2714 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2715 | LocationSummary* locations = |
| 2716 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2717 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2718 | case Primitive::kPrimInt: { |
| 2719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2720 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2721 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2722 | break; |
| 2723 | } |
| 2724 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2725 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2726 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2727 | locations->SetInAt(1, Location::Any()); |
| 2728 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2729 | break; |
| 2730 | } |
| 2731 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2732 | case Primitive::kPrimFloat: |
| 2733 | case Primitive::kPrimDouble: { |
| 2734 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2735 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2736 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2737 | } else if (add->InputAt(1)->IsConstant()) { |
| 2738 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2739 | } else { |
| 2740 | locations->SetInAt(1, Location::Any()); |
| 2741 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2742 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2743 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2744 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2745 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2746 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2747 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2748 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2749 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2753 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2754 | Location first = locations->InAt(0); |
| 2755 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2756 | Location out = locations->Out(); |
| 2757 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2758 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2759 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2760 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2761 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2762 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2763 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2764 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2765 | } else { |
| 2766 | __ leal(out.AsRegister<Register>(), Address( |
| 2767 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2768 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2769 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2770 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2771 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2772 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2773 | } else { |
| 2774 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2775 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2776 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2777 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2778 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2779 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2780 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2784 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2785 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2786 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2787 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2788 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2789 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2790 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2791 | } else { |
| 2792 | DCHECK(second.IsConstant()) << second; |
| 2793 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2794 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2795 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2796 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2797 | break; |
| 2798 | } |
| 2799 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2800 | case Primitive::kPrimFloat: { |
| 2801 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2802 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2803 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2804 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2805 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2806 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2807 | codegen_->LiteralFloatAddress( |
| 2808 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2809 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2810 | } else { |
| 2811 | DCHECK(second.IsStackSlot()); |
| 2812 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2813 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2814 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | case Primitive::kPrimDouble: { |
| 2818 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2819 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2820 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2821 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2822 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2823 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2824 | codegen_->LiteralDoubleAddress( |
| 2825 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2826 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2827 | } else { |
| 2828 | DCHECK(second.IsDoubleStackSlot()); |
| 2829 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2830 | } |
| 2831 | break; |
| 2832 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2833 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2834 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2835 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2839 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2840 | LocationSummary* locations = |
| 2841 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2842 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2843 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2844 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2845 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2846 | locations->SetInAt(1, Location::Any()); |
| 2847 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2848 | break; |
| 2849 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2850 | case Primitive::kPrimFloat: |
| 2851 | case Primitive::kPrimDouble: { |
| 2852 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2853 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2854 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2855 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2856 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2857 | } else { |
| 2858 | locations->SetInAt(1, Location::Any()); |
| 2859 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2860 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2861 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2862 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2863 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2864 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2865 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2866 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2870 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2871 | Location first = locations->InAt(0); |
| 2872 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2873 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2874 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2875 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2876 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2877 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2878 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2879 | __ subl(first.AsRegister<Register>(), |
| 2880 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2881 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2882 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2883 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2884 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2888 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2889 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2890 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2891 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2892 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2893 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2894 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2895 | } else { |
| 2896 | DCHECK(second.IsConstant()) << second; |
| 2897 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2898 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2899 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2900 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2901 | break; |
| 2902 | } |
| 2903 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2904 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2905 | if (second.IsFpuRegister()) { |
| 2906 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2907 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2908 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2909 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2910 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2911 | codegen_->LiteralFloatAddress( |
| 2912 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2913 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2914 | } else { |
| 2915 | DCHECK(second.IsStackSlot()); |
| 2916 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2917 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2918 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2922 | if (second.IsFpuRegister()) { |
| 2923 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2924 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2925 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2926 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2927 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2928 | codegen_->LiteralDoubleAddress( |
| 2929 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2930 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2931 | } else { |
| 2932 | DCHECK(second.IsDoubleStackSlot()); |
| 2933 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2934 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2935 | break; |
| 2936 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2937 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2938 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2939 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2943 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2944 | LocationSummary* locations = |
| 2945 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2946 | switch (mul->GetResultType()) { |
| 2947 | case Primitive::kPrimInt: |
| 2948 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2949 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2950 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2951 | // Can use 3 operand multiply. |
| 2952 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2953 | } else { |
| 2954 | locations->SetOut(Location::SameAsFirstInput()); |
| 2955 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2956 | break; |
| 2957 | case Primitive::kPrimLong: { |
| 2958 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2959 | locations->SetInAt(1, Location::Any()); |
| 2960 | locations->SetOut(Location::SameAsFirstInput()); |
| 2961 | // Needed for imul on 32bits with 64bits output. |
| 2962 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2963 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2964 | break; |
| 2965 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2966 | case Primitive::kPrimFloat: |
| 2967 | case Primitive::kPrimDouble: { |
| 2968 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2969 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2970 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2971 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2972 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2973 | } else { |
| 2974 | locations->SetInAt(1, Location::Any()); |
| 2975 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2976 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2977 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2978 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2979 | |
| 2980 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2981 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2986 | LocationSummary* locations = mul->GetLocations(); |
| 2987 | Location first = locations->InAt(0); |
| 2988 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2989 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2990 | |
| 2991 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2992 | case Primitive::kPrimInt: |
| 2993 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2994 | // problems where the output may not be the same as the first operand. |
| 2995 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2996 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2997 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2998 | } else if (second.IsRegister()) { |
| 2999 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3000 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3001 | } else { |
| 3002 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3003 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3004 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3005 | } |
| 3006 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3007 | |
| 3008 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3009 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3010 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3011 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3012 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3013 | |
| 3014 | DCHECK_EQ(EAX, eax); |
| 3015 | DCHECK_EQ(EDX, edx); |
| 3016 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3017 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3018 | // output: in1 |
| 3019 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3020 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3021 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3022 | if (second.IsConstant()) { |
| 3023 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3024 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3025 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3026 | int32_t low_value = Low32Bits(value); |
| 3027 | int32_t high_value = High32Bits(value); |
| 3028 | Immediate low(low_value); |
| 3029 | Immediate high(high_value); |
| 3030 | |
| 3031 | __ movl(eax, high); |
| 3032 | // eax <- in1.lo * in2.hi |
| 3033 | __ imull(eax, in1_lo); |
| 3034 | // in1.hi <- in1.hi * in2.lo |
| 3035 | __ imull(in1_hi, low); |
| 3036 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3037 | __ addl(in1_hi, eax); |
| 3038 | // move in2_lo to eax to prepare for double precision |
| 3039 | __ movl(eax, low); |
| 3040 | // edx:eax <- in1.lo * in2.lo |
| 3041 | __ mull(in1_lo); |
| 3042 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3043 | __ addl(in1_hi, edx); |
| 3044 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3045 | __ movl(in1_lo, eax); |
| 3046 | } else if (second.IsRegisterPair()) { |
| 3047 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3048 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3049 | |
| 3050 | __ movl(eax, in2_hi); |
| 3051 | // eax <- in1.lo * in2.hi |
| 3052 | __ imull(eax, in1_lo); |
| 3053 | // in1.hi <- in1.hi * in2.lo |
| 3054 | __ imull(in1_hi, in2_lo); |
| 3055 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3056 | __ addl(in1_hi, eax); |
| 3057 | // move in1_lo to eax to prepare for double precision |
| 3058 | __ movl(eax, in1_lo); |
| 3059 | // edx:eax <- in1.lo * in2.lo |
| 3060 | __ mull(in2_lo); |
| 3061 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3062 | __ addl(in1_hi, edx); |
| 3063 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3064 | __ movl(in1_lo, eax); |
| 3065 | } else { |
| 3066 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3067 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3068 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3069 | |
| 3070 | __ movl(eax, in2_hi); |
| 3071 | // eax <- in1.lo * in2.hi |
| 3072 | __ imull(eax, in1_lo); |
| 3073 | // in1.hi <- in1.hi * in2.lo |
| 3074 | __ imull(in1_hi, in2_lo); |
| 3075 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3076 | __ addl(in1_hi, eax); |
| 3077 | // move in1_lo to eax to prepare for double precision |
| 3078 | __ movl(eax, in1_lo); |
| 3079 | // edx:eax <- in1.lo * in2.lo |
| 3080 | __ mull(in2_lo); |
| 3081 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3082 | __ addl(in1_hi, edx); |
| 3083 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3084 | __ movl(in1_lo, eax); |
| 3085 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3086 | |
| 3087 | break; |
| 3088 | } |
| 3089 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3090 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3091 | DCHECK(first.Equals(locations->Out())); |
| 3092 | if (second.IsFpuRegister()) { |
| 3093 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3094 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3095 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3096 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3097 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3098 | codegen_->LiteralFloatAddress( |
| 3099 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3100 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3101 | } else { |
| 3102 | DCHECK(second.IsStackSlot()); |
| 3103 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3104 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3105 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3109 | DCHECK(first.Equals(locations->Out())); |
| 3110 | if (second.IsFpuRegister()) { |
| 3111 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3112 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3113 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3114 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3115 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3116 | codegen_->LiteralDoubleAddress( |
| 3117 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3118 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3119 | } else { |
| 3120 | DCHECK(second.IsDoubleStackSlot()); |
| 3121 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3122 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3123 | break; |
| 3124 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3125 | |
| 3126 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3127 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3131 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3132 | uint32_t temp_offset, |
| 3133 | uint32_t stack_adjustment, |
| 3134 | bool is_fp, |
| 3135 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3136 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3137 | DCHECK(!is_wide); |
| 3138 | if (is_fp) { |
| 3139 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3140 | } else { |
| 3141 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3142 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3143 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3144 | DCHECK(is_wide); |
| 3145 | if (is_fp) { |
| 3146 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3147 | } else { |
| 3148 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3149 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3150 | } else { |
| 3151 | // 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] | 3152 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3153 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3154 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3155 | if (is_fp) { |
| 3156 | __ flds(Address(ESP, temp_offset)); |
| 3157 | } else { |
| 3158 | __ filds(Address(ESP, temp_offset)); |
| 3159 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3160 | } else { |
| 3161 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3162 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3163 | if (is_fp) { |
| 3164 | __ fldl(Address(ESP, temp_offset)); |
| 3165 | } else { |
| 3166 | __ fildl(Address(ESP, temp_offset)); |
| 3167 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3168 | } |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3173 | Primitive::Type type = rem->GetResultType(); |
| 3174 | bool is_float = type == Primitive::kPrimFloat; |
| 3175 | size_t elem_size = Primitive::ComponentSize(type); |
| 3176 | LocationSummary* locations = rem->GetLocations(); |
| 3177 | Location first = locations->InAt(0); |
| 3178 | Location second = locations->InAt(1); |
| 3179 | Location out = locations->Out(); |
| 3180 | |
| 3181 | // Create stack space for 2 elements. |
| 3182 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3183 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3184 | |
| 3185 | // 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] | 3186 | const bool is_wide = !is_float; |
| 3187 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3188 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3189 | |
| 3190 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3191 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3192 | __ Bind(&retry); |
| 3193 | __ fprem(); |
| 3194 | |
| 3195 | // Move FP status to AX. |
| 3196 | __ fstsw(); |
| 3197 | |
| 3198 | // And see if the argument reduction is complete. This is signaled by the |
| 3199 | // C2 FPU flag bit set to 0. |
| 3200 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3201 | __ j(kNotEqual, &retry); |
| 3202 | |
| 3203 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3204 | // Store FP top of stack to real stack. |
| 3205 | if (is_float) { |
| 3206 | __ fsts(Address(ESP, 0)); |
| 3207 | } else { |
| 3208 | __ fstl(Address(ESP, 0)); |
| 3209 | } |
| 3210 | |
| 3211 | // Pop the 2 items from the FP stack. |
| 3212 | __ fucompp(); |
| 3213 | |
| 3214 | // Load the value from the stack into an XMM register. |
| 3215 | DCHECK(out.IsFpuRegister()) << out; |
| 3216 | if (is_float) { |
| 3217 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3218 | } else { |
| 3219 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3220 | } |
| 3221 | |
| 3222 | // And remove the temporary stack space we allocated. |
| 3223 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3224 | } |
| 3225 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3226 | |
| 3227 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3228 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3229 | |
| 3230 | LocationSummary* locations = instruction->GetLocations(); |
| 3231 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3232 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3233 | |
| 3234 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3235 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3236 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3237 | |
| 3238 | DCHECK(imm == 1 || imm == -1); |
| 3239 | |
| 3240 | if (instruction->IsRem()) { |
| 3241 | __ xorl(out_register, out_register); |
| 3242 | } else { |
| 3243 | __ movl(out_register, input_register); |
| 3244 | if (imm == -1) { |
| 3245 | __ negl(out_register); |
| 3246 | } |
| 3247 | } |
| 3248 | } |
| 3249 | |
| 3250 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3251 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3252 | LocationSummary* locations = instruction->GetLocations(); |
| 3253 | |
| 3254 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3255 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3256 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3257 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3258 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3259 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3260 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3261 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3262 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3263 | __ testl(input_register, input_register); |
| 3264 | __ cmovl(kGreaterEqual, num, input_register); |
| 3265 | int shift = CTZ(imm); |
| 3266 | __ sarl(num, Immediate(shift)); |
| 3267 | |
| 3268 | if (imm < 0) { |
| 3269 | __ negl(num); |
| 3270 | } |
| 3271 | |
| 3272 | __ movl(out_register, num); |
| 3273 | } |
| 3274 | |
| 3275 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3276 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3277 | |
| 3278 | LocationSummary* locations = instruction->GetLocations(); |
| 3279 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3280 | |
| 3281 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3282 | Register out = locations->Out().AsRegister<Register>(); |
| 3283 | Register num; |
| 3284 | Register edx; |
| 3285 | |
| 3286 | if (instruction->IsDiv()) { |
| 3287 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3288 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3289 | } else { |
| 3290 | edx = locations->Out().AsRegister<Register>(); |
| 3291 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3292 | } |
| 3293 | |
| 3294 | DCHECK_EQ(EAX, eax); |
| 3295 | DCHECK_EQ(EDX, edx); |
| 3296 | if (instruction->IsDiv()) { |
| 3297 | DCHECK_EQ(EAX, out); |
| 3298 | } else { |
| 3299 | DCHECK_EQ(EDX, out); |
| 3300 | } |
| 3301 | |
| 3302 | int64_t magic; |
| 3303 | int shift; |
| 3304 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3305 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3306 | // Save the numerator. |
| 3307 | __ movl(num, eax); |
| 3308 | |
| 3309 | // EAX = magic |
| 3310 | __ movl(eax, Immediate(magic)); |
| 3311 | |
| 3312 | // EDX:EAX = magic * numerator |
| 3313 | __ imull(num); |
| 3314 | |
| 3315 | if (imm > 0 && magic < 0) { |
| 3316 | // EDX += num |
| 3317 | __ addl(edx, num); |
| 3318 | } else if (imm < 0 && magic > 0) { |
| 3319 | __ subl(edx, num); |
| 3320 | } |
| 3321 | |
| 3322 | // Shift if needed. |
| 3323 | if (shift != 0) { |
| 3324 | __ sarl(edx, Immediate(shift)); |
| 3325 | } |
| 3326 | |
| 3327 | // EDX += 1 if EDX < 0 |
| 3328 | __ movl(eax, edx); |
| 3329 | __ shrl(edx, Immediate(31)); |
| 3330 | __ addl(edx, eax); |
| 3331 | |
| 3332 | if (instruction->IsRem()) { |
| 3333 | __ movl(eax, num); |
| 3334 | __ imull(edx, Immediate(imm)); |
| 3335 | __ subl(eax, edx); |
| 3336 | __ movl(edx, eax); |
| 3337 | } else { |
| 3338 | __ movl(eax, edx); |
| 3339 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3342 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3343 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3344 | |
| 3345 | LocationSummary* locations = instruction->GetLocations(); |
| 3346 | Location out = locations->Out(); |
| 3347 | Location first = locations->InAt(0); |
| 3348 | Location second = locations->InAt(1); |
| 3349 | bool is_div = instruction->IsDiv(); |
| 3350 | |
| 3351 | switch (instruction->GetResultType()) { |
| 3352 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3353 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3354 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3355 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3356 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3357 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3358 | |
| 3359 | if (imm == 0) { |
| 3360 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3361 | } else if (imm == 1 || imm == -1) { |
| 3362 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3363 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3364 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3365 | } else { |
| 3366 | DCHECK(imm <= -2 || imm >= 2); |
| 3367 | GenerateDivRemWithAnyConstant(instruction); |
| 3368 | } |
| 3369 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3370 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3371 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3372 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3373 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3374 | Register second_reg = second.AsRegister<Register>(); |
| 3375 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3376 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3377 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3378 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3379 | __ cmpl(second_reg, Immediate(-1)); |
| 3380 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3381 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3382 | // edx:eax <- sign-extended of eax |
| 3383 | __ cdq(); |
| 3384 | // eax = quotient, edx = remainder |
| 3385 | __ idivl(second_reg); |
| 3386 | __ Bind(slow_path->GetExitLabel()); |
| 3387 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3388 | break; |
| 3389 | } |
| 3390 | |
| 3391 | case Primitive::kPrimLong: { |
| 3392 | InvokeRuntimeCallingConvention calling_convention; |
| 3393 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3394 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3395 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3396 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3397 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3398 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3399 | |
| 3400 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3401 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3402 | instruction, |
| 3403 | instruction->GetDexPc(), |
| 3404 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3405 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3406 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3407 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3408 | instruction, |
| 3409 | instruction->GetDexPc(), |
| 3410 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3411 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3412 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3413 | break; |
| 3414 | } |
| 3415 | |
| 3416 | default: |
| 3417 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3418 | } |
| 3419 | } |
| 3420 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3421 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3422 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3423 | ? LocationSummary::kCall |
| 3424 | : LocationSummary::kNoCall; |
| 3425 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3426 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3427 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3428 | case Primitive::kPrimInt: { |
| 3429 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3430 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3431 | locations->SetOut(Location::SameAsFirstInput()); |
| 3432 | // Intel uses edx:eax as the dividend. |
| 3433 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3434 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3435 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3436 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3437 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3438 | locations->AddTemp(Location::RequiresRegister()); |
| 3439 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3440 | break; |
| 3441 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3442 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3443 | InvokeRuntimeCallingConvention calling_convention; |
| 3444 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3445 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3446 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3447 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3448 | // Runtime helper puts the result in EAX, EDX. |
| 3449 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3450 | break; |
| 3451 | } |
| 3452 | case Primitive::kPrimFloat: |
| 3453 | case Primitive::kPrimDouble: { |
| 3454 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3455 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3456 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3457 | } else if (div->InputAt(1)->IsConstant()) { |
| 3458 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3459 | } else { |
| 3460 | locations->SetInAt(1, Location::Any()); |
| 3461 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3462 | locations->SetOut(Location::SameAsFirstInput()); |
| 3463 | break; |
| 3464 | } |
| 3465 | |
| 3466 | default: |
| 3467 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3472 | LocationSummary* locations = div->GetLocations(); |
| 3473 | Location first = locations->InAt(0); |
| 3474 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3475 | |
| 3476 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3477 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3478 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3479 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3480 | break; |
| 3481 | } |
| 3482 | |
| 3483 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3484 | if (second.IsFpuRegister()) { |
| 3485 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3486 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3487 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3488 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3489 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3490 | codegen_->LiteralFloatAddress( |
| 3491 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3492 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3493 | } else { |
| 3494 | DCHECK(second.IsStackSlot()); |
| 3495 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3496 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3497 | break; |
| 3498 | } |
| 3499 | |
| 3500 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3501 | if (second.IsFpuRegister()) { |
| 3502 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3503 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3504 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3505 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3506 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3507 | codegen_->LiteralDoubleAddress( |
| 3508 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3509 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3510 | } else { |
| 3511 | DCHECK(second.IsDoubleStackSlot()); |
| 3512 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3513 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3514 | break; |
| 3515 | } |
| 3516 | |
| 3517 | default: |
| 3518 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3519 | } |
| 3520 | } |
| 3521 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3522 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3523 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3524 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3525 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3526 | ? LocationSummary::kCall |
| 3527 | : LocationSummary::kNoCall; |
| 3528 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3529 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3530 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3531 | case Primitive::kPrimInt: { |
| 3532 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3533 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3534 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3535 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3536 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3537 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3538 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3539 | locations->AddTemp(Location::RequiresRegister()); |
| 3540 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3541 | break; |
| 3542 | } |
| 3543 | case Primitive::kPrimLong: { |
| 3544 | InvokeRuntimeCallingConvention calling_convention; |
| 3545 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3546 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3547 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3548 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3549 | // Runtime helper puts the result in EAX, EDX. |
| 3550 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3551 | break; |
| 3552 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3553 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3554 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3555 | locations->SetInAt(0, Location::Any()); |
| 3556 | locations->SetInAt(1, Location::Any()); |
| 3557 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3558 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3559 | break; |
| 3560 | } |
| 3561 | |
| 3562 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3563 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | |
| 3567 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3568 | Primitive::Type type = rem->GetResultType(); |
| 3569 | switch (type) { |
| 3570 | case Primitive::kPrimInt: |
| 3571 | case Primitive::kPrimLong: { |
| 3572 | GenerateDivRemIntegral(rem); |
| 3573 | break; |
| 3574 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3575 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3576 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3577 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3578 | break; |
| 3579 | } |
| 3580 | default: |
| 3581 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3582 | } |
| 3583 | } |
| 3584 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3585 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3586 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3587 | ? LocationSummary::kCallOnSlowPath |
| 3588 | : LocationSummary::kNoCall; |
| 3589 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3590 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3591 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3592 | case Primitive::kPrimByte: |
| 3593 | case Primitive::kPrimChar: |
| 3594 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3595 | case Primitive::kPrimInt: { |
| 3596 | locations->SetInAt(0, Location::Any()); |
| 3597 | break; |
| 3598 | } |
| 3599 | case Primitive::kPrimLong: { |
| 3600 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3601 | if (!instruction->IsConstant()) { |
| 3602 | locations->AddTemp(Location::RequiresRegister()); |
| 3603 | } |
| 3604 | break; |
| 3605 | } |
| 3606 | default: |
| 3607 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3608 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3609 | if (instruction->HasUses()) { |
| 3610 | locations->SetOut(Location::SameAsFirstInput()); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3615 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3616 | codegen_->AddSlowPath(slow_path); |
| 3617 | |
| 3618 | LocationSummary* locations = instruction->GetLocations(); |
| 3619 | Location value = locations->InAt(0); |
| 3620 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3621 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3622 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3623 | case Primitive::kPrimByte: |
| 3624 | case Primitive::kPrimChar: |
| 3625 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3626 | case Primitive::kPrimInt: { |
| 3627 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3628 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3629 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3630 | } else if (value.IsStackSlot()) { |
| 3631 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3632 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3633 | } else { |
| 3634 | DCHECK(value.IsConstant()) << value; |
| 3635 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3636 | __ jmp(slow_path->GetEntryLabel()); |
| 3637 | } |
| 3638 | } |
| 3639 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3640 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3641 | case Primitive::kPrimLong: { |
| 3642 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3643 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3644 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3645 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3646 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3647 | } else { |
| 3648 | DCHECK(value.IsConstant()) << value; |
| 3649 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3650 | __ jmp(slow_path->GetEntryLabel()); |
| 3651 | } |
| 3652 | } |
| 3653 | break; |
| 3654 | } |
| 3655 | default: |
| 3656 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3657 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3658 | } |
| 3659 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3660 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3661 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3662 | |
| 3663 | LocationSummary* locations = |
| 3664 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3665 | |
| 3666 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3667 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3668 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3669 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3670 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3671 | // The shift count needs to be in CL or a constant. |
| 3672 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3673 | locations->SetOut(Location::SameAsFirstInput()); |
| 3674 | break; |
| 3675 | } |
| 3676 | default: |
| 3677 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3682 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3683 | |
| 3684 | LocationSummary* locations = op->GetLocations(); |
| 3685 | Location first = locations->InAt(0); |
| 3686 | Location second = locations->InAt(1); |
| 3687 | DCHECK(first.Equals(locations->Out())); |
| 3688 | |
| 3689 | switch (op->GetResultType()) { |
| 3690 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3691 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3692 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3693 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3694 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3695 | DCHECK_EQ(ECX, second_reg); |
| 3696 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3697 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3698 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3699 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3700 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3701 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3702 | } |
| 3703 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3704 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3705 | if (shift == 0) { |
| 3706 | return; |
| 3707 | } |
| 3708 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3709 | if (op->IsShl()) { |
| 3710 | __ shll(first_reg, imm); |
| 3711 | } else if (op->IsShr()) { |
| 3712 | __ sarl(first_reg, imm); |
| 3713 | } else { |
| 3714 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3715 | } |
| 3716 | } |
| 3717 | break; |
| 3718 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3719 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3720 | if (second.IsRegister()) { |
| 3721 | Register second_reg = second.AsRegister<Register>(); |
| 3722 | DCHECK_EQ(ECX, second_reg); |
| 3723 | if (op->IsShl()) { |
| 3724 | GenerateShlLong(first, second_reg); |
| 3725 | } else if (op->IsShr()) { |
| 3726 | GenerateShrLong(first, second_reg); |
| 3727 | } else { |
| 3728 | GenerateUShrLong(first, second_reg); |
| 3729 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3730 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3731 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3732 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3733 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3734 | if (shift != 0) { |
| 3735 | if (op->IsShl()) { |
| 3736 | GenerateShlLong(first, shift); |
| 3737 | } else if (op->IsShr()) { |
| 3738 | GenerateShrLong(first, shift); |
| 3739 | } else { |
| 3740 | GenerateUShrLong(first, shift); |
| 3741 | } |
| 3742 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3743 | } |
| 3744 | break; |
| 3745 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3746 | default: |
| 3747 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3748 | } |
| 3749 | } |
| 3750 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3751 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3752 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3753 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3754 | if (shift == 1) { |
| 3755 | // This is just an addition. |
| 3756 | __ addl(low, low); |
| 3757 | __ adcl(high, high); |
| 3758 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3759 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3760 | codegen_->EmitParallelMoves( |
| 3761 | loc.ToLow(), |
| 3762 | loc.ToHigh(), |
| 3763 | Primitive::kPrimInt, |
| 3764 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3765 | loc.ToLow(), |
| 3766 | Primitive::kPrimInt); |
| 3767 | } else if (shift > 32) { |
| 3768 | // Low part becomes 0. High part is low part << (shift-32). |
| 3769 | __ movl(high, low); |
| 3770 | __ shll(high, Immediate(shift - 32)); |
| 3771 | __ xorl(low, low); |
| 3772 | } else { |
| 3773 | // Between 1 and 31. |
| 3774 | __ shld(high, low, Immediate(shift)); |
| 3775 | __ shll(low, Immediate(shift)); |
| 3776 | } |
| 3777 | } |
| 3778 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3779 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3780 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3781 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3782 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3783 | __ testl(shifter, Immediate(32)); |
| 3784 | __ j(kEqual, &done); |
| 3785 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3786 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3787 | __ Bind(&done); |
| 3788 | } |
| 3789 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3790 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3791 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3792 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3793 | if (shift == 32) { |
| 3794 | // Need to copy the sign. |
| 3795 | DCHECK_NE(low, high); |
| 3796 | __ movl(low, high); |
| 3797 | __ sarl(high, Immediate(31)); |
| 3798 | } else if (shift > 32) { |
| 3799 | DCHECK_NE(low, high); |
| 3800 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3801 | __ movl(low, high); |
| 3802 | __ sarl(high, Immediate(31)); |
| 3803 | __ sarl(low, Immediate(shift - 32)); |
| 3804 | } else { |
| 3805 | // Between 1 and 31. |
| 3806 | __ shrd(low, high, Immediate(shift)); |
| 3807 | __ sarl(high, Immediate(shift)); |
| 3808 | } |
| 3809 | } |
| 3810 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3811 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3812 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3813 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3814 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3815 | __ testl(shifter, Immediate(32)); |
| 3816 | __ j(kEqual, &done); |
| 3817 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3818 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3819 | __ Bind(&done); |
| 3820 | } |
| 3821 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3822 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3823 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3824 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3825 | if (shift == 32) { |
| 3826 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3827 | codegen_->EmitParallelMoves( |
| 3828 | loc.ToHigh(), |
| 3829 | loc.ToLow(), |
| 3830 | Primitive::kPrimInt, |
| 3831 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3832 | loc.ToHigh(), |
| 3833 | Primitive::kPrimInt); |
| 3834 | } else if (shift > 32) { |
| 3835 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3836 | __ movl(low, high); |
| 3837 | __ shrl(low, Immediate(shift - 32)); |
| 3838 | __ xorl(high, high); |
| 3839 | } else { |
| 3840 | // Between 1 and 31. |
| 3841 | __ shrd(low, high, Immediate(shift)); |
| 3842 | __ shrl(high, Immediate(shift)); |
| 3843 | } |
| 3844 | } |
| 3845 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3846 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3847 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3848 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3849 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3850 | __ testl(shifter, Immediate(32)); |
| 3851 | __ j(kEqual, &done); |
| 3852 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3853 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3854 | __ Bind(&done); |
| 3855 | } |
| 3856 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3857 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3858 | LocationSummary* locations = |
| 3859 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3860 | |
| 3861 | switch (ror->GetResultType()) { |
| 3862 | case Primitive::kPrimLong: |
| 3863 | // Add the temporary needed. |
| 3864 | locations->AddTemp(Location::RequiresRegister()); |
| 3865 | FALLTHROUGH_INTENDED; |
| 3866 | case Primitive::kPrimInt: |
| 3867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3868 | // The shift count needs to be in CL (unless it is a constant). |
| 3869 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3870 | locations->SetOut(Location::SameAsFirstInput()); |
| 3871 | break; |
| 3872 | default: |
| 3873 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3874 | UNREACHABLE(); |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3879 | LocationSummary* locations = ror->GetLocations(); |
| 3880 | Location first = locations->InAt(0); |
| 3881 | Location second = locations->InAt(1); |
| 3882 | |
| 3883 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3884 | Register first_reg = first.AsRegister<Register>(); |
| 3885 | if (second.IsRegister()) { |
| 3886 | Register second_reg = second.AsRegister<Register>(); |
| 3887 | __ rorl(first_reg, second_reg); |
| 3888 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3889 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3890 | __ rorl(first_reg, imm); |
| 3891 | } |
| 3892 | return; |
| 3893 | } |
| 3894 | |
| 3895 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3896 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3897 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3898 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3899 | if (second.IsRegister()) { |
| 3900 | Register second_reg = second.AsRegister<Register>(); |
| 3901 | DCHECK_EQ(second_reg, ECX); |
| 3902 | __ movl(temp_reg, first_reg_hi); |
| 3903 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3904 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3905 | __ movl(temp_reg, first_reg_hi); |
| 3906 | __ testl(second_reg, Immediate(32)); |
| 3907 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3908 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3909 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3910 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3911 | if (shift_amt == 0) { |
| 3912 | // Already fine. |
| 3913 | return; |
| 3914 | } |
| 3915 | if (shift_amt == 32) { |
| 3916 | // Just swap. |
| 3917 | __ movl(temp_reg, first_reg_lo); |
| 3918 | __ movl(first_reg_lo, first_reg_hi); |
| 3919 | __ movl(first_reg_hi, temp_reg); |
| 3920 | return; |
| 3921 | } |
| 3922 | |
| 3923 | Immediate imm(shift_amt); |
| 3924 | // Save the constents of the low value. |
| 3925 | __ movl(temp_reg, first_reg_lo); |
| 3926 | |
| 3927 | // Shift right into low, feeding bits from high. |
| 3928 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3929 | |
| 3930 | // Shift right into high, feeding bits from the original low. |
| 3931 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3932 | |
| 3933 | // Swap if needed. |
| 3934 | if (shift_amt > 32) { |
| 3935 | __ movl(temp_reg, first_reg_lo); |
| 3936 | __ movl(first_reg_lo, first_reg_hi); |
| 3937 | __ movl(first_reg_hi, temp_reg); |
| 3938 | } |
| 3939 | } |
| 3940 | } |
| 3941 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3942 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3943 | HandleShift(shl); |
| 3944 | } |
| 3945 | |
| 3946 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3947 | HandleShift(shl); |
| 3948 | } |
| 3949 | |
| 3950 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3951 | HandleShift(shr); |
| 3952 | } |
| 3953 | |
| 3954 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3955 | HandleShift(shr); |
| 3956 | } |
| 3957 | |
| 3958 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3959 | HandleShift(ushr); |
| 3960 | } |
| 3961 | |
| 3962 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3963 | HandleShift(ushr); |
| 3964 | } |
| 3965 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3966 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3967 | LocationSummary* locations = |
| 3968 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3969 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3970 | if (instruction->IsStringAlloc()) { |
| 3971 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3972 | } else { |
| 3973 | InvokeRuntimeCallingConvention calling_convention; |
| 3974 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3975 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3976 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3980 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3981 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3982 | if (instruction->IsStringAlloc()) { |
| 3983 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3984 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3985 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3986 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3987 | __ call(Address(temp, code_offset.Int32Value())); |
| 3988 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3989 | } else { |
| 3990 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3991 | instruction, |
| 3992 | instruction->GetDexPc(), |
| 3993 | nullptr); |
| 3994 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3995 | DCHECK(!codegen_->IsLeafMethod()); |
| 3996 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3999 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4000 | LocationSummary* locations = |
| 4001 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4002 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4003 | InvokeRuntimeCallingConvention calling_convention; |
| 4004 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4005 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4006 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4007 | } |
| 4008 | |
| 4009 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4010 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4011 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4012 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4013 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4014 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4015 | instruction, |
| 4016 | instruction->GetDexPc(), |
| 4017 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4018 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4019 | DCHECK(!codegen_->IsLeafMethod()); |
| 4020 | } |
| 4021 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4022 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4023 | LocationSummary* locations = |
| 4024 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4025 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4026 | if (location.IsStackSlot()) { |
| 4027 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4028 | } else if (location.IsDoubleStackSlot()) { |
| 4029 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4030 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4031 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4032 | } |
| 4033 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4034 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4035 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4036 | } |
| 4037 | |
| 4038 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4039 | LocationSummary* locations = |
| 4040 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4041 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4042 | } |
| 4043 | |
| 4044 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4045 | } |
| 4046 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4047 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4048 | LocationSummary* locations = |
| 4049 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4050 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4051 | locations->SetOut(Location::RequiresRegister()); |
| 4052 | } |
| 4053 | |
| 4054 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4055 | LocationSummary* locations = instruction->GetLocations(); |
| 4056 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4057 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4058 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4059 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4060 | } else { |
| 4061 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4062 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4063 | } |
| 4064 | __ movl(locations->Out().AsRegister<Register>(), |
| 4065 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4066 | } |
| 4067 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4068 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4069 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4070 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4071 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4072 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4073 | } |
| 4074 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4075 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4076 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4077 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4078 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4079 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4080 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4081 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4082 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4083 | break; |
| 4084 | |
| 4085 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4086 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4087 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4088 | break; |
| 4089 | |
| 4090 | default: |
| 4091 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4092 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4093 | } |
| 4094 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4095 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4096 | LocationSummary* locations = |
| 4097 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4098 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4099 | locations->SetOut(Location::SameAsFirstInput()); |
| 4100 | } |
| 4101 | |
| 4102 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4103 | LocationSummary* locations = bool_not->GetLocations(); |
| 4104 | Location in = locations->InAt(0); |
| 4105 | Location out = locations->Out(); |
| 4106 | DCHECK(in.Equals(out)); |
| 4107 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4108 | } |
| 4109 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4110 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4111 | LocationSummary* locations = |
| 4112 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4113 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4114 | case Primitive::kPrimBoolean: |
| 4115 | case Primitive::kPrimByte: |
| 4116 | case Primitive::kPrimShort: |
| 4117 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4118 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4119 | case Primitive::kPrimLong: { |
| 4120 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4121 | locations->SetInAt(1, Location::Any()); |
| 4122 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4123 | break; |
| 4124 | } |
| 4125 | case Primitive::kPrimFloat: |
| 4126 | case Primitive::kPrimDouble: { |
| 4127 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4128 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4129 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4130 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4131 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4132 | } else { |
| 4133 | locations->SetInAt(1, Location::Any()); |
| 4134 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4135 | locations->SetOut(Location::RequiresRegister()); |
| 4136 | break; |
| 4137 | } |
| 4138 | default: |
| 4139 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4140 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4144 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4145 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4146 | Location left = locations->InAt(0); |
| 4147 | Location right = locations->InAt(1); |
| 4148 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4149 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4150 | Condition less_cond = kLess; |
| 4151 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4152 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4153 | case Primitive::kPrimBoolean: |
| 4154 | case Primitive::kPrimByte: |
| 4155 | case Primitive::kPrimShort: |
| 4156 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4157 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4158 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4159 | break; |
| 4160 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4161 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4162 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4163 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4164 | int32_t val_low = 0; |
| 4165 | int32_t val_high = 0; |
| 4166 | bool right_is_const = false; |
| 4167 | |
| 4168 | if (right.IsConstant()) { |
| 4169 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4170 | right_is_const = true; |
| 4171 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4172 | val_low = Low32Bits(val); |
| 4173 | val_high = High32Bits(val); |
| 4174 | } |
| 4175 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4176 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4177 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4178 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4179 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4180 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4181 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4182 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4183 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4184 | __ j(kLess, &less); // Signed compare. |
| 4185 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4186 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4187 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4188 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4189 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4190 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4191 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4192 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4193 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4194 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4195 | break; |
| 4196 | } |
| 4197 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4198 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4199 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4200 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4201 | break; |
| 4202 | } |
| 4203 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4204 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4205 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4206 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4207 | break; |
| 4208 | } |
| 4209 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4210 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4211 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4212 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4213 | __ movl(out, Immediate(0)); |
| 4214 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4215 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4216 | |
| 4217 | __ Bind(&greater); |
| 4218 | __ movl(out, Immediate(1)); |
| 4219 | __ jmp(&done); |
| 4220 | |
| 4221 | __ Bind(&less); |
| 4222 | __ movl(out, Immediate(-1)); |
| 4223 | |
| 4224 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4225 | } |
| 4226 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4227 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4228 | LocationSummary* locations = |
| 4229 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4230 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4231 | locations->SetInAt(i, Location::Any()); |
| 4232 | } |
| 4233 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4234 | } |
| 4235 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4236 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4237 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4238 | } |
| 4239 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4240 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4241 | /* |
| 4242 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4243 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4244 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4245 | */ |
| 4246 | switch (kind) { |
| 4247 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4248 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4249 | break; |
| 4250 | } |
| 4251 | case MemBarrierKind::kAnyStore: |
| 4252 | case MemBarrierKind::kLoadAny: |
| 4253 | case MemBarrierKind::kStoreStore: { |
| 4254 | // nop |
| 4255 | break; |
| 4256 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4257 | case MemBarrierKind::kNTStoreStore: |
| 4258 | // Non-Temporal Store/Store needs an explicit fence. |
| 4259 | MemoryFence(/* non-temporal */ true); |
| 4260 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4261 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4262 | } |
| 4263 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4264 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4265 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4266 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4267 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4268 | |
| 4269 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4270 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4271 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4272 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4273 | if (GetGraph()->HasIrreducibleLoops() && |
| 4274 | (dispatch_info.method_load_kind == |
| 4275 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4276 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4277 | } |
| 4278 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4279 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4280 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4281 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4282 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4283 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4284 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4285 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4286 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4287 | 0u |
| 4288 | }; |
| 4289 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4290 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4291 | } |
| 4292 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4293 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4294 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4295 | Register temp) { |
| 4296 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4297 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4298 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4299 | return location.AsRegister<Register>(); |
| 4300 | } |
| 4301 | // For intrinsics we allow any location, so it may be on the stack. |
| 4302 | if (!location.IsRegister()) { |
| 4303 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4304 | return temp; |
| 4305 | } |
| 4306 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4307 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4308 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4309 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4310 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4311 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4312 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4313 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4314 | __ movl(temp, Address(ESP, stack_offset)); |
| 4315 | return temp; |
| 4316 | } |
| 4317 | return location.AsRegister<Register>(); |
| 4318 | } |
| 4319 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4320 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4321 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4322 | switch (invoke->GetMethodLoadKind()) { |
| 4323 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4324 | // temp = thread->string_init_entrypoint |
| 4325 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4326 | break; |
| 4327 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4328 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4329 | break; |
| 4330 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4331 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4332 | break; |
| 4333 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4334 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4335 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4336 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4337 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4338 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4339 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4340 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4341 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4342 | // Bind a new fixup label at the end of the "movl" insn. |
| 4343 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4344 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4345 | break; |
| 4346 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4347 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4348 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4349 | Register method_reg; |
| 4350 | Register reg = temp.AsRegister<Register>(); |
| 4351 | if (current_method.IsRegister()) { |
| 4352 | method_reg = current_method.AsRegister<Register>(); |
| 4353 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4354 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4355 | DCHECK(!current_method.IsValid()); |
| 4356 | method_reg = reg; |
| 4357 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4358 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4359 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4360 | __ movl(reg, Address(method_reg, |
| 4361 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4362 | // temp = temp[index_in_cache]; |
| 4363 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4364 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4365 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4366 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4367 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | switch (invoke->GetCodePtrLocation()) { |
| 4371 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4372 | __ call(GetFrameEntryLabel()); |
| 4373 | break; |
| 4374 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4375 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4376 | Label* label = &relative_call_patches_.back().label; |
| 4377 | __ call(label); // Bind to the patch label, override at link time. |
| 4378 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4379 | break; |
| 4380 | } |
| 4381 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4382 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4383 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4384 | LOG(FATAL) << "Unsupported"; |
| 4385 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4386 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4387 | // (callee_method + offset_of_quick_compiled_code)() |
| 4388 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4389 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4390 | kX86WordSize).Int32Value())); |
| 4391 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4395 | } |
| 4396 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4397 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4398 | Register temp = temp_in.AsRegister<Register>(); |
| 4399 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4400 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4401 | |
| 4402 | // Use the calling convention instead of the location of the receiver, as |
| 4403 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4404 | // slow path, the arguments have been moved to the right place, so here we are |
| 4405 | // guaranteed that the receiver is the first register of the calling convention. |
| 4406 | InvokeDexCallingConvention calling_convention; |
| 4407 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4408 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4409 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4410 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4411 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4412 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4413 | // emit a read barrier for the previous class reference load. |
| 4414 | // However this is not required in practice, as this is an |
| 4415 | // intermediate/temporary reference and because the current |
| 4416 | // concurrent copying collector keeps the from-space memory |
| 4417 | // intact/accessible until the end of the marking phase (the |
| 4418 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4419 | __ MaybeUnpoisonHeapReference(temp); |
| 4420 | // temp = temp->GetMethodAt(method_offset); |
| 4421 | __ movl(temp, Address(temp, method_offset)); |
| 4422 | // call temp->GetEntryPoint(); |
| 4423 | __ call(Address( |
| 4424 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4425 | } |
| 4426 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4427 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4428 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4429 | simple_patches_.emplace_back(); |
| 4430 | __ Bind(&simple_patches_.back()); |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4435 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4436 | __ Bind(&string_patches_.back().label); |
| 4437 | } |
| 4438 | |
| 4439 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4440 | uint32_t element_offset) { |
| 4441 | // Add the patch entry and bind its label at the end of the instruction. |
| 4442 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4443 | return &pc_relative_dex_cache_patches_.back().label; |
| 4444 | } |
| 4445 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4446 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4447 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4448 | size_t size = |
| 4449 | method_patches_.size() + |
| 4450 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4451 | pc_relative_dex_cache_patches_.size() + |
| 4452 | simple_patches_.size() + |
| 4453 | string_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4454 | linker_patches->reserve(size); |
| 4455 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4456 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4457 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4458 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4459 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4460 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4461 | info.target_method.dex_file, |
| 4462 | info.target_method.dex_method_index)); |
| 4463 | } |
| 4464 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4465 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4466 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4467 | info.target_method.dex_file, |
| 4468 | info.target_method.dex_method_index)); |
| 4469 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4470 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4471 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4472 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4473 | &info.target_dex_file, |
| 4474 | GetMethodAddressOffset(), |
| 4475 | info.element_offset)); |
| 4476 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4477 | for (const Label& label : simple_patches_) { |
| 4478 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4479 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4480 | } |
| 4481 | if (GetCompilerOptions().GetCompilePic()) { |
| 4482 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4483 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4484 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4485 | &info.dex_file, |
| 4486 | GetMethodAddressOffset(), |
| 4487 | info.string_index)); |
| 4488 | } |
| 4489 | } else { |
| 4490 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4491 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4492 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4493 | &info.dex_file, |
| 4494 | info.string_index)); |
| 4495 | } |
| 4496 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4499 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4500 | Register card, |
| 4501 | Register object, |
| 4502 | Register value, |
| 4503 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4504 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4505 | if (value_can_be_null) { |
| 4506 | __ testl(value, value); |
| 4507 | __ j(kEqual, &is_null); |
| 4508 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4509 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4510 | __ movl(temp, object); |
| 4511 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4512 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4513 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4514 | if (value_can_be_null) { |
| 4515 | __ Bind(&is_null); |
| 4516 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4519 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4520 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4521 | |
| 4522 | bool object_field_get_with_read_barrier = |
| 4523 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4524 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4525 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4526 | kEmitCompilerReadBarrier ? |
| 4527 | LocationSummary::kCallOnSlowPath : |
| 4528 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4529 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4530 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4531 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4532 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4533 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4534 | // The output overlaps in case of long: we don't want the low move |
| 4535 | // to overwrite the object's location. Likewise, in the case of |
| 4536 | // an object field get with read barriers enabled, we do not want |
| 4537 | // the move to overwrite the object's location, as we need it to emit |
| 4538 | // the read barrier. |
| 4539 | locations->SetOut( |
| 4540 | Location::RequiresRegister(), |
| 4541 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4542 | Location::kOutputOverlap : |
| 4543 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4544 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4545 | |
| 4546 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4547 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4548 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4549 | // load the temp into the XMM and then copy the XMM into the |
| 4550 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4551 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4552 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4553 | // We need a temporary register for the read barrier marking slow |
| 4554 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4555 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4556 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4557 | } |
| 4558 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4560 | const FieldInfo& field_info) { |
| 4561 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4562 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4563 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4564 | Location base_loc = locations->InAt(0); |
| 4565 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4566 | Location out = locations->Out(); |
| 4567 | bool is_volatile = field_info.IsVolatile(); |
| 4568 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4569 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4570 | |
| 4571 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4572 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4573 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4574 | break; |
| 4575 | } |
| 4576 | |
| 4577 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4579 | break; |
| 4580 | } |
| 4581 | |
| 4582 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4583 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4584 | break; |
| 4585 | } |
| 4586 | |
| 4587 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4589 | break; |
| 4590 | } |
| 4591 | |
| 4592 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4593 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4594 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4595 | |
| 4596 | case Primitive::kPrimNot: { |
| 4597 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4598 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4599 | Location temp_loc = locations->GetTemp(0); |
| 4600 | // Note that a potential implicit null check is handled in this |
| 4601 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4602 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4603 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4604 | if (is_volatile) { |
| 4605 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4606 | } |
| 4607 | } else { |
| 4608 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4609 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4610 | if (is_volatile) { |
| 4611 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4612 | } |
| 4613 | // If read barriers are enabled, emit read barriers other than |
| 4614 | // Baker's using a slow path (and also unpoison the loaded |
| 4615 | // reference, if heap poisoning is enabled). |
| 4616 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4617 | } |
| 4618 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4622 | if (is_volatile) { |
| 4623 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4624 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4625 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4626 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4627 | __ psrlq(temp, Immediate(32)); |
| 4628 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4629 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4630 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4631 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4632 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4634 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4635 | break; |
| 4636 | } |
| 4637 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4638 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4639 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4640 | break; |
| 4641 | } |
| 4642 | |
| 4643 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4645 | break; |
| 4646 | } |
| 4647 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4648 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4649 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4650 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4651 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4652 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4653 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4654 | // Potential implicit null checks, in the case of reference or |
| 4655 | // long fields, are handled in the previous switch statement. |
| 4656 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4657 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4658 | } |
| 4659 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4660 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4661 | if (field_type == Primitive::kPrimNot) { |
| 4662 | // Memory barriers, in the case of references, are also handled |
| 4663 | // in the previous switch statement. |
| 4664 | } else { |
| 4665 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4666 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4667 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4671 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4672 | |
| 4673 | LocationSummary* locations = |
| 4674 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4675 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4676 | bool is_volatile = field_info.IsVolatile(); |
| 4677 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4678 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4679 | || (field_type == Primitive::kPrimByte); |
| 4680 | |
| 4681 | // The register allocator does not support multiple |
| 4682 | // inputs that die at entry with one in a specific register. |
| 4683 | if (is_byte_type) { |
| 4684 | // Ensure the value is in a byte register. |
| 4685 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4686 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4687 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4688 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4689 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4690 | } else { |
| 4691 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4692 | } |
| 4693 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4694 | // 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] | 4695 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4696 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4697 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4698 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4699 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4700 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4701 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4702 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4703 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4704 | } else { |
| 4705 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4706 | |
| 4707 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4708 | // Temporary registers for the write barrier. |
| 4709 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4710 | // Ensure the card is in a byte register. |
| 4711 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4712 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4717 | const FieldInfo& field_info, |
| 4718 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4720 | |
| 4721 | LocationSummary* locations = instruction->GetLocations(); |
| 4722 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4723 | Location value = locations->InAt(1); |
| 4724 | bool is_volatile = field_info.IsVolatile(); |
| 4725 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4726 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4727 | bool needs_write_barrier = |
| 4728 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4729 | |
| 4730 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4731 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4732 | } |
| 4733 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4734 | bool maybe_record_implicit_null_check_done = false; |
| 4735 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4736 | switch (field_type) { |
| 4737 | case Primitive::kPrimBoolean: |
| 4738 | case Primitive::kPrimByte: { |
| 4739 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4740 | break; |
| 4741 | } |
| 4742 | |
| 4743 | case Primitive::kPrimShort: |
| 4744 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4745 | if (value.IsConstant()) { |
| 4746 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4747 | __ movw(Address(base, offset), Immediate(v)); |
| 4748 | } else { |
| 4749 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4750 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4751 | break; |
| 4752 | } |
| 4753 | |
| 4754 | case Primitive::kPrimInt: |
| 4755 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4756 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4757 | // Note that in the case where `value` is a null reference, |
| 4758 | // we do not enter this block, as the reference does not |
| 4759 | // need poisoning. |
| 4760 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4761 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4762 | __ movl(temp, value.AsRegister<Register>()); |
| 4763 | __ PoisonHeapReference(temp); |
| 4764 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4765 | } else if (value.IsConstant()) { |
| 4766 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4767 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4768 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4769 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4770 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4771 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4772 | break; |
| 4773 | } |
| 4774 | |
| 4775 | case Primitive::kPrimLong: { |
| 4776 | if (is_volatile) { |
| 4777 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4778 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4779 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4780 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4781 | __ punpckldq(temp1, temp2); |
| 4782 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4783 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4784 | } else if (value.IsConstant()) { |
| 4785 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4786 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4787 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4788 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4789 | } else { |
| 4790 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4791 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4792 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4793 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4794 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4795 | break; |
| 4796 | } |
| 4797 | |
| 4798 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4799 | if (value.IsConstant()) { |
| 4800 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4801 | __ movl(Address(base, offset), Immediate(v)); |
| 4802 | } else { |
| 4803 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4804 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4809 | if (value.IsConstant()) { |
| 4810 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4811 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4812 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4813 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4814 | maybe_record_implicit_null_check_done = true; |
| 4815 | } else { |
| 4816 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4817 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4818 | break; |
| 4819 | } |
| 4820 | |
| 4821 | case Primitive::kPrimVoid: |
| 4822 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4823 | UNREACHABLE(); |
| 4824 | } |
| 4825 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4826 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4827 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4828 | } |
| 4829 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4830 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4831 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4832 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4833 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4834 | } |
| 4835 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4836 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4837 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4838 | } |
| 4839 | } |
| 4840 | |
| 4841 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4842 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4843 | } |
| 4844 | |
| 4845 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4846 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4847 | } |
| 4848 | |
| 4849 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4850 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4851 | } |
| 4852 | |
| 4853 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4854 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4858 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4859 | } |
| 4860 | |
| 4861 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4862 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4866 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4867 | } |
| 4868 | |
| 4869 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4870 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4873 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4874 | HUnresolvedInstanceFieldGet* instruction) { |
| 4875 | FieldAccessCallingConventionX86 calling_convention; |
| 4876 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4877 | instruction, instruction->GetFieldType(), calling_convention); |
| 4878 | } |
| 4879 | |
| 4880 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4881 | HUnresolvedInstanceFieldGet* instruction) { |
| 4882 | FieldAccessCallingConventionX86 calling_convention; |
| 4883 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4884 | instruction->GetFieldType(), |
| 4885 | instruction->GetFieldIndex(), |
| 4886 | instruction->GetDexPc(), |
| 4887 | calling_convention); |
| 4888 | } |
| 4889 | |
| 4890 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4891 | HUnresolvedInstanceFieldSet* instruction) { |
| 4892 | FieldAccessCallingConventionX86 calling_convention; |
| 4893 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4894 | instruction, instruction->GetFieldType(), calling_convention); |
| 4895 | } |
| 4896 | |
| 4897 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4898 | HUnresolvedInstanceFieldSet* instruction) { |
| 4899 | FieldAccessCallingConventionX86 calling_convention; |
| 4900 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4901 | instruction->GetFieldType(), |
| 4902 | instruction->GetFieldIndex(), |
| 4903 | instruction->GetDexPc(), |
| 4904 | calling_convention); |
| 4905 | } |
| 4906 | |
| 4907 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4908 | HUnresolvedStaticFieldGet* instruction) { |
| 4909 | FieldAccessCallingConventionX86 calling_convention; |
| 4910 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4911 | instruction, instruction->GetFieldType(), calling_convention); |
| 4912 | } |
| 4913 | |
| 4914 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4915 | HUnresolvedStaticFieldGet* instruction) { |
| 4916 | FieldAccessCallingConventionX86 calling_convention; |
| 4917 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4918 | instruction->GetFieldType(), |
| 4919 | instruction->GetFieldIndex(), |
| 4920 | instruction->GetDexPc(), |
| 4921 | calling_convention); |
| 4922 | } |
| 4923 | |
| 4924 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4925 | HUnresolvedStaticFieldSet* instruction) { |
| 4926 | FieldAccessCallingConventionX86 calling_convention; |
| 4927 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4928 | instruction, instruction->GetFieldType(), calling_convention); |
| 4929 | } |
| 4930 | |
| 4931 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4932 | HUnresolvedStaticFieldSet* instruction) { |
| 4933 | FieldAccessCallingConventionX86 calling_convention; |
| 4934 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4935 | instruction->GetFieldType(), |
| 4936 | instruction->GetFieldIndex(), |
| 4937 | instruction->GetDexPc(), |
| 4938 | calling_convention); |
| 4939 | } |
| 4940 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4941 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4942 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4943 | ? LocationSummary::kCallOnSlowPath |
| 4944 | : LocationSummary::kNoCall; |
| 4945 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4946 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4947 | ? Location::RequiresRegister() |
| 4948 | : Location::Any(); |
| 4949 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4950 | if (instruction->HasUses()) { |
| 4951 | locations->SetOut(Location::SameAsFirstInput()); |
| 4952 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4953 | } |
| 4954 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4955 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4956 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4957 | return; |
| 4958 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4959 | LocationSummary* locations = instruction->GetLocations(); |
| 4960 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4961 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4962 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4963 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4964 | } |
| 4965 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4966 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4967 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4968 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4969 | |
| 4970 | LocationSummary* locations = instruction->GetLocations(); |
| 4971 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4972 | |
| 4973 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4974 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4975 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4976 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4977 | } else { |
| 4978 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4979 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4980 | __ jmp(slow_path->GetEntryLabel()); |
| 4981 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4982 | } |
| 4983 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4984 | } |
| 4985 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4986 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4987 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4988 | } |
| 4989 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4990 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4991 | bool object_array_get_with_read_barrier = |
| 4992 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4993 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4994 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4995 | object_array_get_with_read_barrier ? |
| 4996 | LocationSummary::kCallOnSlowPath : |
| 4997 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4998 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4999 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5000 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5001 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5002 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5003 | // The output overlaps in case of long: we don't want the low move |
| 5004 | // to overwrite the array's location. Likewise, in the case of an |
| 5005 | // object array get with read barriers enabled, we do not want the |
| 5006 | // move to overwrite the array's location, as we need it to emit |
| 5007 | // the read barrier. |
| 5008 | locations->SetOut( |
| 5009 | Location::RequiresRegister(), |
| 5010 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5011 | Location::kOutputOverlap : |
| 5012 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5013 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5014 | // We need a temporary register for the read barrier marking slow |
| 5015 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5016 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5017 | locations->AddTemp(Location::RequiresRegister()); |
| 5018 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5022 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5023 | Location obj_loc = locations->InAt(0); |
| 5024 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5025 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5026 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5027 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5028 | Primitive::Type type = instruction->GetType(); |
| 5029 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5030 | case Primitive::kPrimBoolean: { |
| 5031 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5032 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5033 | if (index.IsConstant()) { |
| 5034 | __ movzxb(out, Address(obj, |
| 5035 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5036 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5037 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | } |
| 5039 | break; |
| 5040 | } |
| 5041 | |
| 5042 | case Primitive::kPrimByte: { |
| 5043 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5044 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5045 | if (index.IsConstant()) { |
| 5046 | __ movsxb(out, Address(obj, |
| 5047 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5048 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5049 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5050 | } |
| 5051 | break; |
| 5052 | } |
| 5053 | |
| 5054 | case Primitive::kPrimShort: { |
| 5055 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5056 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5057 | if (index.IsConstant()) { |
| 5058 | __ movsxw(out, Address(obj, |
| 5059 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5060 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5061 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5062 | } |
| 5063 | break; |
| 5064 | } |
| 5065 | |
| 5066 | case Primitive::kPrimChar: { |
| 5067 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5068 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5069 | if (index.IsConstant()) { |
| 5070 | __ movzxw(out, Address(obj, |
| 5071 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5072 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5073 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5074 | } |
| 5075 | break; |
| 5076 | } |
| 5077 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5078 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5079 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5080 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5081 | if (index.IsConstant()) { |
| 5082 | __ movl(out, Address(obj, |
| 5083 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5084 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5085 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5086 | } |
| 5087 | break; |
| 5088 | } |
| 5089 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5090 | case Primitive::kPrimNot: { |
| 5091 | static_assert( |
| 5092 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5093 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5094 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5095 | // /* HeapReference<Object> */ out = |
| 5096 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5097 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5098 | Location temp = locations->GetTemp(0); |
| 5099 | // Note that a potential implicit null check is handled in this |
| 5100 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5101 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5102 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5103 | } else { |
| 5104 | Register out = out_loc.AsRegister<Register>(); |
| 5105 | if (index.IsConstant()) { |
| 5106 | uint32_t offset = |
| 5107 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5108 | __ movl(out, Address(obj, offset)); |
| 5109 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5110 | // If read barriers are enabled, emit read barriers other than |
| 5111 | // Baker's using a slow path (and also unpoison the loaded |
| 5112 | // reference, if heap poisoning is enabled). |
| 5113 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5114 | } else { |
| 5115 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5116 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5117 | // If read barriers are enabled, emit read barriers other than |
| 5118 | // Baker's using a slow path (and also unpoison the loaded |
| 5119 | // reference, if heap poisoning is enabled). |
| 5120 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5121 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5122 | } |
| 5123 | } |
| 5124 | break; |
| 5125 | } |
| 5126 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5127 | case Primitive::kPrimLong: { |
| 5128 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5129 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5130 | if (index.IsConstant()) { |
| 5131 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5132 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5133 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5134 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5135 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5136 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5137 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5138 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5139 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5140 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5141 | } |
| 5142 | break; |
| 5143 | } |
| 5144 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5145 | case Primitive::kPrimFloat: { |
| 5146 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5147 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5148 | if (index.IsConstant()) { |
| 5149 | __ movss(out, Address(obj, |
| 5150 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5151 | } else { |
| 5152 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5153 | } |
| 5154 | break; |
| 5155 | } |
| 5156 | |
| 5157 | case Primitive::kPrimDouble: { |
| 5158 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5159 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5160 | if (index.IsConstant()) { |
| 5161 | __ movsd(out, Address(obj, |
| 5162 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5163 | } else { |
| 5164 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5165 | } |
| 5166 | break; |
| 5167 | } |
| 5168 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5169 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5170 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5171 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5172 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5173 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5174 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5175 | // Potential implicit null checks, in the case of reference or |
| 5176 | // long arrays, are handled in the previous switch statement. |
| 5177 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5178 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5179 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5183 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5184 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5185 | bool needs_write_barrier = |
| 5186 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5187 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5188 | bool object_array_set_with_read_barrier = |
| 5189 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5190 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5191 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5192 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5193 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5194 | LocationSummary::kCallOnSlowPath : |
| 5195 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5196 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5197 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5198 | || (value_type == Primitive::kPrimByte); |
| 5199 | // We need the inputs to be different than the output in case of long operation. |
| 5200 | // In case of a byte operation, the register allocator does not support multiple |
| 5201 | // inputs that die at entry with one in a specific register. |
| 5202 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5203 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5204 | if (is_byte_type) { |
| 5205 | // Ensure the value is in a byte register. |
| 5206 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5207 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5208 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5209 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5210 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5211 | } |
| 5212 | if (needs_write_barrier) { |
| 5213 | // Temporary registers for the write barrier. |
| 5214 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5215 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5216 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5217 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5221 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5222 | Location array_loc = locations->InAt(0); |
| 5223 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5224 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5225 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5226 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5227 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5228 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5229 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5230 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5231 | bool needs_write_barrier = |
| 5232 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5233 | |
| 5234 | switch (value_type) { |
| 5235 | case Primitive::kPrimBoolean: |
| 5236 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5237 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5238 | Address address = index.IsConstant() |
| 5239 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5240 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5241 | if (value.IsRegister()) { |
| 5242 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5244 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5245 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5246 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5247 | break; |
| 5248 | } |
| 5249 | |
| 5250 | case Primitive::kPrimShort: |
| 5251 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5252 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5253 | Address address = index.IsConstant() |
| 5254 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5255 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5256 | if (value.IsRegister()) { |
| 5257 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5259 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5260 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5261 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5262 | break; |
| 5263 | } |
| 5264 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5265 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5266 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5267 | Address address = index.IsConstant() |
| 5268 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5269 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5270 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5271 | if (!value.IsRegister()) { |
| 5272 | // Just setting null. |
| 5273 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5274 | DCHECK(value.IsConstant()) << value; |
| 5275 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5276 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5277 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5278 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5279 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5280 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5281 | |
| 5282 | DCHECK(needs_write_barrier); |
| 5283 | Register register_value = value.AsRegister<Register>(); |
| 5284 | NearLabel done, not_null, do_put; |
| 5285 | SlowPathCode* slow_path = nullptr; |
| 5286 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5287 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5288 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5289 | codegen_->AddSlowPath(slow_path); |
| 5290 | if (instruction->GetValueCanBeNull()) { |
| 5291 | __ testl(register_value, register_value); |
| 5292 | __ j(kNotEqual, ¬_null); |
| 5293 | __ movl(address, Immediate(0)); |
| 5294 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5295 | __ jmp(&done); |
| 5296 | __ Bind(¬_null); |
| 5297 | } |
| 5298 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5299 | if (kEmitCompilerReadBarrier) { |
| 5300 | // When read barriers are enabled, the type checking |
| 5301 | // instrumentation requires two read barriers: |
| 5302 | // |
| 5303 | // __ movl(temp2, temp); |
| 5304 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5305 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5306 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5307 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5308 | // |
| 5309 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5310 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5311 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5312 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5313 | // |
| 5314 | // __ cmpl(temp, temp2); |
| 5315 | // |
| 5316 | // However, the second read barrier may trash `temp`, as it |
| 5317 | // is a temporary register, and as such would not be saved |
| 5318 | // along with live registers before calling the runtime (nor |
| 5319 | // restored afterwards). So in this case, we bail out and |
| 5320 | // delegate the work to the array set slow path. |
| 5321 | // |
| 5322 | // TODO: Extend the register allocator to support a new |
| 5323 | // "(locally) live temp" location so as to avoid always |
| 5324 | // going into the slow path when read barriers are enabled. |
| 5325 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5326 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5327 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5328 | __ movl(temp, Address(array, class_offset)); |
| 5329 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5330 | __ MaybeUnpoisonHeapReference(temp); |
| 5331 | |
| 5332 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5333 | __ movl(temp, Address(temp, component_offset)); |
| 5334 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5335 | // nor the object reference in `register_value->klass`, as |
| 5336 | // we are comparing two poisoned references. |
| 5337 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5338 | |
| 5339 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5340 | __ j(kEqual, &do_put); |
| 5341 | // If heap poisoning is enabled, the `temp` reference has |
| 5342 | // not been unpoisoned yet; unpoison it now. |
| 5343 | __ MaybeUnpoisonHeapReference(temp); |
| 5344 | |
| 5345 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5346 | __ movl(temp, Address(temp, super_offset)); |
| 5347 | // If heap poisoning is enabled, no need to unpoison |
| 5348 | // `temp`, as we are comparing against null below. |
| 5349 | __ testl(temp, temp); |
| 5350 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5351 | __ Bind(&do_put); |
| 5352 | } else { |
| 5353 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5354 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5355 | } |
| 5356 | } |
| 5357 | |
| 5358 | if (kPoisonHeapReferences) { |
| 5359 | __ movl(temp, register_value); |
| 5360 | __ PoisonHeapReference(temp); |
| 5361 | __ movl(address, temp); |
| 5362 | } else { |
| 5363 | __ movl(address, register_value); |
| 5364 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5365 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5366 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5367 | } |
| 5368 | |
| 5369 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5370 | codegen_->MarkGCCard( |
| 5371 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5372 | __ Bind(&done); |
| 5373 | |
| 5374 | if (slow_path != nullptr) { |
| 5375 | __ Bind(slow_path->GetExitLabel()); |
| 5376 | } |
| 5377 | |
| 5378 | break; |
| 5379 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5380 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5381 | case Primitive::kPrimInt: { |
| 5382 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5383 | Address address = index.IsConstant() |
| 5384 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5385 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5386 | if (value.IsRegister()) { |
| 5387 | __ movl(address, value.AsRegister<Register>()); |
| 5388 | } else { |
| 5389 | DCHECK(value.IsConstant()) << value; |
| 5390 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5391 | __ movl(address, Immediate(v)); |
| 5392 | } |
| 5393 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5394 | break; |
| 5395 | } |
| 5396 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5397 | case Primitive::kPrimLong: { |
| 5398 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5399 | if (index.IsConstant()) { |
| 5400 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5401 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5402 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5403 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5404 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5405 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5406 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5407 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5408 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5409 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5410 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5411 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5412 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5413 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5414 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5415 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5416 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5417 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5418 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5419 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5420 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5421 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5422 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5423 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5424 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5425 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5426 | Immediate(High32Bits(val))); |
| 5427 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5428 | } |
| 5429 | break; |
| 5430 | } |
| 5431 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5432 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5433 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5434 | Address address = index.IsConstant() |
| 5435 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5436 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5437 | if (value.IsFpuRegister()) { |
| 5438 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5439 | } else { |
| 5440 | DCHECK(value.IsConstant()); |
| 5441 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5442 | __ movl(address, Immediate(v)); |
| 5443 | } |
| 5444 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5445 | break; |
| 5446 | } |
| 5447 | |
| 5448 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5449 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5450 | Address address = index.IsConstant() |
| 5451 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5452 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5453 | if (value.IsFpuRegister()) { |
| 5454 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5455 | } else { |
| 5456 | DCHECK(value.IsConstant()); |
| 5457 | Address address_hi = index.IsConstant() ? |
| 5458 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5459 | offset + kX86WordSize) : |
| 5460 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5461 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5462 | __ movl(address, Immediate(Low32Bits(v))); |
| 5463 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5464 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5465 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5466 | break; |
| 5467 | } |
| 5468 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5469 | case Primitive::kPrimVoid: |
| 5470 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5471 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5472 | } |
| 5473 | } |
| 5474 | |
| 5475 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5477 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5478 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5482 | LocationSummary* locations = instruction->GetLocations(); |
| 5483 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5484 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5485 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5486 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5487 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5491 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5492 | ? LocationSummary::kCallOnSlowPath |
| 5493 | : LocationSummary::kNoCall; |
| 5494 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5495 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5496 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5497 | if (instruction->HasUses()) { |
| 5498 | locations->SetOut(Location::SameAsFirstInput()); |
| 5499 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5503 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5504 | Location index_loc = locations->InAt(0); |
| 5505 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5506 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5507 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5508 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5509 | if (length_loc.IsConstant()) { |
| 5510 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5511 | if (index_loc.IsConstant()) { |
| 5512 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5513 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5514 | if (index < 0 || index >= length) { |
| 5515 | codegen_->AddSlowPath(slow_path); |
| 5516 | __ jmp(slow_path->GetEntryLabel()); |
| 5517 | } else { |
| 5518 | // Some optimization after BCE may have generated this, and we should not |
| 5519 | // generate a bounds check if it is a valid range. |
| 5520 | } |
| 5521 | return; |
| 5522 | } |
| 5523 | |
| 5524 | // We have to reverse the jump condition because the length is the constant. |
| 5525 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5526 | __ cmpl(index_reg, Immediate(length)); |
| 5527 | codegen_->AddSlowPath(slow_path); |
| 5528 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5529 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5530 | Register length = length_loc.AsRegister<Register>(); |
| 5531 | if (index_loc.IsConstant()) { |
| 5532 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5533 | __ cmpl(length, Immediate(value)); |
| 5534 | } else { |
| 5535 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5536 | } |
| 5537 | codegen_->AddSlowPath(slow_path); |
| 5538 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5539 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5540 | } |
| 5541 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5542 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5543 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5547 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5548 | } |
| 5549 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5550 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5551 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5552 | } |
| 5553 | |
| 5554 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5555 | HBasicBlock* block = instruction->GetBlock(); |
| 5556 | if (block->GetLoopInformation() != nullptr) { |
| 5557 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5558 | // The back edge will generate the suspend check. |
| 5559 | return; |
| 5560 | } |
| 5561 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5562 | // The goto will generate the suspend check. |
| 5563 | return; |
| 5564 | } |
| 5565 | GenerateSuspendCheck(instruction, nullptr); |
| 5566 | } |
| 5567 | |
| 5568 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5569 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5570 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5571 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5572 | if (slow_path == nullptr) { |
| 5573 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5574 | instruction->SetSlowPath(slow_path); |
| 5575 | codegen_->AddSlowPath(slow_path); |
| 5576 | if (successor != nullptr) { |
| 5577 | DCHECK(successor->IsLoopHeader()); |
| 5578 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5579 | } |
| 5580 | } else { |
| 5581 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5582 | } |
| 5583 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5584 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5585 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5586 | if (successor == nullptr) { |
| 5587 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5588 | __ Bind(slow_path->GetReturnLabel()); |
| 5589 | } else { |
| 5590 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5591 | __ jmp(slow_path->GetEntryLabel()); |
| 5592 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5593 | } |
| 5594 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5595 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5596 | return codegen_->GetAssembler(); |
| 5597 | } |
| 5598 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5599 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5600 | ScratchRegisterScope ensure_scratch( |
| 5601 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5602 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5603 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5604 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5605 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5606 | } |
| 5607 | |
| 5608 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5609 | ScratchRegisterScope ensure_scratch( |
| 5610 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5611 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5612 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5613 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5614 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5615 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5616 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5620 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5621 | Location source = move->GetSource(); |
| 5622 | Location destination = move->GetDestination(); |
| 5623 | |
| 5624 | if (source.IsRegister()) { |
| 5625 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5626 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5627 | } else if (destination.IsFpuRegister()) { |
| 5628 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5629 | } else { |
| 5630 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5631 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5632 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5633 | } else if (source.IsRegisterPair()) { |
| 5634 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5635 | // Create stack space for 2 elements. |
| 5636 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5637 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5638 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5639 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5640 | // And remove the temporary stack space we allocated. |
| 5641 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5642 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5643 | if (destination.IsRegister()) { |
| 5644 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5645 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5646 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5647 | } else if (destination.IsRegisterPair()) { |
| 5648 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5649 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5650 | __ psrlq(src_reg, Immediate(32)); |
| 5651 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5652 | } else if (destination.IsStackSlot()) { |
| 5653 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5654 | } else { |
| 5655 | DCHECK(destination.IsDoubleStackSlot()); |
| 5656 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5657 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5658 | } else if (source.IsStackSlot()) { |
| 5659 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5660 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5661 | } else if (destination.IsFpuRegister()) { |
| 5662 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5663 | } else { |
| 5664 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5665 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5666 | } |
| 5667 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5668 | if (destination.IsRegisterPair()) { |
| 5669 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5670 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5671 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5672 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5673 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5674 | } else { |
| 5675 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5676 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5677 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5678 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5679 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5680 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5681 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5682 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5683 | if (value == 0) { |
| 5684 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5685 | } else { |
| 5686 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5687 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5688 | } else { |
| 5689 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5690 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5691 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5692 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5693 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5694 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5695 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5696 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5697 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5698 | if (value == 0) { |
| 5699 | // Easy handling of 0.0. |
| 5700 | __ xorps(dest, dest); |
| 5701 | } else { |
| 5702 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5703 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5704 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5705 | __ movl(temp, Immediate(value)); |
| 5706 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5707 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5708 | } else { |
| 5709 | DCHECK(destination.IsStackSlot()) << destination; |
| 5710 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5711 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5712 | } else if (constant->IsLongConstant()) { |
| 5713 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5714 | int32_t low_value = Low32Bits(value); |
| 5715 | int32_t high_value = High32Bits(value); |
| 5716 | Immediate low(low_value); |
| 5717 | Immediate high(high_value); |
| 5718 | if (destination.IsDoubleStackSlot()) { |
| 5719 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5720 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5721 | } else { |
| 5722 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5723 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5724 | } |
| 5725 | } else { |
| 5726 | DCHECK(constant->IsDoubleConstant()); |
| 5727 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5728 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5729 | int32_t low_value = Low32Bits(value); |
| 5730 | int32_t high_value = High32Bits(value); |
| 5731 | Immediate low(low_value); |
| 5732 | Immediate high(high_value); |
| 5733 | if (destination.IsFpuRegister()) { |
| 5734 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5735 | if (value == 0) { |
| 5736 | // Easy handling of 0.0. |
| 5737 | __ xorpd(dest, dest); |
| 5738 | } else { |
| 5739 | __ pushl(high); |
| 5740 | __ pushl(low); |
| 5741 | __ movsd(dest, Address(ESP, 0)); |
| 5742 | __ addl(ESP, Immediate(8)); |
| 5743 | } |
| 5744 | } else { |
| 5745 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5746 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5747 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5748 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5749 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5750 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5751 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5752 | } |
| 5753 | } |
| 5754 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5755 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5756 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5757 | ScratchRegisterScope ensure_scratch( |
| 5758 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5759 | |
| 5760 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5761 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5762 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5763 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5764 | } |
| 5765 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5766 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5767 | ScratchRegisterScope ensure_scratch( |
| 5768 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5769 | |
| 5770 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5771 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5772 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5773 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5774 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5775 | } |
| 5776 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5777 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5778 | ScratchRegisterScope ensure_scratch1( |
| 5779 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5780 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5781 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5782 | ScratchRegisterScope ensure_scratch2( |
| 5783 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5784 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5785 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5786 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5787 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5788 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5789 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5790 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5794 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5795 | Location source = move->GetSource(); |
| 5796 | Location destination = move->GetDestination(); |
| 5797 | |
| 5798 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5799 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5800 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5801 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5802 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5803 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5804 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5805 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5806 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5807 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5808 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5809 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5810 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5811 | // Use XOR Swap algorithm to avoid a temporary. |
| 5812 | DCHECK_NE(source.reg(), destination.reg()); |
| 5813 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5814 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5815 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5816 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5817 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5818 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5819 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5820 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5821 | // Take advantage of the 16 bytes in the XMM register. |
| 5822 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5823 | Address stack(ESP, destination.GetStackIndex()); |
| 5824 | // Load the double into the high doubleword. |
| 5825 | __ movhpd(reg, stack); |
| 5826 | |
| 5827 | // Store the low double into the destination. |
| 5828 | __ movsd(stack, reg); |
| 5829 | |
| 5830 | // Move the high double to the low double. |
| 5831 | __ psrldq(reg, Immediate(8)); |
| 5832 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5833 | // Take advantage of the 16 bytes in the XMM register. |
| 5834 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5835 | Address stack(ESP, source.GetStackIndex()); |
| 5836 | // Load the double into the high doubleword. |
| 5837 | __ movhpd(reg, stack); |
| 5838 | |
| 5839 | // Store the low double into the destination. |
| 5840 | __ movsd(stack, reg); |
| 5841 | |
| 5842 | // Move the high double to the low double. |
| 5843 | __ psrldq(reg, Immediate(8)); |
| 5844 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5845 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5846 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5847 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5848 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5849 | } |
| 5850 | } |
| 5851 | |
| 5852 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5853 | __ pushl(static_cast<Register>(reg)); |
| 5854 | } |
| 5855 | |
| 5856 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5857 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5858 | } |
| 5859 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5860 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5861 | InvokeRuntimeCallingConvention calling_convention; |
| 5862 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5863 | cls, |
| 5864 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5865 | Location::RegisterLocation(EAX), |
| 5866 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5870 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5871 | if (cls->NeedsAccessCheck()) { |
| 5872 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5873 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5874 | cls, |
| 5875 | cls->GetDexPc(), |
| 5876 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5877 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5878 | return; |
| 5879 | } |
| 5880 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5881 | Location out_loc = locations->Out(); |
| 5882 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5883 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5884 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5885 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5886 | DCHECK(!cls->CanCallRuntime()); |
| 5887 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5888 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5889 | GenerateGcRootFieldLoad( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5890 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5891 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5892 | // /* GcRoot<mirror::Class>[] */ out = |
| 5893 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5894 | __ movl(out, Address(current_method, |
| 5895 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5896 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5897 | GenerateGcRootFieldLoad( |
| 5898 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5899 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5900 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5901 | DCHECK(cls->CanCallRuntime()); |
| 5902 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5903 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5904 | codegen_->AddSlowPath(slow_path); |
| 5905 | |
| 5906 | if (!cls->IsInDexCache()) { |
| 5907 | __ testl(out, out); |
| 5908 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5909 | } |
| 5910 | |
| 5911 | if (cls->MustGenerateClinitCheck()) { |
| 5912 | GenerateClassInitializationCheck(slow_path, out); |
| 5913 | } else { |
| 5914 | __ Bind(slow_path->GetExitLabel()); |
| 5915 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5916 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5917 | } |
| 5918 | } |
| 5919 | |
| 5920 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5921 | LocationSummary* locations = |
| 5922 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5924 | if (check->HasUses()) { |
| 5925 | locations->SetOut(Location::SameAsFirstInput()); |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5930 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5931 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5932 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5933 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5934 | GenerateClassInitializationCheck(slow_path, |
| 5935 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5936 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5937 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5938 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5939 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5940 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5941 | Immediate(mirror::Class::kStatusInitialized)); |
| 5942 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5943 | __ Bind(slow_path->GetExitLabel()); |
| 5944 | // No need for memory fence, thanks to the X86 memory model. |
| 5945 | } |
| 5946 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5947 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 5948 | HLoadString::LoadKind desired_string_load_kind) { |
| 5949 | if (kEmitCompilerReadBarrier) { |
| 5950 | switch (desired_string_load_kind) { |
| 5951 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5952 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5953 | case HLoadString::LoadKind::kBootImageAddress: |
| 5954 | // TODO: Implement for read barrier. |
| 5955 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5956 | default: |
| 5957 | break; |
| 5958 | } |
| 5959 | } |
| 5960 | switch (desired_string_load_kind) { |
| 5961 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5962 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5963 | break; |
| 5964 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5965 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5966 | FALLTHROUGH_INTENDED; |
| 5967 | case HLoadString::LoadKind::kDexCachePcRelative: |
| 5968 | DCHECK(!Runtime::Current()->UseJit()); // Note: boot image is also non-JIT. |
| 5969 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5970 | // is incompatible with it. |
| 5971 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5972 | // with irreducible loops. |
| 5973 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5974 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5975 | } |
| 5976 | break; |
| 5977 | case HLoadString::LoadKind::kBootImageAddress: |
| 5978 | break; |
| 5979 | case HLoadString::LoadKind::kDexCacheAddress: |
| 5980 | DCHECK(Runtime::Current()->UseJit()); |
| 5981 | break; |
| 5982 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5983 | break; |
| 5984 | } |
| 5985 | return desired_string_load_kind; |
| 5986 | } |
| 5987 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5988 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5989 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5990 | ? LocationSummary::kCallOnSlowPath |
| 5991 | : LocationSummary::kNoCall; |
| 5992 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5993 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 5994 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 5995 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 5996 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 5997 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5998 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5999 | locations->SetOut(Location::RequiresRegister()); |
| 6000 | } |
| 6001 | |
| 6002 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6003 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6004 | Location out_loc = locations->Out(); |
| 6005 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6006 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6007 | switch (load->GetLoadKind()) { |
| 6008 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6009 | DCHECK(!kEmitCompilerReadBarrier); |
| 6010 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6011 | codegen_->RecordStringPatch(load); |
| 6012 | return; // No dex cache slow path. |
| 6013 | } |
| 6014 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6015 | DCHECK(!kEmitCompilerReadBarrier); |
| 6016 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6017 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6018 | codegen_->RecordStringPatch(load); |
| 6019 | return; // No dex cache slow path. |
| 6020 | } |
| 6021 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6022 | DCHECK(!kEmitCompilerReadBarrier); |
| 6023 | DCHECK_NE(load->GetAddress(), 0u); |
| 6024 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6025 | __ movl(out, Immediate(address)); |
| 6026 | codegen_->RecordSimplePatch(); |
| 6027 | return; // No dex cache slow path. |
| 6028 | } |
| 6029 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 6030 | DCHECK_NE(load->GetAddress(), 0u); |
| 6031 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6032 | GenerateGcRootFieldLoad(load, out_loc, Address::Absolute(address)); |
| 6033 | break; |
| 6034 | } |
| 6035 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 6036 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6037 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 6038 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
| 6039 | GenerateGcRootFieldLoad( |
| 6040 | load, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6041 | break; |
| 6042 | } |
| 6043 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 6044 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6045 | |
| 6046 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6047 | GenerateGcRootFieldLoad( |
| 6048 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6049 | |
| 6050 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 6051 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
| 6052 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 6053 | GenerateGcRootFieldLoad( |
| 6054 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 6055 | break; |
| 6056 | } |
| 6057 | default: |
| 6058 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 6059 | UNREACHABLE(); |
| 6060 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6061 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6062 | if (!load->IsInDexCache()) { |
| 6063 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6064 | codegen_->AddSlowPath(slow_path); |
| 6065 | __ testl(out, out); |
| 6066 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6067 | __ Bind(slow_path->GetExitLabel()); |
| 6068 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6069 | } |
| 6070 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6071 | static Address GetExceptionTlsAddress() { |
| 6072 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6073 | } |
| 6074 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6075 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6076 | LocationSummary* locations = |
| 6077 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6078 | locations->SetOut(Location::RequiresRegister()); |
| 6079 | } |
| 6080 | |
| 6081 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6082 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6083 | } |
| 6084 | |
| 6085 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6086 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6087 | } |
| 6088 | |
| 6089 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6090 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6094 | LocationSummary* locations = |
| 6095 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6096 | InvokeRuntimeCallingConvention calling_convention; |
| 6097 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6098 | } |
| 6099 | |
| 6100 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6101 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6102 | instruction, |
| 6103 | instruction->GetDexPc(), |
| 6104 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6105 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6106 | } |
| 6107 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6108 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6109 | return kEmitCompilerReadBarrier && |
| 6110 | (kUseBakerReadBarrier || |
| 6111 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6112 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6113 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6114 | } |
| 6115 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6116 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6117 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6118 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6119 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6120 | case TypeCheckKind::kExactCheck: |
| 6121 | case TypeCheckKind::kAbstractClassCheck: |
| 6122 | case TypeCheckKind::kClassHierarchyCheck: |
| 6123 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6124 | call_kind = |
| 6125 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6126 | break; |
| 6127 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6128 | case TypeCheckKind::kUnresolvedCheck: |
| 6129 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6130 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6131 | break; |
| 6132 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6133 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6134 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6135 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6136 | locations->SetInAt(1, Location::Any()); |
| 6137 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6138 | locations->SetOut(Location::RequiresRegister()); |
| 6139 | // When read barriers are enabled, we need a temporary register for |
| 6140 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6141 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6142 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6143 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6144 | } |
| 6145 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6146 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6147 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6148 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6149 | Location obj_loc = locations->InAt(0); |
| 6150 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6151 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6152 | Location out_loc = locations->Out(); |
| 6153 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6154 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6155 | locations->GetTemp(0) : |
| 6156 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6157 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6159 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6160 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6161 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6162 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6163 | |
| 6164 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6165 | // Avoid null check if we know obj is not null. |
| 6166 | if (instruction->MustDoNullCheck()) { |
| 6167 | __ testl(obj, obj); |
| 6168 | __ j(kEqual, &zero); |
| 6169 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6170 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6171 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6172 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6173 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6174 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6175 | case TypeCheckKind::kExactCheck: { |
| 6176 | if (cls.IsRegister()) { |
| 6177 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6178 | } else { |
| 6179 | DCHECK(cls.IsStackSlot()) << cls; |
| 6180 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6181 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6182 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | // Classes must be equal for the instanceof to succeed. |
| 6184 | __ j(kNotEqual, &zero); |
| 6185 | __ movl(out, Immediate(1)); |
| 6186 | __ jmp(&done); |
| 6187 | break; |
| 6188 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6189 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 | case TypeCheckKind::kAbstractClassCheck: { |
| 6191 | // If the class is abstract, we eagerly fetch the super class of the |
| 6192 | // object to avoid doing a comparison we know will fail. |
| 6193 | NearLabel loop; |
| 6194 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6195 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6196 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6197 | __ testl(out, out); |
| 6198 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6199 | __ j(kEqual, &done); |
| 6200 | if (cls.IsRegister()) { |
| 6201 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6202 | } else { |
| 6203 | DCHECK(cls.IsStackSlot()) << cls; |
| 6204 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6205 | } |
| 6206 | __ j(kNotEqual, &loop); |
| 6207 | __ movl(out, Immediate(1)); |
| 6208 | if (zero.IsLinked()) { |
| 6209 | __ jmp(&done); |
| 6210 | } |
| 6211 | break; |
| 6212 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6213 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6214 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6215 | // Walk over the class hierarchy to find a match. |
| 6216 | NearLabel loop, success; |
| 6217 | __ Bind(&loop); |
| 6218 | if (cls.IsRegister()) { |
| 6219 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6220 | } else { |
| 6221 | DCHECK(cls.IsStackSlot()) << cls; |
| 6222 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6223 | } |
| 6224 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6225 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6226 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6227 | __ testl(out, out); |
| 6228 | __ j(kNotEqual, &loop); |
| 6229 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6230 | __ jmp(&done); |
| 6231 | __ Bind(&success); |
| 6232 | __ movl(out, Immediate(1)); |
| 6233 | if (zero.IsLinked()) { |
| 6234 | __ jmp(&done); |
| 6235 | } |
| 6236 | break; |
| 6237 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6238 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6240 | // Do an exact check. |
| 6241 | NearLabel exact_check; |
| 6242 | if (cls.IsRegister()) { |
| 6243 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6244 | } else { |
| 6245 | DCHECK(cls.IsStackSlot()) << cls; |
| 6246 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6247 | } |
| 6248 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6249 | // 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] | 6250 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6251 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6252 | __ testl(out, out); |
| 6253 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6254 | __ j(kEqual, &done); |
| 6255 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6256 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6257 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6258 | __ movl(out, Immediate(1)); |
| 6259 | __ jmp(&done); |
| 6260 | break; |
| 6261 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6262 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6263 | case TypeCheckKind::kArrayCheck: { |
| 6264 | if (cls.IsRegister()) { |
| 6265 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6266 | } else { |
| 6267 | DCHECK(cls.IsStackSlot()) << cls; |
| 6268 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6269 | } |
| 6270 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6272 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6273 | codegen_->AddSlowPath(slow_path); |
| 6274 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6275 | __ movl(out, Immediate(1)); |
| 6276 | if (zero.IsLinked()) { |
| 6277 | __ jmp(&done); |
| 6278 | } |
| 6279 | break; |
| 6280 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6282 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6283 | case TypeCheckKind::kInterfaceCheck: { |
| 6284 | // 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] | 6285 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6286 | // cases. |
| 6287 | // |
| 6288 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6289 | // entry point without resorting to a type checking slow path |
| 6290 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6291 | // require to assign fixed registers for the inputs of this |
| 6292 | // HInstanceOf instruction (following the runtime calling |
| 6293 | // convention), which might be cluttered by the potential first |
| 6294 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6295 | // |
| 6296 | // TODO: Introduce a new runtime entry point taking the object |
| 6297 | // to test (instead of its class) as argument, and let it deal |
| 6298 | // with the read barrier issues. This will let us refactor this |
| 6299 | // case of the `switch` code as it was previously (with a direct |
| 6300 | // call to the runtime not using a type checking slow path). |
| 6301 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6302 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6303 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6304 | /* is_fatal */ false); |
| 6305 | codegen_->AddSlowPath(slow_path); |
| 6306 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6307 | if (zero.IsLinked()) { |
| 6308 | __ jmp(&done); |
| 6309 | } |
| 6310 | break; |
| 6311 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6314 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6315 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6316 | __ xorl(out, out); |
| 6317 | } |
| 6318 | |
| 6319 | if (done.IsLinked()) { |
| 6320 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6321 | } |
| 6322 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6323 | if (slow_path != nullptr) { |
| 6324 | __ Bind(slow_path->GetExitLabel()); |
| 6325 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6328 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6329 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6330 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6331 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6332 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6333 | case TypeCheckKind::kExactCheck: |
| 6334 | case TypeCheckKind::kAbstractClassCheck: |
| 6335 | case TypeCheckKind::kClassHierarchyCheck: |
| 6336 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6337 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6338 | LocationSummary::kCallOnSlowPath : |
| 6339 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6340 | break; |
| 6341 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6342 | case TypeCheckKind::kUnresolvedCheck: |
| 6343 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6344 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6345 | break; |
| 6346 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6347 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6349 | locations->SetInAt(1, Location::Any()); |
| 6350 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6351 | locations->AddTemp(Location::RequiresRegister()); |
| 6352 | // When read barriers are enabled, we need an additional temporary |
| 6353 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6354 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6355 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6356 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6360 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6361 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6362 | Location obj_loc = locations->InAt(0); |
| 6363 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6364 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6365 | Location temp_loc = locations->GetTemp(0); |
| 6366 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6367 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6368 | locations->GetTemp(1) : |
| 6369 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6370 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6371 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6372 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6373 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6374 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6375 | bool is_type_check_slow_path_fatal = |
| 6376 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6377 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6378 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6379 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6380 | !instruction->CanThrowIntoCatchBlock(); |
| 6381 | SlowPathCode* type_check_slow_path = |
| 6382 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6383 | is_type_check_slow_path_fatal); |
| 6384 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6385 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6386 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6387 | // Avoid null check if we know obj is not null. |
| 6388 | if (instruction->MustDoNullCheck()) { |
| 6389 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6390 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6391 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6392 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6393 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6394 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6395 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6396 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6397 | case TypeCheckKind::kExactCheck: |
| 6398 | case TypeCheckKind::kArrayCheck: { |
| 6399 | if (cls.IsRegister()) { |
| 6400 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6401 | } else { |
| 6402 | DCHECK(cls.IsStackSlot()) << cls; |
| 6403 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6404 | } |
| 6405 | // Jump to slow path for throwing the exception or doing a |
| 6406 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6407 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6408 | break; |
| 6409 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6410 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6411 | case TypeCheckKind::kAbstractClassCheck: { |
| 6412 | // If the class is abstract, we eagerly fetch the super class of the |
| 6413 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6414 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6415 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6416 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6417 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6418 | |
| 6419 | // If the class reference currently in `temp` is not null, jump |
| 6420 | // to the `compare_classes` label to compare it with the checked |
| 6421 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6422 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | __ j(kNotEqual, &compare_classes); |
| 6424 | // Otherwise, jump to the slow path to throw the exception. |
| 6425 | // |
| 6426 | // But before, move back the object's class into `temp` before |
| 6427 | // going into the slow path, as it has been overwritten in the |
| 6428 | // meantime. |
| 6429 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6430 | GenerateReferenceLoadTwoRegisters( |
| 6431 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6432 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6433 | |
| 6434 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6435 | if (cls.IsRegister()) { |
| 6436 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6437 | } else { |
| 6438 | DCHECK(cls.IsStackSlot()) << cls; |
| 6439 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6440 | } |
| 6441 | __ j(kNotEqual, &loop); |
| 6442 | break; |
| 6443 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6444 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6445 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6446 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6447 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6448 | __ Bind(&loop); |
| 6449 | if (cls.IsRegister()) { |
| 6450 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6451 | } else { |
| 6452 | DCHECK(cls.IsStackSlot()) << cls; |
| 6453 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6454 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6455 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6456 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6457 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6458 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6459 | |
| 6460 | // If the class reference currently in `temp` is not null, jump |
| 6461 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6462 | __ testl(temp, temp); |
| 6463 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6464 | // Otherwise, jump to the slow path to throw the exception. |
| 6465 | // |
| 6466 | // But before, move back the object's class into `temp` before |
| 6467 | // going into the slow path, as it has been overwritten in the |
| 6468 | // meantime. |
| 6469 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6470 | GenerateReferenceLoadTwoRegisters( |
| 6471 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6472 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6473 | break; |
| 6474 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6476 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6477 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6478 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6479 | if (cls.IsRegister()) { |
| 6480 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6481 | } else { |
| 6482 | DCHECK(cls.IsStackSlot()) << cls; |
| 6483 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6484 | } |
| 6485 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6486 | |
| 6487 | // 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] | 6488 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6489 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6490 | |
| 6491 | // If the component type is not null (i.e. the object is indeed |
| 6492 | // an array), jump to label `check_non_primitive_component_type` |
| 6493 | // to further check that this component type is not a primitive |
| 6494 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6495 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6496 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6497 | // Otherwise, jump to the slow path to throw the exception. |
| 6498 | // |
| 6499 | // But before, move back the object's class into `temp` before |
| 6500 | // going into the slow path, as it has been overwritten in the |
| 6501 | // meantime. |
| 6502 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6503 | GenerateReferenceLoadTwoRegisters( |
| 6504 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6505 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6506 | |
| 6507 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6508 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6509 | __ j(kEqual, &done); |
| 6510 | // Same comment as above regarding `temp` and the slow path. |
| 6511 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6512 | GenerateReferenceLoadTwoRegisters( |
| 6513 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6514 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6515 | break; |
| 6516 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6517 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6518 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6519 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6520 | // We always go into the type check slow path for the unresolved |
| 6521 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6522 | // |
| 6523 | // We cannot directly call the CheckCast runtime entry point |
| 6524 | // without resorting to a type checking slow path here (i.e. by |
| 6525 | // calling InvokeRuntime directly), as it would require to |
| 6526 | // assign fixed registers for the inputs of this HInstanceOf |
| 6527 | // instruction (following the runtime calling convention), which |
| 6528 | // might be cluttered by the potential first read barrier |
| 6529 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6530 | // |
| 6531 | // TODO: Introduce a new runtime entry point taking the object |
| 6532 | // to test (instead of its class) as argument, and let it deal |
| 6533 | // with the read barrier issues. This will let us refactor this |
| 6534 | // case of the `switch` code as it was previously (with a direct |
| 6535 | // call to the runtime not using a type checking slow path). |
| 6536 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6537 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6538 | break; |
| 6539 | } |
| 6540 | __ Bind(&done); |
| 6541 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6542 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6543 | } |
| 6544 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6545 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6546 | LocationSummary* locations = |
| 6547 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6548 | InvokeRuntimeCallingConvention calling_convention; |
| 6549 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6550 | } |
| 6551 | |
| 6552 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6553 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6554 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6555 | instruction, |
| 6556 | instruction->GetDexPc(), |
| 6557 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6558 | if (instruction->IsEnter()) { |
| 6559 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6560 | } else { |
| 6561 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6562 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6563 | } |
| 6564 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6565 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6566 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6567 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6568 | |
| 6569 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6570 | LocationSummary* locations = |
| 6571 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6572 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6573 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6574 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6575 | locations->SetInAt(1, Location::Any()); |
| 6576 | locations->SetOut(Location::SameAsFirstInput()); |
| 6577 | } |
| 6578 | |
| 6579 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6580 | HandleBitwiseOperation(instruction); |
| 6581 | } |
| 6582 | |
| 6583 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6584 | HandleBitwiseOperation(instruction); |
| 6585 | } |
| 6586 | |
| 6587 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6588 | HandleBitwiseOperation(instruction); |
| 6589 | } |
| 6590 | |
| 6591 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6592 | LocationSummary* locations = instruction->GetLocations(); |
| 6593 | Location first = locations->InAt(0); |
| 6594 | Location second = locations->InAt(1); |
| 6595 | DCHECK(first.Equals(locations->Out())); |
| 6596 | |
| 6597 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6598 | if (second.IsRegister()) { |
| 6599 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6600 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6601 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6602 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6603 | } else { |
| 6604 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6605 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6606 | } |
| 6607 | } else if (second.IsConstant()) { |
| 6608 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6609 | __ andl(first.AsRegister<Register>(), |
| 6610 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6611 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6612 | __ orl(first.AsRegister<Register>(), |
| 6613 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6614 | } else { |
| 6615 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6616 | __ xorl(first.AsRegister<Register>(), |
| 6617 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6618 | } |
| 6619 | } else { |
| 6620 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6621 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6622 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6623 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6624 | } else { |
| 6625 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6626 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6627 | } |
| 6628 | } |
| 6629 | } else { |
| 6630 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6631 | if (second.IsRegisterPair()) { |
| 6632 | if (instruction->IsAnd()) { |
| 6633 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6634 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6635 | } else if (instruction->IsOr()) { |
| 6636 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6637 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6638 | } else { |
| 6639 | DCHECK(instruction->IsXor()); |
| 6640 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6641 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6642 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6643 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6644 | if (instruction->IsAnd()) { |
| 6645 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6646 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6647 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6648 | } else if (instruction->IsOr()) { |
| 6649 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6650 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6651 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6652 | } else { |
| 6653 | DCHECK(instruction->IsXor()); |
| 6654 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6655 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6656 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6657 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6658 | } else { |
| 6659 | DCHECK(second.IsConstant()) << second; |
| 6660 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6661 | int32_t low_value = Low32Bits(value); |
| 6662 | int32_t high_value = High32Bits(value); |
| 6663 | Immediate low(low_value); |
| 6664 | Immediate high(high_value); |
| 6665 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6666 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6667 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6668 | if (low_value == 0) { |
| 6669 | __ xorl(first_low, first_low); |
| 6670 | } else if (low_value != -1) { |
| 6671 | __ andl(first_low, low); |
| 6672 | } |
| 6673 | if (high_value == 0) { |
| 6674 | __ xorl(first_high, first_high); |
| 6675 | } else if (high_value != -1) { |
| 6676 | __ andl(first_high, high); |
| 6677 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6678 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6679 | if (low_value != 0) { |
| 6680 | __ orl(first_low, low); |
| 6681 | } |
| 6682 | if (high_value != 0) { |
| 6683 | __ orl(first_high, high); |
| 6684 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6685 | } else { |
| 6686 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6687 | if (low_value != 0) { |
| 6688 | __ xorl(first_low, low); |
| 6689 | } |
| 6690 | if (high_value != 0) { |
| 6691 | __ xorl(first_high, high); |
| 6692 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6693 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6694 | } |
| 6695 | } |
| 6696 | } |
| 6697 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6698 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6699 | Location out, |
| 6700 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6701 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6702 | Register out_reg = out.AsRegister<Register>(); |
| 6703 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6704 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6705 | if (kUseBakerReadBarrier) { |
| 6706 | // Load with fast path based Baker's read barrier. |
| 6707 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6708 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6709 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6710 | } else { |
| 6711 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6712 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6713 | // in the following move operation, as we will need it for the |
| 6714 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6715 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6716 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6717 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6718 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6719 | } |
| 6720 | } else { |
| 6721 | // Plain load with no read barrier. |
| 6722 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6723 | __ movl(out_reg, Address(out_reg, offset)); |
| 6724 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6729 | Location out, |
| 6730 | Location obj, |
| 6731 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6732 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6733 | Register out_reg = out.AsRegister<Register>(); |
| 6734 | Register obj_reg = obj.AsRegister<Register>(); |
| 6735 | if (kEmitCompilerReadBarrier) { |
| 6736 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6737 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6738 | // Load with fast path based Baker's read barrier. |
| 6739 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6740 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6741 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6742 | } else { |
| 6743 | // Load with slow path based read barrier. |
| 6744 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6745 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6746 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6747 | } |
| 6748 | } else { |
| 6749 | // Plain load with no read barrier. |
| 6750 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6751 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6752 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6757 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6758 | const Address& address, |
| 6759 | Label* fixup_label) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6760 | Register root_reg = root.AsRegister<Register>(); |
| 6761 | if (kEmitCompilerReadBarrier) { |
| 6762 | if (kUseBakerReadBarrier) { |
| 6763 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6764 | // Baker's read barrier are used: |
| 6765 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6766 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6767 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6768 | // root = ReadBarrier::Mark(root) |
| 6769 | // } |
| 6770 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6771 | // /* GcRoot<mirror::Object> */ root = *address |
| 6772 | __ movl(root_reg, address); |
| 6773 | if (fixup_label != nullptr) { |
| 6774 | __ Bind(fixup_label); |
| 6775 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6776 | static_assert( |
| 6777 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6778 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6779 | "have different sizes."); |
| 6780 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6781 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6782 | "have different sizes."); |
| 6783 | |
| 6784 | // Slow path used to mark the GC root `root`. |
| 6785 | SlowPathCode* slow_path = |
| 6786 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6787 | codegen_->AddSlowPath(slow_path); |
| 6788 | |
| 6789 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6790 | Immediate(0)); |
| 6791 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6792 | __ Bind(slow_path->GetExitLabel()); |
| 6793 | } else { |
| 6794 | // GC root loaded through a slow path for read barriers other |
| 6795 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6796 | // /* GcRoot<mirror::Object>* */ root = address |
| 6797 | __ leal(root_reg, address); |
| 6798 | if (fixup_label != nullptr) { |
| 6799 | __ Bind(fixup_label); |
| 6800 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6801 | // /* mirror::Object* */ root = root->Read() |
| 6802 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6803 | } |
| 6804 | } else { |
| 6805 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6806 | // /* GcRoot<mirror::Object> */ root = *address |
| 6807 | __ movl(root_reg, address); |
| 6808 | if (fixup_label != nullptr) { |
| 6809 | __ Bind(fixup_label); |
| 6810 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6811 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6812 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6813 | } |
| 6814 | } |
| 6815 | |
| 6816 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6817 | Location ref, |
| 6818 | Register obj, |
| 6819 | uint32_t offset, |
| 6820 | Location temp, |
| 6821 | bool needs_null_check) { |
| 6822 | DCHECK(kEmitCompilerReadBarrier); |
| 6823 | DCHECK(kUseBakerReadBarrier); |
| 6824 | |
| 6825 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6826 | Address src(obj, offset); |
| 6827 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6828 | } |
| 6829 | |
| 6830 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6831 | Location ref, |
| 6832 | Register obj, |
| 6833 | uint32_t data_offset, |
| 6834 | Location index, |
| 6835 | Location temp, |
| 6836 | bool needs_null_check) { |
| 6837 | DCHECK(kEmitCompilerReadBarrier); |
| 6838 | DCHECK(kUseBakerReadBarrier); |
| 6839 | |
| 6840 | // /* HeapReference<Object> */ ref = |
| 6841 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6842 | Address src = index.IsConstant() ? |
| 6843 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6844 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6845 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6846 | } |
| 6847 | |
| 6848 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6849 | Location ref, |
| 6850 | Register obj, |
| 6851 | const Address& src, |
| 6852 | Location temp, |
| 6853 | bool needs_null_check) { |
| 6854 | DCHECK(kEmitCompilerReadBarrier); |
| 6855 | DCHECK(kUseBakerReadBarrier); |
| 6856 | |
| 6857 | // In slow path based read barriers, the read barrier call is |
| 6858 | // inserted after the original load. However, in fast path based |
| 6859 | // Baker's read barriers, we need to perform the load of |
| 6860 | // mirror::Object::monitor_ *before* the original reference load. |
| 6861 | // This load-load ordering is required by the read barrier. |
| 6862 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6863 | // |
| 6864 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6865 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6866 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6867 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6868 | // if (is_gray) { |
| 6869 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6870 | // } |
| 6871 | // |
| 6872 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6873 | // slightly more complex as: |
| 6874 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6875 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6876 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6877 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6878 | // - it performs additional checks that we do not do here for |
| 6879 | // performance reasons. |
| 6880 | |
| 6881 | Register ref_reg = ref.AsRegister<Register>(); |
| 6882 | Register temp_reg = temp.AsRegister<Register>(); |
| 6883 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6884 | |
| 6885 | // /* int32_t */ monitor = obj->monitor_ |
| 6886 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6887 | if (needs_null_check) { |
| 6888 | MaybeRecordImplicitNullCheck(instruction); |
| 6889 | } |
| 6890 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6891 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6892 | "art::LockWord and int32_t have different sizes."); |
| 6893 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6894 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6895 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6896 | static_assert( |
| 6897 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6898 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6899 | |
| 6900 | // Load fence to prevent load-load reordering. |
| 6901 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6902 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6903 | |
| 6904 | // The actual reference load. |
| 6905 | // /* HeapReference<Object> */ ref = *src |
| 6906 | __ movl(ref_reg, src); |
| 6907 | |
| 6908 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6909 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6910 | |
| 6911 | // Slow path used to mark the object `ref` when it is gray. |
| 6912 | SlowPathCode* slow_path = |
| 6913 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6914 | AddSlowPath(slow_path); |
| 6915 | |
| 6916 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6917 | // ref = ReadBarrier::Mark(ref); |
| 6918 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6919 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6920 | __ Bind(slow_path->GetExitLabel()); |
| 6921 | } |
| 6922 | |
| 6923 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6924 | Location out, |
| 6925 | Location ref, |
| 6926 | Location obj, |
| 6927 | uint32_t offset, |
| 6928 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6929 | DCHECK(kEmitCompilerReadBarrier); |
| 6930 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6931 | // Insert a slow path based read barrier *after* the reference load. |
| 6932 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6933 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6934 | // reference will be carried out by the runtime within the slow |
| 6935 | // path. |
| 6936 | // |
| 6937 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6938 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6939 | // not used by the artReadBarrierSlow entry point. |
| 6940 | // |
| 6941 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6942 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6943 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6944 | AddSlowPath(slow_path); |
| 6945 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6946 | __ jmp(slow_path->GetEntryLabel()); |
| 6947 | __ Bind(slow_path->GetExitLabel()); |
| 6948 | } |
| 6949 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6950 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6951 | Location out, |
| 6952 | Location ref, |
| 6953 | Location obj, |
| 6954 | uint32_t offset, |
| 6955 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6956 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6957 | // Baker's read barriers shall be handled by the fast path |
| 6958 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6959 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6960 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6961 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6962 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6963 | } else if (kPoisonHeapReferences) { |
| 6964 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6965 | } |
| 6966 | } |
| 6967 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6968 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6969 | Location out, |
| 6970 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6971 | DCHECK(kEmitCompilerReadBarrier); |
| 6972 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6973 | // Insert a slow path based read barrier *after* the GC root load. |
| 6974 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6975 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6976 | // not need to do anything special for this here. |
| 6977 | SlowPathCode* slow_path = |
| 6978 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6979 | AddSlowPath(slow_path); |
| 6980 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6981 | __ jmp(slow_path->GetEntryLabel()); |
| 6982 | __ Bind(slow_path->GetExitLabel()); |
| 6983 | } |
| 6984 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6985 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6986 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6987 | LOG(FATAL) << "Unreachable"; |
| 6988 | } |
| 6989 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6990 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6991 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6992 | LOG(FATAL) << "Unreachable"; |
| 6993 | } |
| 6994 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6995 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6996 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6997 | LocationSummary* locations = |
| 6998 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6999 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7000 | } |
| 7001 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7002 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7003 | int32_t lower_bound, |
| 7004 | uint32_t num_entries, |
| 7005 | HBasicBlock* switch_block, |
| 7006 | HBasicBlock* default_block) { |
| 7007 | // Figure out the correct compare values and jump conditions. |
| 7008 | // Handle the first compare/branch as a special case because it might |
| 7009 | // jump to the default case. |
| 7010 | DCHECK_GT(num_entries, 2u); |
| 7011 | Condition first_condition; |
| 7012 | uint32_t index; |
| 7013 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7014 | if (lower_bound != 0) { |
| 7015 | first_condition = kLess; |
| 7016 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7017 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7018 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7019 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7020 | index = 1; |
| 7021 | } else { |
| 7022 | // Handle all the compare/jumps below. |
| 7023 | first_condition = kBelow; |
| 7024 | index = 0; |
| 7025 | } |
| 7026 | |
| 7027 | // Handle the rest of the compare/jumps. |
| 7028 | for (; index + 1 < num_entries; index += 2) { |
| 7029 | int32_t compare_to_value = lower_bound + index + 1; |
| 7030 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7031 | // Jump to successors[index] if value < case_value[index]. |
| 7032 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7033 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7034 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7035 | } |
| 7036 | |
| 7037 | if (index != num_entries) { |
| 7038 | // There are an odd number of entries. Handle the last one. |
| 7039 | DCHECK_EQ(index + 1, num_entries); |
| 7040 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7041 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7042 | } |
| 7043 | |
| 7044 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7045 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7046 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7047 | } |
| 7048 | } |
| 7049 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7050 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7051 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7052 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7053 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7054 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7055 | |
| 7056 | GenPackedSwitchWithCompares(value_reg, |
| 7057 | lower_bound, |
| 7058 | num_entries, |
| 7059 | switch_instr->GetBlock(), |
| 7060 | switch_instr->GetDefaultBlock()); |
| 7061 | } |
| 7062 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7063 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7064 | LocationSummary* locations = |
| 7065 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7066 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7067 | |
| 7068 | // Constant area pointer. |
| 7069 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7070 | |
| 7071 | // And the temporary we need. |
| 7072 | locations->AddTemp(Location::RequiresRegister()); |
| 7073 | } |
| 7074 | |
| 7075 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7076 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7077 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7078 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7079 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7080 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7081 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7082 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7083 | GenPackedSwitchWithCompares(value_reg, |
| 7084 | lower_bound, |
| 7085 | num_entries, |
| 7086 | switch_instr->GetBlock(), |
| 7087 | default_block); |
| 7088 | return; |
| 7089 | } |
| 7090 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7091 | // Optimizing has a jump area. |
| 7092 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7093 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7094 | |
| 7095 | // Remove the bias, if needed. |
| 7096 | if (lower_bound != 0) { |
| 7097 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7098 | value_reg = temp_reg; |
| 7099 | } |
| 7100 | |
| 7101 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7102 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7103 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7104 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7105 | |
| 7106 | // We are in the range of the table. |
| 7107 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7108 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7109 | |
| 7110 | // Compute the actual target address by adding in constant_area. |
| 7111 | __ addl(temp_reg, constant_area); |
| 7112 | |
| 7113 | // And jump. |
| 7114 | __ jmp(temp_reg); |
| 7115 | } |
| 7116 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7117 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7118 | HX86ComputeBaseMethodAddress* insn) { |
| 7119 | LocationSummary* locations = |
| 7120 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7121 | locations->SetOut(Location::RequiresRegister()); |
| 7122 | } |
| 7123 | |
| 7124 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7125 | HX86ComputeBaseMethodAddress* insn) { |
| 7126 | LocationSummary* locations = insn->GetLocations(); |
| 7127 | Register reg = locations->Out().AsRegister<Register>(); |
| 7128 | |
| 7129 | // Generate call to next instruction. |
| 7130 | Label next_instruction; |
| 7131 | __ call(&next_instruction); |
| 7132 | __ Bind(&next_instruction); |
| 7133 | |
| 7134 | // Remember this offset for later use with constant area. |
| 7135 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7136 | |
| 7137 | // Grab the return address off the stack. |
| 7138 | __ popl(reg); |
| 7139 | } |
| 7140 | |
| 7141 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7142 | HX86LoadFromConstantTable* insn) { |
| 7143 | LocationSummary* locations = |
| 7144 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7145 | |
| 7146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7147 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7148 | |
| 7149 | // 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] | 7150 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7151 | return; |
| 7152 | } |
| 7153 | |
| 7154 | switch (insn->GetType()) { |
| 7155 | case Primitive::kPrimFloat: |
| 7156 | case Primitive::kPrimDouble: |
| 7157 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7158 | break; |
| 7159 | |
| 7160 | case Primitive::kPrimInt: |
| 7161 | locations->SetOut(Location::RequiresRegister()); |
| 7162 | break; |
| 7163 | |
| 7164 | default: |
| 7165 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7166 | } |
| 7167 | } |
| 7168 | |
| 7169 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7170 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7171 | return; |
| 7172 | } |
| 7173 | |
| 7174 | LocationSummary* locations = insn->GetLocations(); |
| 7175 | Location out = locations->Out(); |
| 7176 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7177 | HConstant *value = insn->GetConstant(); |
| 7178 | |
| 7179 | switch (insn->GetType()) { |
| 7180 | case Primitive::kPrimFloat: |
| 7181 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7182 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7183 | break; |
| 7184 | |
| 7185 | case Primitive::kPrimDouble: |
| 7186 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7187 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7188 | break; |
| 7189 | |
| 7190 | case Primitive::kPrimInt: |
| 7191 | __ movl(out.AsRegister<Register>(), |
| 7192 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7193 | break; |
| 7194 | |
| 7195 | default: |
| 7196 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7197 | } |
| 7198 | } |
| 7199 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7200 | /** |
| 7201 | * Class to handle late fixup of offsets into constant area. |
| 7202 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7203 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7204 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7205 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7206 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7207 | |
| 7208 | protected: |
| 7209 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7210 | |
| 7211 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7212 | |
| 7213 | private: |
| 7214 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7215 | // Patch the correct offset for the instruction. The place to patch is the |
| 7216 | // last 4 bytes of the instruction. |
| 7217 | // The value to patch is the distance from the offset in the constant area |
| 7218 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7219 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7220 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7221 | |
| 7222 | // Patch in the right value. |
| 7223 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7224 | } |
| 7225 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7226 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7227 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7228 | }; |
| 7229 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7230 | /** |
| 7231 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7232 | * constant area. |
| 7233 | */ |
| 7234 | class JumpTableRIPFixup : public RIPFixup { |
| 7235 | public: |
| 7236 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7237 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7238 | |
| 7239 | void CreateJumpTable() { |
| 7240 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7241 | |
| 7242 | // Ensure that the reference to the jump table has the correct offset. |
| 7243 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7244 | SetOffset(offset_in_constant_table); |
| 7245 | |
| 7246 | // The label values in the jump table are computed relative to the |
| 7247 | // instruction addressing the constant area. |
| 7248 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7249 | |
| 7250 | // Populate the jump table with the correct values for the jump table. |
| 7251 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7252 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7253 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7254 | // The value that we want is the target offset - the position of the table. |
| 7255 | for (int32_t i = 0; i < num_entries; i++) { |
| 7256 | HBasicBlock* b = successors[i]; |
| 7257 | Label* l = codegen_->GetLabelOf(b); |
| 7258 | DCHECK(l->IsBound()); |
| 7259 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7260 | assembler->AppendInt32(offset_to_block); |
| 7261 | } |
| 7262 | } |
| 7263 | |
| 7264 | private: |
| 7265 | const HX86PackedSwitch* switch_instr_; |
| 7266 | }; |
| 7267 | |
| 7268 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7269 | // Generate the constant area if needed. |
| 7270 | X86Assembler* assembler = GetAssembler(); |
| 7271 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7272 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7273 | // byte values. |
| 7274 | assembler->Align(4, 0); |
| 7275 | constant_area_start_ = assembler->CodeSize(); |
| 7276 | |
| 7277 | // Populate any jump tables. |
| 7278 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7279 | jump_table->CreateJumpTable(); |
| 7280 | } |
| 7281 | |
| 7282 | // And now add the constant area to the generated code. |
| 7283 | assembler->AddConstantArea(); |
| 7284 | } |
| 7285 | |
| 7286 | // And finish up. |
| 7287 | CodeGenerator::Finalize(allocator); |
| 7288 | } |
| 7289 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7290 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7291 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7292 | return Address(reg, kDummy32BitOffset, fixup); |
| 7293 | } |
| 7294 | |
| 7295 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7296 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7297 | return Address(reg, kDummy32BitOffset, fixup); |
| 7298 | } |
| 7299 | |
| 7300 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7301 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7302 | return Address(reg, kDummy32BitOffset, fixup); |
| 7303 | } |
| 7304 | |
| 7305 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7306 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7307 | return Address(reg, kDummy32BitOffset, fixup); |
| 7308 | } |
| 7309 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7310 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7311 | if (value == 0) { |
| 7312 | __ xorl(dest, dest); |
| 7313 | } else { |
| 7314 | __ movl(dest, Immediate(value)); |
| 7315 | } |
| 7316 | } |
| 7317 | |
| 7318 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7319 | if (value == 0) { |
| 7320 | __ testl(dest, dest); |
| 7321 | } else { |
| 7322 | __ cmpl(dest, Immediate(value)); |
| 7323 | } |
| 7324 | } |
| 7325 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7326 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7327 | Register reg, |
| 7328 | Register value) { |
| 7329 | // Create a fixup to be used to create and address the jump table. |
| 7330 | JumpTableRIPFixup* table_fixup = |
| 7331 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7332 | |
| 7333 | // We have to populate the jump tables. |
| 7334 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7335 | |
| 7336 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7337 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7338 | } |
| 7339 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7340 | // TODO: target as memory. |
| 7341 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7342 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7343 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7344 | return; |
| 7345 | } |
| 7346 | |
| 7347 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7348 | |
| 7349 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7350 | if (target.Equals(return_loc)) { |
| 7351 | return; |
| 7352 | } |
| 7353 | |
| 7354 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7355 | // with the else branch. |
| 7356 | if (type == Primitive::kPrimLong) { |
| 7357 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7358 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7359 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7360 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7361 | } else { |
| 7362 | // Let the parallel move resolver take care of all of this. |
| 7363 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7364 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7365 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7366 | } |
| 7367 | } |
| 7368 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7369 | #undef __ |
| 7370 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7371 | } // namespace x86 |
| 7372 | } // namespace art |