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" |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 22 | #include "constant_area_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace x86 { |
| 39 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 40 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 41 | static constexpr Register kMethodRegisterArgument = EAX; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 43 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 45 | static constexpr int kC2ConditionMask = 0x400; |
| 46 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 47 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 48 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 49 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 50 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 51 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 52 | class NullCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 54 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 56 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 57 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 59 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 60 | // Live registers will be restored in the catch block if caught. |
| 61 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 62 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 63 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 64 | instruction_, |
| 65 | instruction_->GetDexPc(), |
| 66 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 69 | bool IsFatal() const OVERRIDE { return true; } |
| 70 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 71 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 72 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 74 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 76 | }; |
| 77 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 78 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 79 | public: |
| 80 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 81 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 82 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 83 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 85 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 86 | // Live registers will be restored in the catch block if caught. |
| 87 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 88 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 90 | instruction_, |
| 91 | instruction_->GetDexPc(), |
| 92 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
| 100 | HDivZeroCheck* const instruction_; |
| 101 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 102 | }; |
| 103 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 104 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 106 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(reg_); |
| 112 | } else { |
| 113 | __ movl(reg_, Immediate(0)); |
| 114 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | __ jmp(GetExitLabel()); |
| 116 | } |
| 117 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 118 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 119 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | private: |
| 121 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | bool is_div_; |
| 123 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 126 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 128 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 130 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 132 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 134 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 135 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 136 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 137 | // Live registers will be restored in the catch block if caught. |
| 138 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 139 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 141 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 142 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 143 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 144 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 147 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 148 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 149 | instruction_, |
| 150 | instruction_->GetDexPc(), |
| 151 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 154 | bool IsFatal() const OVERRIDE { return true; } |
| 155 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 156 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 157 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 159 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | |
| 161 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 162 | }; |
| 163 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 164 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 166 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 167 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 169 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 170 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 172 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 173 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 174 | instruction_, |
| 175 | instruction_->GetDexPc(), |
| 176 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 177 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | if (successor_ == nullptr) { |
| 179 | __ jmp(GetReturnLabel()); |
| 180 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 181 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 182 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | Label* GetReturnLabel() { |
| 186 | DCHECK(successor_ == nullptr); |
| 187 | return &return_label_; |
| 188 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 190 | HBasicBlock* GetSuccessor() const { |
| 191 | return successor_; |
| 192 | } |
| 193 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 194 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 195 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 196 | private: |
| 197 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | Label return_label_; |
| 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 202 | }; |
| 203 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 204 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 205 | public: |
| 206 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 207 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 208 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 209 | LocationSummary* locations = instruction_->GetLocations(); |
| 210 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 211 | |
| 212 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 213 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 214 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | |
| 216 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 217 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 218 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 219 | instruction_, |
| 220 | instruction_->GetDexPc(), |
| 221 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 222 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 223 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 224 | |
| 225 | __ jmp(GetExitLabel()); |
| 226 | } |
| 227 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 229 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | private: |
| 231 | HLoadString* const instruction_; |
| 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 234 | }; |
| 235 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 236 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 237 | public: |
| 238 | LoadClassSlowPathX86(HLoadClass* cls, |
| 239 | HInstruction* at, |
| 240 | uint32_t dex_pc, |
| 241 | bool do_clinit) |
| 242 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 243 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 244 | } |
| 245 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 246 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | LocationSummary* locations = at_->GetLocations(); |
| 248 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 249 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 250 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | |
| 252 | InvokeRuntimeCallingConvention calling_convention; |
| 253 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 254 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 255 | : QUICK_ENTRY_POINT(pInitializeType), |
| 256 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | |
| 258 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 259 | Location out = locations->Out(); |
| 260 | if (out.IsValid()) { |
| 261 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 262 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 264 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | __ jmp(GetExitLabel()); |
| 267 | } |
| 268 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 269 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 270 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | private: |
| 272 | // The class this slow path will load. |
| 273 | HLoadClass* const cls_; |
| 274 | |
| 275 | // The instruction where this slow path is happening. |
| 276 | // (Might be the load class or an initialization check). |
| 277 | HInstruction* const at_; |
| 278 | |
| 279 | // The dex PC of `at_`. |
| 280 | const uint32_t dex_pc_; |
| 281 | |
| 282 | // Whether to initialize the class. |
| 283 | const bool do_clinit_; |
| 284 | |
| 285 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 286 | }; |
| 287 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 288 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 289 | public: |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 290 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 291 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 293 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 294 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 295 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 296 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 297 | DCHECK(instruction_->IsCheckCast() |
| 298 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
| 300 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 301 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 302 | |
| 303 | if (instruction_->IsCheckCast()) { |
| 304 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 305 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 306 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 307 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 308 | __ movl(temp, Address(obj, class_offset)); |
| 309 | __ MaybeUnpoisonHeapReference(temp); |
| 310 | } |
| 311 | |
| 312 | if (!is_fatal_) { |
| 313 | SaveLiveRegisters(codegen, locations); |
| 314 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 315 | |
| 316 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 317 | // move resolver. |
| 318 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 319 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 320 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 321 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 322 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 324 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 325 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 327 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 328 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 329 | instruction_, |
| 330 | instruction_->GetDexPc(), |
| 331 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 332 | } else { |
| 333 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 334 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 335 | instruction_, |
| 336 | instruction_->GetDexPc(), |
| 337 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [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 | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [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 | 64acf30 | 2015-09-14 22:20:29 +0100 | [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 | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 354 | HInstruction* const instruction_; |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 355 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 356 | |
| 357 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 358 | }; |
| 359 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 360 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 361 | public: |
| 362 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 363 | : instruction_(instruction) {} |
| 364 | |
| 365 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 366 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 367 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | __ Bind(GetEntryLabel()); |
| 369 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 370 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 371 | instruction_, |
| 372 | instruction_->GetDexPc(), |
| 373 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 376 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 377 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | private: |
| 379 | HInstruction* const instruction_; |
| 380 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 381 | }; |
| 382 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 383 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 384 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 385 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 386 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 387 | switch (cond) { |
| 388 | case kCondEQ: return kEqual; |
| 389 | case kCondNE: return kNotEqual; |
| 390 | case kCondLT: return kLess; |
| 391 | case kCondLE: return kLessEqual; |
| 392 | case kCondGT: return kGreater; |
| 393 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 394 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 395 | LOG(FATAL) << "Unreachable"; |
| 396 | UNREACHABLE(); |
| 397 | } |
| 398 | |
| 399 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 400 | switch (cond) { |
| 401 | case kCondEQ: return kEqual; |
| 402 | case kCondNE: return kNotEqual; |
| 403 | case kCondLT: return kBelow; |
| 404 | case kCondLE: return kBelowEqual; |
| 405 | case kCondGT: return kAbove; |
| 406 | case kCondGE: return kAboveEqual; |
| 407 | } |
| 408 | LOG(FATAL) << "Unreachable"; |
| 409 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 412 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 413 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 417 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 420 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 421 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 422 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 423 | } |
| 424 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 425 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 426 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 427 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 428 | } |
| 429 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 430 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 431 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 432 | return GetFloatingPointSpillSlotSize(); |
| 433 | } |
| 434 | |
| 435 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 436 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 437 | return GetFloatingPointSpillSlotSize(); |
| 438 | } |
| 439 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 440 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 441 | HInstruction* instruction, |
| 442 | uint32_t dex_pc, |
| 443 | SlowPathCode* slow_path) { |
| 444 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 445 | instruction, |
| 446 | dex_pc, |
| 447 | slow_path); |
| 448 | } |
| 449 | |
| 450 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 451 | HInstruction* instruction, |
| 452 | uint32_t dex_pc, |
| 453 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 454 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 455 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 456 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 459 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 460 | const X86InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 461 | const CompilerOptions& compiler_options, |
| 462 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 463 | : CodeGenerator(graph, |
| 464 | kNumberOfCpuRegisters, |
| 465 | kNumberOfXmmRegisters, |
| 466 | kNumberOfRegisterPairs, |
| 467 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 468 | arraysize(kCoreCalleeSaves)) |
| 469 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 470 | 0, |
| 471 | compiler_options, |
| 472 | stats), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 473 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 474 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 475 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 476 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 477 | isa_features_(isa_features), |
| 478 | method_patches_(graph->GetArena()->Adapter()), |
| 479 | relative_call_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 480 | // Use a fake return address register to mimic Quick. |
| 481 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 482 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 483 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 484 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 485 | switch (type) { |
| 486 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 487 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 488 | X86ManagedRegister pair = |
| 489 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 490 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 491 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 492 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 493 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 494 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 495 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | case Primitive::kPrimByte: |
| 499 | case Primitive::kPrimBoolean: |
| 500 | case Primitive::kPrimChar: |
| 501 | case Primitive::kPrimShort: |
| 502 | case Primitive::kPrimInt: |
| 503 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 504 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 505 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 506 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 507 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 508 | X86ManagedRegister current = |
| 509 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 510 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 511 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 512 | } |
| 513 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 514 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 518 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 519 | return Location::FpuRegisterLocation( |
| 520 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 521 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 522 | |
| 523 | case Primitive::kPrimVoid: |
| 524 | LOG(FATAL) << "Unreachable type " << type; |
| 525 | } |
| 526 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 527 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 528 | } |
| 529 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 530 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 531 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 532 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 533 | |
| 534 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 535 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 536 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 537 | if (is_baseline) { |
| 538 | blocked_core_registers_[EBP] = true; |
| 539 | blocked_core_registers_[ESI] = true; |
| 540 | blocked_core_registers_[EDI] = true; |
| 541 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 542 | |
| 543 | UpdateBlockedPairRegisters(); |
| 544 | } |
| 545 | |
| 546 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 547 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 548 | X86ManagedRegister current = |
| 549 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 550 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 551 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 552 | blocked_register_pairs_[i] = true; |
| 553 | } |
| 554 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 555 | } |
| 556 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 557 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 558 | : HGraphVisitor(graph), |
| 559 | assembler_(codegen->GetAssembler()), |
| 560 | codegen_(codegen) {} |
| 561 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 562 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 563 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 566 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 567 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 568 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 569 | bool skip_overflow_check = |
| 570 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 571 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 572 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 573 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 574 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 575 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 576 | } |
| 577 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 578 | if (HasEmptyFrame()) { |
| 579 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 580 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 581 | |
| 582 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 583 | Register reg = kCoreCalleeSaves[i]; |
| 584 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 585 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 586 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 587 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 591 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 592 | __ subl(ESP, Immediate(adjust)); |
| 593 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 594 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 598 | __ cfi().RememberState(); |
| 599 | if (!HasEmptyFrame()) { |
| 600 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 601 | __ addl(ESP, Immediate(adjust)); |
| 602 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 603 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 604 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 605 | Register reg = kCoreCalleeSaves[i]; |
| 606 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 607 | __ popl(reg); |
| 608 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 609 | __ cfi().Restore(DWARFReg(reg)); |
| 610 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 611 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 612 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 613 | __ ret(); |
| 614 | __ cfi().RestoreState(); |
| 615 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 618 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 619 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 622 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 623 | switch (load->GetType()) { |
| 624 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 625 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 626 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 627 | |
| 628 | case Primitive::kPrimInt: |
| 629 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 630 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 631 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 632 | |
| 633 | case Primitive::kPrimBoolean: |
| 634 | case Primitive::kPrimByte: |
| 635 | case Primitive::kPrimChar: |
| 636 | case Primitive::kPrimShort: |
| 637 | case Primitive::kPrimVoid: |
| 638 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 639 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 643 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 644 | } |
| 645 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 646 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 647 | switch (type) { |
| 648 | case Primitive::kPrimBoolean: |
| 649 | case Primitive::kPrimByte: |
| 650 | case Primitive::kPrimChar: |
| 651 | case Primitive::kPrimShort: |
| 652 | case Primitive::kPrimInt: |
| 653 | case Primitive::kPrimNot: |
| 654 | return Location::RegisterLocation(EAX); |
| 655 | |
| 656 | case Primitive::kPrimLong: |
| 657 | return Location::RegisterPairLocation(EAX, EDX); |
| 658 | |
| 659 | case Primitive::kPrimVoid: |
| 660 | return Location::NoLocation(); |
| 661 | |
| 662 | case Primitive::kPrimDouble: |
| 663 | case Primitive::kPrimFloat: |
| 664 | return Location::FpuRegisterLocation(XMM0); |
| 665 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 666 | |
| 667 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 671 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 672 | } |
| 673 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 674 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 675 | switch (type) { |
| 676 | case Primitive::kPrimBoolean: |
| 677 | case Primitive::kPrimByte: |
| 678 | case Primitive::kPrimChar: |
| 679 | case Primitive::kPrimShort: |
| 680 | case Primitive::kPrimInt: |
| 681 | case Primitive::kPrimNot: { |
| 682 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 683 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 684 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 685 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 686 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 687 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 688 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 689 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 690 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 691 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 692 | uint32_t index = gp_index_; |
| 693 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 694 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 695 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 696 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 697 | calling_convention.GetRegisterPairAt(index)); |
| 698 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 699 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 700 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 705 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 706 | stack_index_++; |
| 707 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 708 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 709 | } else { |
| 710 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 715 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 716 | stack_index_ += 2; |
| 717 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 718 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 719 | } else { |
| 720 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 724 | case Primitive::kPrimVoid: |
| 725 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 726 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 727 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 728 | return Location(); |
| 729 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 730 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 731 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 732 | if (source.Equals(destination)) { |
| 733 | return; |
| 734 | } |
| 735 | if (destination.IsRegister()) { |
| 736 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 737 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 738 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 739 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 740 | } else { |
| 741 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 742 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 743 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 744 | } else if (destination.IsFpuRegister()) { |
| 745 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 746 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 747 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 748 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 749 | } else { |
| 750 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 751 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 752 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 753 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 754 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 755 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 756 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 757 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 758 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 759 | } else if (source.IsConstant()) { |
| 760 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 761 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 762 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 763 | } else { |
| 764 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 765 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 766 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 772 | if (source.Equals(destination)) { |
| 773 | return; |
| 774 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 775 | if (destination.IsRegisterPair()) { |
| 776 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 777 | EmitParallelMoves( |
| 778 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 779 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 780 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 781 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 782 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 783 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 784 | } else if (source.IsFpuRegister()) { |
| 785 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 786 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 787 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 788 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 789 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 790 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 791 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 792 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 793 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 794 | if (source.IsFpuRegister()) { |
| 795 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 796 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 797 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 798 | } else { |
| 799 | LOG(FATAL) << "Unimplemented"; |
| 800 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 801 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 802 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 803 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 804 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 805 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 806 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 807 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 808 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 809 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 810 | } else if (source.IsConstant()) { |
| 811 | HConstant* constant = source.GetConstant(); |
| 812 | int64_t value; |
| 813 | if (constant->IsLongConstant()) { |
| 814 | value = constant->AsLongConstant()->GetValue(); |
| 815 | } else { |
| 816 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 817 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 818 | } |
| 819 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 820 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 821 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 822 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 823 | EmitParallelMoves( |
| 824 | Location::StackSlot(source.GetStackIndex()), |
| 825 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 826 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 827 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 828 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 829 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 834 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 835 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 836 | if (instruction->IsCurrentMethod()) { |
| 837 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 838 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 839 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 840 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 841 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 842 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 843 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 844 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 845 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 846 | } else if (location.IsStackSlot()) { |
| 847 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 848 | } else { |
| 849 | DCHECK(location.IsConstant()); |
| 850 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 851 | } |
| 852 | } else if (const_to_move->IsLongConstant()) { |
| 853 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 854 | if (location.IsRegisterPair()) { |
| 855 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 856 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 857 | } else if (location.IsDoubleStackSlot()) { |
| 858 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 859 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 860 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 861 | } else { |
| 862 | DCHECK(location.IsConstant()); |
| 863 | DCHECK_EQ(location.GetConstant(), instruction); |
| 864 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 865 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 866 | } else if (instruction->IsTemporary()) { |
| 867 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 868 | if (temp_location.IsStackSlot()) { |
| 869 | Move32(location, temp_location); |
| 870 | } else { |
| 871 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 872 | Move64(location, temp_location); |
| 873 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 874 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 875 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 876 | switch (instruction->GetType()) { |
| 877 | case Primitive::kPrimBoolean: |
| 878 | case Primitive::kPrimByte: |
| 879 | case Primitive::kPrimChar: |
| 880 | case Primitive::kPrimShort: |
| 881 | case Primitive::kPrimInt: |
| 882 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 883 | case Primitive::kPrimFloat: |
| 884 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 885 | break; |
| 886 | |
| 887 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 888 | case Primitive::kPrimDouble: |
| 889 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | default: |
| 893 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 894 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 895 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 896 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 897 | switch (instruction->GetType()) { |
| 898 | case Primitive::kPrimBoolean: |
| 899 | case Primitive::kPrimByte: |
| 900 | case Primitive::kPrimChar: |
| 901 | case Primitive::kPrimShort: |
| 902 | case Primitive::kPrimInt: |
| 903 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 904 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 905 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 909 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 910 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 914 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 915 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 919 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 920 | DCHECK(location.IsRegister()); |
| 921 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 922 | } |
| 923 | |
Calin Juravle | 23a8e35 | 2015-09-08 19:56:31 +0100 | [diff] [blame] | 924 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 925 | if (location.IsRegister()) { |
| 926 | locations->AddTemp(location); |
| 927 | } else if (location.IsRegisterPair()) { |
| 928 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 929 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 930 | } else { |
| 931 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | void CodeGeneratorX86::MoveLocationToTemp(Location source, |
| 936 | const LocationSummary& locations, |
| 937 | int temp_index, |
| 938 | Primitive::Type type) { |
| 939 | if (!Primitive::IsFloatingPointType(type)) { |
| 940 | UNIMPLEMENTED(FATAL) << "MoveLocationToTemp not implemented for type " << type; |
| 941 | } |
| 942 | |
| 943 | DCHECK(source.IsFpuRegister()) << source; |
| 944 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 945 | if (type == Primitive::kPrimFloat) { |
| 946 | __ movd(locations.GetTemp(temp_index).AsRegister<Register>(), src_reg); |
| 947 | } else { |
| 948 | DCHECK(type == Primitive::kPrimDouble); |
| 949 | __ movd(locations.GetTemp(temp_index).AsRegister<Register>(), src_reg); |
| 950 | __ psrlq(src_reg, Immediate(32)); |
| 951 | __ movd(locations.GetTemp(temp_index + 1).AsRegister<Register>(), src_reg); |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | void CodeGeneratorX86::MoveTempToLocation(const LocationSummary& locations, |
| 956 | int temp_index, |
| 957 | Location destination, |
| 958 | Primitive::Type type) { |
| 959 | if (!Primitive::IsFloatingPointType(type)) { |
| 960 | UNIMPLEMENTED(FATAL) << "MoveLocationToTemp not implemented for type " << type; |
| 961 | } |
| 962 | |
| 963 | DCHECK(destination.IsFpuRegister()) << destination; |
| 964 | XmmRegister dst_reg = destination.AsFpuRegister<XmmRegister>(); |
| 965 | if (type == Primitive::kPrimFloat) { |
| 966 | __ movd(dst_reg, locations.GetTemp(temp_index).AsRegister<Register>()); |
| 967 | } else { |
| 968 | DCHECK(type == Primitive::kPrimDouble); |
| 969 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 970 | // Create stack space for 2 elements. |
| 971 | __ subl(ESP, Immediate(2 * elem_size)); |
| 972 | __ movl(Address(ESP, 0), locations.GetTemp(temp_index).AsRegister<Register>()); |
| 973 | __ movl(Address(ESP, elem_size), locations.GetTemp(temp_index + 1).AsRegister<Register>()); |
| 974 | __ movsd(dst_reg, Address(ESP, 0)); |
| 975 | // And remove the temporary stack space we allocated. |
| 976 | __ addl(ESP, Immediate(2 * elem_size)); |
| 977 | } |
| 978 | } |
| 979 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 980 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 981 | DCHECK(!successor->IsExitBlock()); |
| 982 | |
| 983 | HBasicBlock* block = got->GetBlock(); |
| 984 | HInstruction* previous = got->GetPrevious(); |
| 985 | |
| 986 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 987 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 988 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 989 | return; |
| 990 | } |
| 991 | |
| 992 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 993 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 994 | } |
| 995 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 996 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1000 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1001 | got->SetLocations(nullptr); |
| 1002 | } |
| 1003 | |
| 1004 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1005 | HandleGoto(got, got->GetSuccessor()); |
| 1006 | } |
| 1007 | |
| 1008 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1009 | try_boundary->SetLocations(nullptr); |
| 1010 | } |
| 1011 | |
| 1012 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1013 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1014 | if (!successor->IsExitBlock()) { |
| 1015 | HandleGoto(try_boundary, successor); |
| 1016 | } |
| 1017 | } |
| 1018 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1019 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1020 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1023 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1024 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1027 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 1028 | Label* true_label, |
| 1029 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1030 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1031 | __ j(kUnordered, true_label); |
| 1032 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1033 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1034 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1035 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 1039 | Label* true_label, |
| 1040 | Label* false_label) { |
| 1041 | LocationSummary* locations = cond->GetLocations(); |
| 1042 | Location left = locations->InAt(0); |
| 1043 | Location right = locations->InAt(1); |
| 1044 | IfCondition if_cond = cond->GetCondition(); |
| 1045 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1046 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1047 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1048 | IfCondition true_high_cond = if_cond; |
| 1049 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1050 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1051 | |
| 1052 | // Set the conditions for the test, remembering that == needs to be |
| 1053 | // decided using the low words. |
| 1054 | switch (if_cond) { |
| 1055 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1056 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1057 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1058 | break; |
| 1059 | case kCondLT: |
| 1060 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1061 | break; |
| 1062 | case kCondLE: |
| 1063 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1064 | break; |
| 1065 | case kCondGT: |
| 1066 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1067 | break; |
| 1068 | case kCondGE: |
| 1069 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1070 | break; |
| 1071 | } |
| 1072 | |
| 1073 | if (right.IsConstant()) { |
| 1074 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1075 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1076 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1077 | |
| 1078 | if (val_high == 0) { |
| 1079 | __ testl(left_high, left_high); |
| 1080 | } else { |
| 1081 | __ cmpl(left_high, Immediate(val_high)); |
| 1082 | } |
| 1083 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1084 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1085 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1086 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1087 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1088 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1089 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1090 | } |
| 1091 | // Must be equal high, so compare the lows. |
| 1092 | if (val_low == 0) { |
| 1093 | __ testl(left_low, left_low); |
| 1094 | } else { |
| 1095 | __ cmpl(left_low, Immediate(val_low)); |
| 1096 | } |
| 1097 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1098 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1099 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1100 | |
| 1101 | __ cmpl(left_high, right_high); |
| 1102 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1103 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1104 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1105 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1106 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1107 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1108 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1109 | } |
| 1110 | // Must be equal high, so compare the lows. |
| 1111 | __ cmpl(left_low, right_low); |
| 1112 | } |
| 1113 | // The last comparison might be unsigned. |
| 1114 | __ j(final_condition, true_label); |
| 1115 | } |
| 1116 | |
| 1117 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1118 | HCondition* condition, |
| 1119 | Label* true_target, |
| 1120 | Label* false_target, |
| 1121 | Label* always_true_target) { |
| 1122 | LocationSummary* locations = condition->GetLocations(); |
| 1123 | Location left = locations->InAt(0); |
| 1124 | Location right = locations->InAt(1); |
| 1125 | |
| 1126 | // We don't want true_target as a nullptr. |
| 1127 | if (true_target == nullptr) { |
| 1128 | true_target = always_true_target; |
| 1129 | } |
| 1130 | bool falls_through = (false_target == nullptr); |
| 1131 | |
| 1132 | // FP compares don't like null false_targets. |
| 1133 | if (false_target == nullptr) { |
| 1134 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1135 | } |
| 1136 | |
| 1137 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1138 | switch (type) { |
| 1139 | case Primitive::kPrimLong: |
| 1140 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1141 | break; |
| 1142 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1143 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1144 | GenerateFPJumps(condition, true_target, false_target); |
| 1145 | break; |
| 1146 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1147 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1148 | GenerateFPJumps(condition, true_target, false_target); |
| 1149 | break; |
| 1150 | default: |
| 1151 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1152 | } |
| 1153 | |
| 1154 | if (!falls_through) { |
| 1155 | __ jmp(false_target); |
| 1156 | } |
| 1157 | } |
| 1158 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1159 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1160 | Label* true_target, |
| 1161 | Label* false_target, |
| 1162 | Label* always_true_target) { |
| 1163 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1164 | if (cond->IsIntConstant()) { |
| 1165 | // Constant condition, statically compared against 1. |
| 1166 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1167 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1168 | if (always_true_target != nullptr) { |
| 1169 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1170 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1171 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1172 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1173 | DCHECK_EQ(cond_value, 0); |
| 1174 | } |
| 1175 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1176 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1177 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1178 | // Moves do not affect the eflags register, so if the condition is |
| 1179 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1180 | // again. We can't use the eflags on long/FP conditions if they are |
| 1181 | // materialized due to the complex branching. |
| 1182 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1183 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1184 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1185 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1186 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1187 | if (!eflags_set) { |
| 1188 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1189 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1190 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1191 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1192 | } else { |
| 1193 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1194 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1195 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1196 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1197 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1198 | } |
| 1199 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1200 | // Condition has not been materialized, use its inputs as the |
| 1201 | // comparison and its condition as the branch condition. |
| 1202 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1203 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1204 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1205 | // Generate the comparison directly. |
| 1206 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1207 | cond->AsCondition(), |
| 1208 | true_target, |
| 1209 | false_target, |
| 1210 | always_true_target); |
| 1211 | return; |
| 1212 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1213 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1214 | Location lhs = cond->GetLocations()->InAt(0); |
| 1215 | Location rhs = cond->GetLocations()->InAt(1); |
| 1216 | // LHS is guaranteed to be in a register (see |
| 1217 | // LocationsBuilderX86::VisitCondition). |
| 1218 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1219 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1220 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1221 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1222 | if (constant == 0) { |
| 1223 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1224 | } else { |
| 1225 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1226 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1227 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1228 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1229 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1230 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1231 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1232 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1233 | if (false_target != nullptr) { |
| 1234 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1238 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1239 | LocationSummary* locations = |
| 1240 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1241 | HInstruction* cond = if_instr->InputAt(0); |
| 1242 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1243 | locations->SetInAt(0, Location::Any()); |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1248 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1249 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1250 | Label* always_true_target = true_target; |
| 1251 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1252 | if_instr->IfTrueSuccessor())) { |
| 1253 | always_true_target = nullptr; |
| 1254 | } |
| 1255 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1256 | if_instr->IfFalseSuccessor())) { |
| 1257 | false_target = nullptr; |
| 1258 | } |
| 1259 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1260 | } |
| 1261 | |
| 1262 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1263 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1264 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1265 | HInstruction* cond = deoptimize->InputAt(0); |
| 1266 | DCHECK(cond->IsCondition()); |
| 1267 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1268 | locations->SetInAt(0, Location::Any()); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1273 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1274 | DeoptimizationSlowPathX86(deoptimize); |
| 1275 | codegen_->AddSlowPath(slow_path); |
| 1276 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1277 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1278 | } |
| 1279 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1280 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1281 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1284 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1285 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1288 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1289 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1292 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1293 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1294 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1297 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1298 | LocationSummary* locations = |
| 1299 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1300 | switch (store->InputAt(1)->GetType()) { |
| 1301 | case Primitive::kPrimBoolean: |
| 1302 | case Primitive::kPrimByte: |
| 1303 | case Primitive::kPrimChar: |
| 1304 | case Primitive::kPrimShort: |
| 1305 | case Primitive::kPrimInt: |
| 1306 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1307 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1308 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1309 | break; |
| 1310 | |
| 1311 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1312 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1313 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1314 | break; |
| 1315 | |
| 1316 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1317 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1318 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1321 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1322 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1325 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1326 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1327 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1328 | // Handle the long/FP comparisons made in instruction simplification. |
| 1329 | switch (cond->InputAt(0)->GetType()) { |
| 1330 | case Primitive::kPrimLong: { |
| 1331 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1332 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1333 | if (cond->NeedsMaterialization()) { |
| 1334 | locations->SetOut(Location::RequiresRegister()); |
| 1335 | } |
| 1336 | break; |
| 1337 | } |
| 1338 | case Primitive::kPrimFloat: |
| 1339 | case Primitive::kPrimDouble: { |
| 1340 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1341 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1342 | if (cond->NeedsMaterialization()) { |
| 1343 | locations->SetOut(Location::RequiresRegister()); |
| 1344 | } |
| 1345 | break; |
| 1346 | } |
| 1347 | default: |
| 1348 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1349 | locations->SetInAt(1, Location::Any()); |
| 1350 | if (cond->NeedsMaterialization()) { |
| 1351 | // We need a byte register. |
| 1352 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1353 | } |
| 1354 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1355 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1356 | } |
| 1357 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1358 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | if (!cond->NeedsMaterialization()) { |
| 1360 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1361 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | |
| 1363 | LocationSummary* locations = cond->GetLocations(); |
| 1364 | Location lhs = locations->InAt(0); |
| 1365 | Location rhs = locations->InAt(1); |
| 1366 | Register reg = locations->Out().AsRegister<Register>(); |
| 1367 | Label true_label, false_label; |
| 1368 | |
| 1369 | switch (cond->InputAt(0)->GetType()) { |
| 1370 | default: { |
| 1371 | // Integer case. |
| 1372 | |
| 1373 | // Clear output register: setcc only sets the low byte. |
| 1374 | __ xorl(reg, reg); |
| 1375 | |
| 1376 | if (rhs.IsRegister()) { |
| 1377 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1378 | } else if (rhs.IsConstant()) { |
| 1379 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1380 | if (constant == 0) { |
| 1381 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1382 | } else { |
| 1383 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1384 | } |
| 1385 | } else { |
| 1386 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1387 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1388 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1389 | return; |
| 1390 | } |
| 1391 | case Primitive::kPrimLong: |
| 1392 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1393 | break; |
| 1394 | case Primitive::kPrimFloat: |
| 1395 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1396 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1397 | break; |
| 1398 | case Primitive::kPrimDouble: |
| 1399 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1400 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1401 | break; |
| 1402 | } |
| 1403 | |
| 1404 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1405 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1406 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1407 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | __ Bind(&false_label); |
| 1409 | __ xorl(reg, reg); |
| 1410 | __ jmp(&done_label); |
| 1411 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1412 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | __ Bind(&true_label); |
| 1414 | __ movl(reg, Immediate(1)); |
| 1415 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1419 | VisitCondition(comp); |
| 1420 | } |
| 1421 | |
| 1422 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1423 | VisitCondition(comp); |
| 1424 | } |
| 1425 | |
| 1426 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1427 | VisitCondition(comp); |
| 1428 | } |
| 1429 | |
| 1430 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1431 | VisitCondition(comp); |
| 1432 | } |
| 1433 | |
| 1434 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1435 | VisitCondition(comp); |
| 1436 | } |
| 1437 | |
| 1438 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1439 | VisitCondition(comp); |
| 1440 | } |
| 1441 | |
| 1442 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1443 | VisitCondition(comp); |
| 1444 | } |
| 1445 | |
| 1446 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1447 | VisitCondition(comp); |
| 1448 | } |
| 1449 | |
| 1450 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1451 | VisitCondition(comp); |
| 1452 | } |
| 1453 | |
| 1454 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1455 | VisitCondition(comp); |
| 1456 | } |
| 1457 | |
| 1458 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1459 | VisitCondition(comp); |
| 1460 | } |
| 1461 | |
| 1462 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1463 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1467 | LocationSummary* locations = |
| 1468 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1469 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1472 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1473 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1474 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1477 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1478 | LocationSummary* locations = |
| 1479 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1480 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1481 | } |
| 1482 | |
| 1483 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1484 | // Will be generated at use site. |
| 1485 | UNUSED(constant); |
| 1486 | } |
| 1487 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1488 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1489 | LocationSummary* locations = |
| 1490 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1491 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1495 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1496 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1497 | } |
| 1498 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1499 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1500 | LocationSummary* locations = |
| 1501 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1502 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1503 | } |
| 1504 | |
| 1505 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1506 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1507 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1511 | LocationSummary* locations = |
| 1512 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1513 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1514 | } |
| 1515 | |
| 1516 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1517 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1518 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1519 | } |
| 1520 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1521 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1522 | memory_barrier->SetLocations(nullptr); |
| 1523 | } |
| 1524 | |
| 1525 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1526 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1527 | } |
| 1528 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1529 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1530 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1533 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1534 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1535 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1538 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1539 | LocationSummary* locations = |
| 1540 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1541 | switch (ret->InputAt(0)->GetType()) { |
| 1542 | case Primitive::kPrimBoolean: |
| 1543 | case Primitive::kPrimByte: |
| 1544 | case Primitive::kPrimChar: |
| 1545 | case Primitive::kPrimShort: |
| 1546 | case Primitive::kPrimInt: |
| 1547 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1548 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1549 | break; |
| 1550 | |
| 1551 | case Primitive::kPrimLong: |
| 1552 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1553 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1554 | break; |
| 1555 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1556 | case Primitive::kPrimFloat: |
| 1557 | case Primitive::kPrimDouble: |
| 1558 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1559 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1560 | break; |
| 1561 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1562 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1563 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1564 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1567 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1568 | if (kIsDebugBuild) { |
| 1569 | switch (ret->InputAt(0)->GetType()) { |
| 1570 | case Primitive::kPrimBoolean: |
| 1571 | case Primitive::kPrimByte: |
| 1572 | case Primitive::kPrimChar: |
| 1573 | case Primitive::kPrimShort: |
| 1574 | case Primitive::kPrimInt: |
| 1575 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1576 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1577 | break; |
| 1578 | |
| 1579 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1580 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1581 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1582 | break; |
| 1583 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1584 | case Primitive::kPrimFloat: |
| 1585 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1586 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1587 | break; |
| 1588 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1589 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1590 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1591 | } |
| 1592 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1593 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1596 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1597 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1598 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1599 | // the method_idx. |
| 1600 | HandleInvoke(invoke); |
| 1601 | } |
| 1602 | |
| 1603 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1604 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1605 | } |
| 1606 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1607 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1608 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1609 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1610 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1611 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1612 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1613 | if (intrinsic.TryDispatch(invoke)) { |
| 1614 | return; |
| 1615 | } |
| 1616 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1617 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1618 | |
| 1619 | if (codegen_->IsBaseline()) { |
| 1620 | // Baseline does not have enough registers if the current method also |
| 1621 | // needs a register. We therefore do not require a register for it, and let |
| 1622 | // the code generation of the invoke handle it. |
| 1623 | LocationSummary* locations = invoke->GetLocations(); |
| 1624 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1625 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1626 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1627 | } |
| 1628 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1629 | } |
| 1630 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1631 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1632 | if (invoke->GetLocations()->Intrinsified()) { |
| 1633 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1634 | intrinsic.Dispatch(invoke); |
| 1635 | return true; |
| 1636 | } |
| 1637 | return false; |
| 1638 | } |
| 1639 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1640 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1641 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1642 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1643 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1644 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1645 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1646 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1647 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1648 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1649 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1650 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1651 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1652 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1656 | HandleInvoke(invoke); |
| 1657 | } |
| 1658 | |
| 1659 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1660 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1661 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1664 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1665 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1666 | return; |
| 1667 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1668 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1669 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1670 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1671 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1674 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1675 | HandleInvoke(invoke); |
| 1676 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1677 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1681 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1682 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1683 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1684 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1685 | LocationSummary* locations = invoke->GetLocations(); |
| 1686 | Location receiver = locations->InAt(0); |
| 1687 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1688 | |
| 1689 | // Set the hidden argument. |
| 1690 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1691 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1692 | |
| 1693 | // temp = object->GetClass(); |
| 1694 | if (receiver.IsStackSlot()) { |
| 1695 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1696 | __ movl(temp, Address(temp, class_offset)); |
| 1697 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1698 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1699 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1700 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1701 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1702 | // temp = temp->GetImtEntryAt(method_offset); |
| 1703 | __ movl(temp, Address(temp, method_offset)); |
| 1704 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1705 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1706 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1707 | |
| 1708 | DCHECK(!codegen_->IsLeafMethod()); |
| 1709 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1710 | } |
| 1711 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1712 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1713 | LocationSummary* locations = |
| 1714 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1715 | switch (neg->GetResultType()) { |
| 1716 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1717 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1718 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1719 | locations->SetOut(Location::SameAsFirstInput()); |
| 1720 | break; |
| 1721 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1722 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1723 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1724 | locations->SetOut(Location::SameAsFirstInput()); |
| 1725 | locations->AddTemp(Location::RequiresRegister()); |
| 1726 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1727 | break; |
| 1728 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1729 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1730 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1731 | locations->SetOut(Location::SameAsFirstInput()); |
| 1732 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1733 | break; |
| 1734 | |
| 1735 | default: |
| 1736 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1741 | LocationSummary* locations = neg->GetLocations(); |
| 1742 | Location out = locations->Out(); |
| 1743 | Location in = locations->InAt(0); |
| 1744 | switch (neg->GetResultType()) { |
| 1745 | case Primitive::kPrimInt: |
| 1746 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1747 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1748 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1749 | break; |
| 1750 | |
| 1751 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1752 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1753 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1754 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1755 | // Negation is similar to subtraction from zero. The least |
| 1756 | // significant byte triggers a borrow when it is different from |
| 1757 | // zero; to take it into account, add 1 to the most significant |
| 1758 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1759 | // operation. |
| 1760 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1761 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1762 | break; |
| 1763 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1764 | case Primitive::kPrimFloat: { |
| 1765 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1766 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1767 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1768 | // Implement float negation with an exclusive or with value |
| 1769 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1770 | // single-precision floating-point number). |
| 1771 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1772 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1773 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1774 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1775 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1776 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1777 | case Primitive::kPrimDouble: { |
| 1778 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1779 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1780 | // Implement double negation with an exclusive or with value |
| 1781 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1782 | // a double-precision floating-point number). |
| 1783 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1784 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1785 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1786 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1787 | |
| 1788 | default: |
| 1789 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1790 | } |
| 1791 | } |
| 1792 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1793 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1794 | Primitive::Type result_type = conversion->GetResultType(); |
| 1795 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1796 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1797 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1798 | // The float-to-long and double-to-long type conversions rely on a |
| 1799 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1800 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1801 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1802 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1803 | ? LocationSummary::kCall |
| 1804 | : LocationSummary::kNoCall; |
| 1805 | LocationSummary* locations = |
| 1806 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1807 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1808 | // The Java language does not allow treating boolean as an integral type but |
| 1809 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1810 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1811 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1812 | case Primitive::kPrimByte: |
| 1813 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1814 | case Primitive::kPrimBoolean: |
| 1815 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1816 | case Primitive::kPrimShort: |
| 1817 | case Primitive::kPrimInt: |
| 1818 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1819 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1820 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1821 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1822 | // the validation of the linear scan implementation |
| 1823 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1824 | break; |
| 1825 | |
| 1826 | default: |
| 1827 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1828 | << " to " << result_type; |
| 1829 | } |
| 1830 | break; |
| 1831 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1832 | case Primitive::kPrimShort: |
| 1833 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1834 | case Primitive::kPrimBoolean: |
| 1835 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1836 | case Primitive::kPrimByte: |
| 1837 | case Primitive::kPrimInt: |
| 1838 | case Primitive::kPrimChar: |
| 1839 | // Processing a Dex `int-to-short' instruction. |
| 1840 | locations->SetInAt(0, Location::Any()); |
| 1841 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1842 | break; |
| 1843 | |
| 1844 | default: |
| 1845 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1846 | << " to " << result_type; |
| 1847 | } |
| 1848 | break; |
| 1849 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1850 | case Primitive::kPrimInt: |
| 1851 | switch (input_type) { |
| 1852 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1853 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1854 | locations->SetInAt(0, Location::Any()); |
| 1855 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1856 | break; |
| 1857 | |
| 1858 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1859 | // Processing a Dex `float-to-int' instruction. |
| 1860 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1861 | locations->SetOut(Location::RequiresRegister()); |
| 1862 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1863 | break; |
| 1864 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1865 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1866 | // Processing a Dex `double-to-int' instruction. |
| 1867 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1868 | locations->SetOut(Location::RequiresRegister()); |
| 1869 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1870 | break; |
| 1871 | |
| 1872 | default: |
| 1873 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1874 | << " to " << result_type; |
| 1875 | } |
| 1876 | break; |
| 1877 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1878 | case Primitive::kPrimLong: |
| 1879 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1880 | case Primitive::kPrimBoolean: |
| 1881 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1882 | case Primitive::kPrimByte: |
| 1883 | case Primitive::kPrimShort: |
| 1884 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1886 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1887 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1888 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1889 | break; |
| 1890 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1891 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1892 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1893 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1894 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1895 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1896 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1897 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1898 | // The runtime helper puts the result in EAX, EDX. |
| 1899 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1900 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1901 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1902 | |
| 1903 | default: |
| 1904 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1905 | << " to " << result_type; |
| 1906 | } |
| 1907 | break; |
| 1908 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1909 | case Primitive::kPrimChar: |
| 1910 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1911 | case Primitive::kPrimBoolean: |
| 1912 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1913 | case Primitive::kPrimByte: |
| 1914 | case Primitive::kPrimShort: |
| 1915 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1916 | // Processing a Dex `int-to-char' instruction. |
| 1917 | locations->SetInAt(0, Location::Any()); |
| 1918 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1919 | break; |
| 1920 | |
| 1921 | default: |
| 1922 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1923 | << " to " << result_type; |
| 1924 | } |
| 1925 | break; |
| 1926 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1927 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1928 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1929 | case Primitive::kPrimBoolean: |
| 1930 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1931 | case Primitive::kPrimByte: |
| 1932 | case Primitive::kPrimShort: |
| 1933 | case Primitive::kPrimInt: |
| 1934 | case Primitive::kPrimChar: |
| 1935 | // Processing a Dex `int-to-float' instruction. |
| 1936 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1937 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1938 | break; |
| 1939 | |
| 1940 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1941 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1942 | locations->SetInAt(0, Location::Any()); |
| 1943 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1946 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1947 | // Processing a Dex `double-to-float' instruction. |
| 1948 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1949 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1950 | break; |
| 1951 | |
| 1952 | default: |
| 1953 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1954 | << " to " << result_type; |
| 1955 | }; |
| 1956 | break; |
| 1957 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1958 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1959 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1960 | case Primitive::kPrimBoolean: |
| 1961 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1962 | case Primitive::kPrimByte: |
| 1963 | case Primitive::kPrimShort: |
| 1964 | case Primitive::kPrimInt: |
| 1965 | case Primitive::kPrimChar: |
| 1966 | // Processing a Dex `int-to-double' instruction. |
| 1967 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1968 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1969 | break; |
| 1970 | |
| 1971 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1972 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1973 | locations->SetInAt(0, Location::Any()); |
| 1974 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1975 | break; |
| 1976 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1977 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1978 | // Processing a Dex `float-to-double' instruction. |
| 1979 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1980 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1981 | break; |
| 1982 | |
| 1983 | default: |
| 1984 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1985 | << " to " << result_type; |
| 1986 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1987 | break; |
| 1988 | |
| 1989 | default: |
| 1990 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1991 | << " to " << result_type; |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1996 | LocationSummary* locations = conversion->GetLocations(); |
| 1997 | Location out = locations->Out(); |
| 1998 | Location in = locations->InAt(0); |
| 1999 | Primitive::Type result_type = conversion->GetResultType(); |
| 2000 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2001 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2002 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2003 | case Primitive::kPrimByte: |
| 2004 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2005 | case Primitive::kPrimBoolean: |
| 2006 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2007 | case Primitive::kPrimShort: |
| 2008 | case Primitive::kPrimInt: |
| 2009 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2010 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2011 | if (in.IsRegister()) { |
| 2012 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2013 | } else { |
| 2014 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2015 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2016 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2017 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2018 | break; |
| 2019 | |
| 2020 | default: |
| 2021 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2022 | << " to " << result_type; |
| 2023 | } |
| 2024 | break; |
| 2025 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2026 | case Primitive::kPrimShort: |
| 2027 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2028 | case Primitive::kPrimBoolean: |
| 2029 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2030 | case Primitive::kPrimByte: |
| 2031 | case Primitive::kPrimInt: |
| 2032 | case Primitive::kPrimChar: |
| 2033 | // Processing a Dex `int-to-short' instruction. |
| 2034 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2035 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2036 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2037 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2038 | } else { |
| 2039 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2040 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2041 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2042 | } |
| 2043 | break; |
| 2044 | |
| 2045 | default: |
| 2046 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2047 | << " to " << result_type; |
| 2048 | } |
| 2049 | break; |
| 2050 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2051 | case Primitive::kPrimInt: |
| 2052 | switch (input_type) { |
| 2053 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2054 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2055 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2056 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2057 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2058 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2059 | } else { |
| 2060 | DCHECK(in.IsConstant()); |
| 2061 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2062 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2063 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2064 | } |
| 2065 | break; |
| 2066 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2067 | case Primitive::kPrimFloat: { |
| 2068 | // Processing a Dex `float-to-int' instruction. |
| 2069 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2070 | Register output = out.AsRegister<Register>(); |
| 2071 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2072 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2073 | |
| 2074 | __ movl(output, Immediate(kPrimIntMax)); |
| 2075 | // temp = int-to-float(output) |
| 2076 | __ cvtsi2ss(temp, output); |
| 2077 | // if input >= temp goto done |
| 2078 | __ comiss(input, temp); |
| 2079 | __ j(kAboveEqual, &done); |
| 2080 | // if input == NaN goto nan |
| 2081 | __ j(kUnordered, &nan); |
| 2082 | // output = float-to-int-truncate(input) |
| 2083 | __ cvttss2si(output, input); |
| 2084 | __ jmp(&done); |
| 2085 | __ Bind(&nan); |
| 2086 | // output = 0 |
| 2087 | __ xorl(output, output); |
| 2088 | __ Bind(&done); |
| 2089 | break; |
| 2090 | } |
| 2091 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2092 | case Primitive::kPrimDouble: { |
| 2093 | // Processing a Dex `double-to-int' instruction. |
| 2094 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2095 | Register output = out.AsRegister<Register>(); |
| 2096 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2097 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2098 | |
| 2099 | __ movl(output, Immediate(kPrimIntMax)); |
| 2100 | // temp = int-to-double(output) |
| 2101 | __ cvtsi2sd(temp, output); |
| 2102 | // if input >= temp goto done |
| 2103 | __ comisd(input, temp); |
| 2104 | __ j(kAboveEqual, &done); |
| 2105 | // if input == NaN goto nan |
| 2106 | __ j(kUnordered, &nan); |
| 2107 | // output = double-to-int-truncate(input) |
| 2108 | __ cvttsd2si(output, input); |
| 2109 | __ jmp(&done); |
| 2110 | __ Bind(&nan); |
| 2111 | // output = 0 |
| 2112 | __ xorl(output, output); |
| 2113 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2114 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2115 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2116 | |
| 2117 | default: |
| 2118 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2119 | << " to " << result_type; |
| 2120 | } |
| 2121 | break; |
| 2122 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2123 | case Primitive::kPrimLong: |
| 2124 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2125 | case Primitive::kPrimBoolean: |
| 2126 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2127 | case Primitive::kPrimByte: |
| 2128 | case Primitive::kPrimShort: |
| 2129 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2130 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2131 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2132 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2133 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2134 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2135 | __ cdq(); |
| 2136 | break; |
| 2137 | |
| 2138 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2139 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2140 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2141 | conversion, |
| 2142 | conversion->GetDexPc(), |
| 2143 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2146 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2147 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2148 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2149 | conversion, |
| 2150 | conversion->GetDexPc(), |
| 2151 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2152 | break; |
| 2153 | |
| 2154 | default: |
| 2155 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2156 | << " to " << result_type; |
| 2157 | } |
| 2158 | break; |
| 2159 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2160 | case Primitive::kPrimChar: |
| 2161 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2162 | case Primitive::kPrimBoolean: |
| 2163 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2164 | case Primitive::kPrimByte: |
| 2165 | case Primitive::kPrimShort: |
| 2166 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2167 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2168 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2169 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2170 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2171 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2172 | } else { |
| 2173 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2174 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2175 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2176 | } |
| 2177 | break; |
| 2178 | |
| 2179 | default: |
| 2180 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2181 | << " to " << result_type; |
| 2182 | } |
| 2183 | break; |
| 2184 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2185 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2186 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2187 | case Primitive::kPrimBoolean: |
| 2188 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2189 | case Primitive::kPrimByte: |
| 2190 | case Primitive::kPrimShort: |
| 2191 | case Primitive::kPrimInt: |
| 2192 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2193 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2194 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2195 | break; |
| 2196 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2197 | case Primitive::kPrimLong: { |
| 2198 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2199 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2200 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2201 | // Create stack space for the call to |
| 2202 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2203 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2204 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2205 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2206 | __ subl(ESP, Immediate(adjustment)); |
| 2207 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2208 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2209 | // Load the value to the FP stack, using temporaries if needed. |
| 2210 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2211 | |
| 2212 | if (out.IsStackSlot()) { |
| 2213 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2214 | } else { |
| 2215 | __ fstps(Address(ESP, 0)); |
| 2216 | Location stack_temp = Location::StackSlot(0); |
| 2217 | codegen_->Move32(out, stack_temp); |
| 2218 | } |
| 2219 | |
| 2220 | // Remove the temporary stack space we allocated. |
| 2221 | if (adjustment != 0) { |
| 2222 | __ addl(ESP, Immediate(adjustment)); |
| 2223 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | } |
| 2226 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2227 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2228 | // Processing a Dex `double-to-float' instruction. |
| 2229 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | |
| 2232 | default: |
| 2233 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2234 | << " to " << result_type; |
| 2235 | }; |
| 2236 | break; |
| 2237 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2238 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2239 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2240 | case Primitive::kPrimBoolean: |
| 2241 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2242 | case Primitive::kPrimByte: |
| 2243 | case Primitive::kPrimShort: |
| 2244 | case Primitive::kPrimInt: |
| 2245 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2246 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2247 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2248 | break; |
| 2249 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2250 | case Primitive::kPrimLong: { |
| 2251 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2252 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2253 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2254 | // Create stack space for the call to |
| 2255 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2256 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2257 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2258 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2259 | __ subl(ESP, Immediate(adjustment)); |
| 2260 | } |
| 2261 | |
| 2262 | // Load the value to the FP stack, using temporaries if needed. |
| 2263 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2264 | |
| 2265 | if (out.IsDoubleStackSlot()) { |
| 2266 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2267 | } else { |
| 2268 | __ fstpl(Address(ESP, 0)); |
| 2269 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2270 | codegen_->Move64(out, stack_temp); |
| 2271 | } |
| 2272 | |
| 2273 | // Remove the temporary stack space we allocated. |
| 2274 | if (adjustment != 0) { |
| 2275 | __ addl(ESP, Immediate(adjustment)); |
| 2276 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2277 | break; |
| 2278 | } |
| 2279 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2281 | // Processing a Dex `float-to-double' instruction. |
| 2282 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2283 | break; |
| 2284 | |
| 2285 | default: |
| 2286 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2287 | << " to " << result_type; |
| 2288 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2289 | break; |
| 2290 | |
| 2291 | default: |
| 2292 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2293 | << " to " << result_type; |
| 2294 | } |
| 2295 | } |
| 2296 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2297 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2298 | LocationSummary* locations = |
| 2299 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2300 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2301 | case Primitive::kPrimInt: { |
| 2302 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2303 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2304 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2305 | break; |
| 2306 | } |
| 2307 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2308 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2309 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2310 | locations->SetInAt(1, Location::Any()); |
| 2311 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2312 | break; |
| 2313 | } |
| 2314 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2315 | case Primitive::kPrimFloat: |
| 2316 | case Primitive::kPrimDouble: { |
| 2317 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2318 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2319 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2320 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2321 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2322 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2323 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2324 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2325 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2326 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2330 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2331 | Location first = locations->InAt(0); |
| 2332 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2333 | Location out = locations->Out(); |
| 2334 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2335 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2336 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2337 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2338 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2339 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2340 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2341 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2342 | } else { |
| 2343 | __ leal(out.AsRegister<Register>(), Address( |
| 2344 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2345 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2346 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2347 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2348 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2349 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2350 | } else { |
| 2351 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2352 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2353 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2354 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2355 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2356 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2357 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2361 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2362 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2363 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2364 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2365 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2366 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2367 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2368 | } else { |
| 2369 | DCHECK(second.IsConstant()) << second; |
| 2370 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2371 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2372 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2373 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2374 | break; |
| 2375 | } |
| 2376 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2377 | case Primitive::kPrimFloat: { |
| 2378 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2379 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2380 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2381 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2382 | DCHECK(!const_area->NeedsMaterialization()); |
| 2383 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2384 | codegen_->LiteralFloatAddress( |
| 2385 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2386 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2387 | } else { |
| 2388 | DCHECK(second.IsStackSlot()); |
| 2389 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2390 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2391 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | case Primitive::kPrimDouble: { |
| 2395 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2396 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2397 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2398 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2399 | DCHECK(!const_area->NeedsMaterialization()); |
| 2400 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2401 | codegen_->LiteralDoubleAddress( |
| 2402 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2403 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2404 | } else { |
| 2405 | DCHECK(second.IsDoubleStackSlot()); |
| 2406 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2407 | } |
| 2408 | break; |
| 2409 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2410 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2411 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2412 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2413 | } |
| 2414 | } |
| 2415 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2416 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2417 | LocationSummary* locations = |
| 2418 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2419 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2420 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2421 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2422 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2423 | locations->SetInAt(1, Location::Any()); |
| 2424 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2425 | break; |
| 2426 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2427 | case Primitive::kPrimFloat: |
| 2428 | case Primitive::kPrimDouble: { |
| 2429 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2430 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2431 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2432 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2433 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2434 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2435 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2436 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2437 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2441 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2442 | Location first = locations->InAt(0); |
| 2443 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2444 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2445 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2446 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2447 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2448 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2449 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2450 | __ subl(first.AsRegister<Register>(), |
| 2451 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2452 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2453 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2454 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2455 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2459 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2460 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2461 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2462 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2463 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2464 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2465 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2466 | } else { |
| 2467 | DCHECK(second.IsConstant()) << second; |
| 2468 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2469 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2470 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2471 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2472 | break; |
| 2473 | } |
| 2474 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2475 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2476 | if (second.IsFpuRegister()) { |
| 2477 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2478 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2479 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2480 | DCHECK(!const_area->NeedsMaterialization()); |
| 2481 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2482 | codegen_->LiteralFloatAddress( |
| 2483 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2484 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2485 | } else { |
| 2486 | DCHECK(second.IsStackSlot()); |
| 2487 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2488 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2489 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2493 | if (second.IsFpuRegister()) { |
| 2494 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2495 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2496 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2497 | DCHECK(!const_area->NeedsMaterialization()); |
| 2498 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2499 | codegen_->LiteralDoubleAddress( |
| 2500 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2501 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2502 | } else { |
| 2503 | DCHECK(second.IsDoubleStackSlot()); |
| 2504 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2505 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2506 | break; |
| 2507 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2508 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2509 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2510 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2511 | } |
| 2512 | } |
| 2513 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2514 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2515 | LocationSummary* locations = |
| 2516 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2517 | switch (mul->GetResultType()) { |
| 2518 | case Primitive::kPrimInt: |
| 2519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2520 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2521 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2522 | // Can use 3 operand multiply. |
| 2523 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2524 | } else { |
| 2525 | locations->SetOut(Location::SameAsFirstInput()); |
| 2526 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2527 | break; |
| 2528 | case Primitive::kPrimLong: { |
| 2529 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2530 | locations->SetInAt(1, Location::Any()); |
| 2531 | locations->SetOut(Location::SameAsFirstInput()); |
| 2532 | // Needed for imul on 32bits with 64bits output. |
| 2533 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2534 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2535 | break; |
| 2536 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2537 | case Primitive::kPrimFloat: |
| 2538 | case Primitive::kPrimDouble: { |
| 2539 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2540 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2541 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2542 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2543 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2544 | |
| 2545 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2546 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2551 | LocationSummary* locations = mul->GetLocations(); |
| 2552 | Location first = locations->InAt(0); |
| 2553 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2554 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2555 | |
| 2556 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2557 | case Primitive::kPrimInt: |
| 2558 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2559 | // problems where the output may not be the same as the first operand. |
| 2560 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2561 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2562 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2563 | } else if (second.IsRegister()) { |
| 2564 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2565 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2566 | } else { |
| 2567 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2568 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2569 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2570 | } |
| 2571 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2572 | |
| 2573 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2574 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2575 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2576 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2577 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2578 | |
| 2579 | DCHECK_EQ(EAX, eax); |
| 2580 | DCHECK_EQ(EDX, edx); |
| 2581 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2582 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2583 | // output: in1 |
| 2584 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2585 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2586 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2587 | if (second.IsConstant()) { |
| 2588 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2589 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2590 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2591 | int32_t low_value = Low32Bits(value); |
| 2592 | int32_t high_value = High32Bits(value); |
| 2593 | Immediate low(low_value); |
| 2594 | Immediate high(high_value); |
| 2595 | |
| 2596 | __ movl(eax, high); |
| 2597 | // eax <- in1.lo * in2.hi |
| 2598 | __ imull(eax, in1_lo); |
| 2599 | // in1.hi <- in1.hi * in2.lo |
| 2600 | __ imull(in1_hi, low); |
| 2601 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2602 | __ addl(in1_hi, eax); |
| 2603 | // move in2_lo to eax to prepare for double precision |
| 2604 | __ movl(eax, low); |
| 2605 | // edx:eax <- in1.lo * in2.lo |
| 2606 | __ mull(in1_lo); |
| 2607 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2608 | __ addl(in1_hi, edx); |
| 2609 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2610 | __ movl(in1_lo, eax); |
| 2611 | } else if (second.IsRegisterPair()) { |
| 2612 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2613 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2614 | |
| 2615 | __ movl(eax, in2_hi); |
| 2616 | // eax <- in1.lo * in2.hi |
| 2617 | __ imull(eax, in1_lo); |
| 2618 | // in1.hi <- in1.hi * in2.lo |
| 2619 | __ imull(in1_hi, in2_lo); |
| 2620 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2621 | __ addl(in1_hi, eax); |
| 2622 | // move in1_lo to eax to prepare for double precision |
| 2623 | __ movl(eax, in1_lo); |
| 2624 | // edx:eax <- in1.lo * in2.lo |
| 2625 | __ mull(in2_lo); |
| 2626 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2627 | __ addl(in1_hi, edx); |
| 2628 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2629 | __ movl(in1_lo, eax); |
| 2630 | } else { |
| 2631 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2632 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2633 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2634 | |
| 2635 | __ movl(eax, in2_hi); |
| 2636 | // eax <- in1.lo * in2.hi |
| 2637 | __ imull(eax, in1_lo); |
| 2638 | // in1.hi <- in1.hi * in2.lo |
| 2639 | __ imull(in1_hi, in2_lo); |
| 2640 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2641 | __ addl(in1_hi, eax); |
| 2642 | // move in1_lo to eax to prepare for double precision |
| 2643 | __ movl(eax, in1_lo); |
| 2644 | // edx:eax <- in1.lo * in2.lo |
| 2645 | __ mull(in2_lo); |
| 2646 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2647 | __ addl(in1_hi, edx); |
| 2648 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2649 | __ movl(in1_lo, eax); |
| 2650 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2651 | |
| 2652 | break; |
| 2653 | } |
| 2654 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2655 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2656 | DCHECK(first.Equals(locations->Out())); |
| 2657 | if (second.IsFpuRegister()) { |
| 2658 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2659 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2660 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2661 | DCHECK(!const_area->NeedsMaterialization()); |
| 2662 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2663 | codegen_->LiteralFloatAddress( |
| 2664 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2665 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2666 | } else { |
| 2667 | DCHECK(second.IsStackSlot()); |
| 2668 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2669 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2670 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2674 | DCHECK(first.Equals(locations->Out())); |
| 2675 | if (second.IsFpuRegister()) { |
| 2676 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2677 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2678 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2679 | DCHECK(!const_area->NeedsMaterialization()); |
| 2680 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2681 | codegen_->LiteralDoubleAddress( |
| 2682 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2683 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2684 | } else { |
| 2685 | DCHECK(second.IsDoubleStackSlot()); |
| 2686 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2687 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2688 | break; |
| 2689 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2690 | |
| 2691 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2692 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2693 | } |
| 2694 | } |
| 2695 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2696 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2697 | uint32_t temp_offset, |
| 2698 | uint32_t stack_adjustment, |
| 2699 | bool is_fp, |
| 2700 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2701 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2702 | DCHECK(!is_wide); |
| 2703 | if (is_fp) { |
| 2704 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2705 | } else { |
| 2706 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2707 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2708 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2709 | DCHECK(is_wide); |
| 2710 | if (is_fp) { |
| 2711 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2712 | } else { |
| 2713 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2714 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2715 | } else { |
| 2716 | // 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] | 2717 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2718 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2719 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2720 | if (is_fp) { |
| 2721 | __ flds(Address(ESP, temp_offset)); |
| 2722 | } else { |
| 2723 | __ filds(Address(ESP, temp_offset)); |
| 2724 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2725 | } else { |
| 2726 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2727 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2728 | if (is_fp) { |
| 2729 | __ fldl(Address(ESP, temp_offset)); |
| 2730 | } else { |
| 2731 | __ fildl(Address(ESP, temp_offset)); |
| 2732 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2733 | } |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2738 | Primitive::Type type = rem->GetResultType(); |
| 2739 | bool is_float = type == Primitive::kPrimFloat; |
| 2740 | size_t elem_size = Primitive::ComponentSize(type); |
| 2741 | LocationSummary* locations = rem->GetLocations(); |
| 2742 | Location first = locations->InAt(0); |
| 2743 | Location second = locations->InAt(1); |
| 2744 | Location out = locations->Out(); |
| 2745 | |
| 2746 | // Create stack space for 2 elements. |
| 2747 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2748 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2749 | |
| 2750 | // 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] | 2751 | const bool is_wide = !is_float; |
| 2752 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2753 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2754 | |
| 2755 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2756 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2757 | __ Bind(&retry); |
| 2758 | __ fprem(); |
| 2759 | |
| 2760 | // Move FP status to AX. |
| 2761 | __ fstsw(); |
| 2762 | |
| 2763 | // And see if the argument reduction is complete. This is signaled by the |
| 2764 | // C2 FPU flag bit set to 0. |
| 2765 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2766 | __ j(kNotEqual, &retry); |
| 2767 | |
| 2768 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2769 | // Store FP top of stack to real stack. |
| 2770 | if (is_float) { |
| 2771 | __ fsts(Address(ESP, 0)); |
| 2772 | } else { |
| 2773 | __ fstl(Address(ESP, 0)); |
| 2774 | } |
| 2775 | |
| 2776 | // Pop the 2 items from the FP stack. |
| 2777 | __ fucompp(); |
| 2778 | |
| 2779 | // Load the value from the stack into an XMM register. |
| 2780 | DCHECK(out.IsFpuRegister()) << out; |
| 2781 | if (is_float) { |
| 2782 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2783 | } else { |
| 2784 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2785 | } |
| 2786 | |
| 2787 | // And remove the temporary stack space we allocated. |
| 2788 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2789 | } |
| 2790 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2791 | |
| 2792 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2793 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2794 | |
| 2795 | LocationSummary* locations = instruction->GetLocations(); |
| 2796 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2797 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2798 | |
| 2799 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2800 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2801 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2802 | |
| 2803 | DCHECK(imm == 1 || imm == -1); |
| 2804 | |
| 2805 | if (instruction->IsRem()) { |
| 2806 | __ xorl(out_register, out_register); |
| 2807 | } else { |
| 2808 | __ movl(out_register, input_register); |
| 2809 | if (imm == -1) { |
| 2810 | __ negl(out_register); |
| 2811 | } |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2816 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2817 | LocationSummary* locations = instruction->GetLocations(); |
| 2818 | |
| 2819 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2820 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2821 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2822 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2823 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2824 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2825 | |
| 2826 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2827 | __ testl(input_register, input_register); |
| 2828 | __ cmovl(kGreaterEqual, num, input_register); |
| 2829 | int shift = CTZ(imm); |
| 2830 | __ sarl(num, Immediate(shift)); |
| 2831 | |
| 2832 | if (imm < 0) { |
| 2833 | __ negl(num); |
| 2834 | } |
| 2835 | |
| 2836 | __ movl(out_register, num); |
| 2837 | } |
| 2838 | |
| 2839 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2840 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2841 | |
| 2842 | LocationSummary* locations = instruction->GetLocations(); |
| 2843 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2844 | |
| 2845 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2846 | Register out = locations->Out().AsRegister<Register>(); |
| 2847 | Register num; |
| 2848 | Register edx; |
| 2849 | |
| 2850 | if (instruction->IsDiv()) { |
| 2851 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2852 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2853 | } else { |
| 2854 | edx = locations->Out().AsRegister<Register>(); |
| 2855 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2856 | } |
| 2857 | |
| 2858 | DCHECK_EQ(EAX, eax); |
| 2859 | DCHECK_EQ(EDX, edx); |
| 2860 | if (instruction->IsDiv()) { |
| 2861 | DCHECK_EQ(EAX, out); |
| 2862 | } else { |
| 2863 | DCHECK_EQ(EDX, out); |
| 2864 | } |
| 2865 | |
| 2866 | int64_t magic; |
| 2867 | int shift; |
| 2868 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2869 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2870 | NearLabel ndiv; |
| 2871 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2872 | // If numerator is 0, the result is 0, no computation needed. |
| 2873 | __ testl(eax, eax); |
| 2874 | __ j(kNotEqual, &ndiv); |
| 2875 | |
| 2876 | __ xorl(out, out); |
| 2877 | __ jmp(&end); |
| 2878 | |
| 2879 | __ Bind(&ndiv); |
| 2880 | |
| 2881 | // Save the numerator. |
| 2882 | __ movl(num, eax); |
| 2883 | |
| 2884 | // EAX = magic |
| 2885 | __ movl(eax, Immediate(magic)); |
| 2886 | |
| 2887 | // EDX:EAX = magic * numerator |
| 2888 | __ imull(num); |
| 2889 | |
| 2890 | if (imm > 0 && magic < 0) { |
| 2891 | // EDX += num |
| 2892 | __ addl(edx, num); |
| 2893 | } else if (imm < 0 && magic > 0) { |
| 2894 | __ subl(edx, num); |
| 2895 | } |
| 2896 | |
| 2897 | // Shift if needed. |
| 2898 | if (shift != 0) { |
| 2899 | __ sarl(edx, Immediate(shift)); |
| 2900 | } |
| 2901 | |
| 2902 | // EDX += 1 if EDX < 0 |
| 2903 | __ movl(eax, edx); |
| 2904 | __ shrl(edx, Immediate(31)); |
| 2905 | __ addl(edx, eax); |
| 2906 | |
| 2907 | if (instruction->IsRem()) { |
| 2908 | __ movl(eax, num); |
| 2909 | __ imull(edx, Immediate(imm)); |
| 2910 | __ subl(eax, edx); |
| 2911 | __ movl(edx, eax); |
| 2912 | } else { |
| 2913 | __ movl(eax, edx); |
| 2914 | } |
| 2915 | __ Bind(&end); |
| 2916 | } |
| 2917 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2918 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2919 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2920 | |
| 2921 | LocationSummary* locations = instruction->GetLocations(); |
| 2922 | Location out = locations->Out(); |
| 2923 | Location first = locations->InAt(0); |
| 2924 | Location second = locations->InAt(1); |
| 2925 | bool is_div = instruction->IsDiv(); |
| 2926 | |
| 2927 | switch (instruction->GetResultType()) { |
| 2928 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2929 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2930 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2931 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2932 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2933 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2934 | |
| 2935 | if (imm == 0) { |
| 2936 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2937 | } else if (imm == 1 || imm == -1) { |
| 2938 | DivRemOneOrMinusOne(instruction); |
| 2939 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2940 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2941 | } else { |
| 2942 | DCHECK(imm <= -2 || imm >= 2); |
| 2943 | GenerateDivRemWithAnyConstant(instruction); |
| 2944 | } |
| 2945 | } else { |
| 2946 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2947 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2948 | is_div); |
| 2949 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2950 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2951 | Register second_reg = second.AsRegister<Register>(); |
| 2952 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2953 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2954 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2955 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2956 | __ cmpl(second_reg, Immediate(-1)); |
| 2957 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2958 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2959 | // edx:eax <- sign-extended of eax |
| 2960 | __ cdq(); |
| 2961 | // eax = quotient, edx = remainder |
| 2962 | __ idivl(second_reg); |
| 2963 | __ Bind(slow_path->GetExitLabel()); |
| 2964 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2965 | break; |
| 2966 | } |
| 2967 | |
| 2968 | case Primitive::kPrimLong: { |
| 2969 | InvokeRuntimeCallingConvention calling_convention; |
| 2970 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2971 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2972 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2973 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2974 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2975 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2976 | |
| 2977 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2978 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2979 | instruction, |
| 2980 | instruction->GetDexPc(), |
| 2981 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2982 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2983 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2984 | instruction, |
| 2985 | instruction->GetDexPc(), |
| 2986 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2987 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2988 | break; |
| 2989 | } |
| 2990 | |
| 2991 | default: |
| 2992 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2993 | } |
| 2994 | } |
| 2995 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2996 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2997 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2998 | ? LocationSummary::kCall |
| 2999 | : LocationSummary::kNoCall; |
| 3000 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3001 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3002 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3003 | case Primitive::kPrimInt: { |
| 3004 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3005 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3006 | locations->SetOut(Location::SameAsFirstInput()); |
| 3007 | // Intel uses edx:eax as the dividend. |
| 3008 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3009 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3010 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3011 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3012 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3013 | locations->AddTemp(Location::RequiresRegister()); |
| 3014 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3015 | break; |
| 3016 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3017 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3018 | InvokeRuntimeCallingConvention calling_convention; |
| 3019 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3020 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3021 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3022 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3023 | // Runtime helper puts the result in EAX, EDX. |
| 3024 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3025 | break; |
| 3026 | } |
| 3027 | case Primitive::kPrimFloat: |
| 3028 | case Primitive::kPrimDouble: { |
| 3029 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3030 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3031 | locations->SetOut(Location::SameAsFirstInput()); |
| 3032 | break; |
| 3033 | } |
| 3034 | |
| 3035 | default: |
| 3036 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3041 | LocationSummary* locations = div->GetLocations(); |
| 3042 | Location first = locations->InAt(0); |
| 3043 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3044 | |
| 3045 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3046 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3047 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3048 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3049 | break; |
| 3050 | } |
| 3051 | |
| 3052 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3053 | if (second.IsFpuRegister()) { |
| 3054 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3055 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3056 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3057 | DCHECK(!const_area->NeedsMaterialization()); |
| 3058 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3059 | codegen_->LiteralFloatAddress( |
| 3060 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3061 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3062 | } else { |
| 3063 | DCHECK(second.IsStackSlot()); |
| 3064 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3065 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3066 | break; |
| 3067 | } |
| 3068 | |
| 3069 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3070 | if (second.IsFpuRegister()) { |
| 3071 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3072 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3073 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3074 | DCHECK(!const_area->NeedsMaterialization()); |
| 3075 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3076 | codegen_->LiteralDoubleAddress( |
| 3077 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3078 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3079 | } else { |
| 3080 | DCHECK(second.IsDoubleStackSlot()); |
| 3081 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3082 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3083 | break; |
| 3084 | } |
| 3085 | |
| 3086 | default: |
| 3087 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3088 | } |
| 3089 | } |
| 3090 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3091 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3092 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3093 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3094 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3095 | ? LocationSummary::kCall |
| 3096 | : LocationSummary::kNoCall; |
| 3097 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3098 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3099 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3100 | case Primitive::kPrimInt: { |
| 3101 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3102 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3103 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3104 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3105 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3106 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3107 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3108 | locations->AddTemp(Location::RequiresRegister()); |
| 3109 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3110 | break; |
| 3111 | } |
| 3112 | case Primitive::kPrimLong: { |
| 3113 | InvokeRuntimeCallingConvention calling_convention; |
| 3114 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3115 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3116 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3117 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3118 | // Runtime helper puts the result in EAX, EDX. |
| 3119 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3120 | break; |
| 3121 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3122 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3123 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3124 | locations->SetInAt(0, Location::Any()); |
| 3125 | locations->SetInAt(1, Location::Any()); |
| 3126 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3127 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3128 | break; |
| 3129 | } |
| 3130 | |
| 3131 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3132 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | |
| 3136 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3137 | Primitive::Type type = rem->GetResultType(); |
| 3138 | switch (type) { |
| 3139 | case Primitive::kPrimInt: |
| 3140 | case Primitive::kPrimLong: { |
| 3141 | GenerateDivRemIntegral(rem); |
| 3142 | break; |
| 3143 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3144 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3145 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3146 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3147 | break; |
| 3148 | } |
| 3149 | default: |
| 3150 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3151 | } |
| 3152 | } |
| 3153 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3154 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3155 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3156 | ? LocationSummary::kCallOnSlowPath |
| 3157 | : LocationSummary::kNoCall; |
| 3158 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3159 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3160 | case Primitive::kPrimByte: |
| 3161 | case Primitive::kPrimChar: |
| 3162 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3163 | case Primitive::kPrimInt: { |
| 3164 | locations->SetInAt(0, Location::Any()); |
| 3165 | break; |
| 3166 | } |
| 3167 | case Primitive::kPrimLong: { |
| 3168 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3169 | if (!instruction->IsConstant()) { |
| 3170 | locations->AddTemp(Location::RequiresRegister()); |
| 3171 | } |
| 3172 | break; |
| 3173 | } |
| 3174 | default: |
| 3175 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3176 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3177 | if (instruction->HasUses()) { |
| 3178 | locations->SetOut(Location::SameAsFirstInput()); |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3183 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 3184 | codegen_->AddSlowPath(slow_path); |
| 3185 | |
| 3186 | LocationSummary* locations = instruction->GetLocations(); |
| 3187 | Location value = locations->InAt(0); |
| 3188 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3189 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3190 | case Primitive::kPrimByte: |
| 3191 | case Primitive::kPrimChar: |
| 3192 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3193 | case Primitive::kPrimInt: { |
| 3194 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3195 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3196 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3197 | } else if (value.IsStackSlot()) { |
| 3198 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3199 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3200 | } else { |
| 3201 | DCHECK(value.IsConstant()) << value; |
| 3202 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3203 | __ jmp(slow_path->GetEntryLabel()); |
| 3204 | } |
| 3205 | } |
| 3206 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3207 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3208 | case Primitive::kPrimLong: { |
| 3209 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3210 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3211 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3212 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3213 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3214 | } else { |
| 3215 | DCHECK(value.IsConstant()) << value; |
| 3216 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3217 | __ jmp(slow_path->GetEntryLabel()); |
| 3218 | } |
| 3219 | } |
| 3220 | break; |
| 3221 | } |
| 3222 | default: |
| 3223 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3224 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3227 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3228 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3229 | |
| 3230 | LocationSummary* locations = |
| 3231 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3232 | |
| 3233 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3234 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3235 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3236 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3237 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3238 | // The shift count needs to be in CL or a constant. |
| 3239 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3240 | locations->SetOut(Location::SameAsFirstInput()); |
| 3241 | break; |
| 3242 | } |
| 3243 | default: |
| 3244 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3249 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3250 | |
| 3251 | LocationSummary* locations = op->GetLocations(); |
| 3252 | Location first = locations->InAt(0); |
| 3253 | Location second = locations->InAt(1); |
| 3254 | DCHECK(first.Equals(locations->Out())); |
| 3255 | |
| 3256 | switch (op->GetResultType()) { |
| 3257 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3258 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3259 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3260 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3261 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3262 | DCHECK_EQ(ECX, second_reg); |
| 3263 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3264 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3265 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3266 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3267 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3268 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3269 | } |
| 3270 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3271 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3272 | if (shift == 0) { |
| 3273 | return; |
| 3274 | } |
| 3275 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3276 | if (op->IsShl()) { |
| 3277 | __ shll(first_reg, imm); |
| 3278 | } else if (op->IsShr()) { |
| 3279 | __ sarl(first_reg, imm); |
| 3280 | } else { |
| 3281 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3282 | } |
| 3283 | } |
| 3284 | break; |
| 3285 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3286 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3287 | if (second.IsRegister()) { |
| 3288 | Register second_reg = second.AsRegister<Register>(); |
| 3289 | DCHECK_EQ(ECX, second_reg); |
| 3290 | if (op->IsShl()) { |
| 3291 | GenerateShlLong(first, second_reg); |
| 3292 | } else if (op->IsShr()) { |
| 3293 | GenerateShrLong(first, second_reg); |
| 3294 | } else { |
| 3295 | GenerateUShrLong(first, second_reg); |
| 3296 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3297 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3298 | // Shift by a constant. |
| 3299 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3300 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3301 | if (shift != 0) { |
| 3302 | if (op->IsShl()) { |
| 3303 | GenerateShlLong(first, shift); |
| 3304 | } else if (op->IsShr()) { |
| 3305 | GenerateShrLong(first, shift); |
| 3306 | } else { |
| 3307 | GenerateUShrLong(first, shift); |
| 3308 | } |
| 3309 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3310 | } |
| 3311 | break; |
| 3312 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3313 | default: |
| 3314 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3315 | } |
| 3316 | } |
| 3317 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3318 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3319 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3320 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3321 | if (shift == 1) { |
| 3322 | // This is just an addition. |
| 3323 | __ addl(low, low); |
| 3324 | __ adcl(high, high); |
| 3325 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3326 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3327 | codegen_->EmitParallelMoves( |
| 3328 | loc.ToLow(), |
| 3329 | loc.ToHigh(), |
| 3330 | Primitive::kPrimInt, |
| 3331 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3332 | loc.ToLow(), |
| 3333 | Primitive::kPrimInt); |
| 3334 | } else if (shift > 32) { |
| 3335 | // Low part becomes 0. High part is low part << (shift-32). |
| 3336 | __ movl(high, low); |
| 3337 | __ shll(high, Immediate(shift - 32)); |
| 3338 | __ xorl(low, low); |
| 3339 | } else { |
| 3340 | // Between 1 and 31. |
| 3341 | __ shld(high, low, Immediate(shift)); |
| 3342 | __ shll(low, Immediate(shift)); |
| 3343 | } |
| 3344 | } |
| 3345 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3346 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3347 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3348 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3349 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3350 | __ testl(shifter, Immediate(32)); |
| 3351 | __ j(kEqual, &done); |
| 3352 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3353 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3354 | __ Bind(&done); |
| 3355 | } |
| 3356 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3357 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3358 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3359 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3360 | if (shift == 32) { |
| 3361 | // Need to copy the sign. |
| 3362 | DCHECK_NE(low, high); |
| 3363 | __ movl(low, high); |
| 3364 | __ sarl(high, Immediate(31)); |
| 3365 | } else if (shift > 32) { |
| 3366 | DCHECK_NE(low, high); |
| 3367 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3368 | __ movl(low, high); |
| 3369 | __ sarl(high, Immediate(31)); |
| 3370 | __ sarl(low, Immediate(shift - 32)); |
| 3371 | } else { |
| 3372 | // Between 1 and 31. |
| 3373 | __ shrd(low, high, Immediate(shift)); |
| 3374 | __ sarl(high, Immediate(shift)); |
| 3375 | } |
| 3376 | } |
| 3377 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3378 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3379 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3380 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3381 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3382 | __ testl(shifter, Immediate(32)); |
| 3383 | __ j(kEqual, &done); |
| 3384 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3385 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3386 | __ Bind(&done); |
| 3387 | } |
| 3388 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3389 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3390 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3391 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3392 | if (shift == 32) { |
| 3393 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3394 | codegen_->EmitParallelMoves( |
| 3395 | loc.ToHigh(), |
| 3396 | loc.ToLow(), |
| 3397 | Primitive::kPrimInt, |
| 3398 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3399 | loc.ToHigh(), |
| 3400 | Primitive::kPrimInt); |
| 3401 | } else if (shift > 32) { |
| 3402 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3403 | __ movl(low, high); |
| 3404 | __ shrl(low, Immediate(shift - 32)); |
| 3405 | __ xorl(high, high); |
| 3406 | } else { |
| 3407 | // Between 1 and 31. |
| 3408 | __ shrd(low, high, Immediate(shift)); |
| 3409 | __ shrl(high, Immediate(shift)); |
| 3410 | } |
| 3411 | } |
| 3412 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3413 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3414 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3415 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3416 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3417 | __ testl(shifter, Immediate(32)); |
| 3418 | __ j(kEqual, &done); |
| 3419 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3420 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3421 | __ Bind(&done); |
| 3422 | } |
| 3423 | |
| 3424 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3425 | HandleShift(shl); |
| 3426 | } |
| 3427 | |
| 3428 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3429 | HandleShift(shl); |
| 3430 | } |
| 3431 | |
| 3432 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3433 | HandleShift(shr); |
| 3434 | } |
| 3435 | |
| 3436 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3437 | HandleShift(shr); |
| 3438 | } |
| 3439 | |
| 3440 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3441 | HandleShift(ushr); |
| 3442 | } |
| 3443 | |
| 3444 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3445 | HandleShift(ushr); |
| 3446 | } |
| 3447 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3448 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3449 | LocationSummary* locations = |
| 3450 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3451 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3452 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3453 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3454 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3458 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3459 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3460 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3461 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3462 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3463 | instruction, |
| 3464 | instruction->GetDexPc(), |
| 3465 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3466 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3467 | } |
| 3468 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3469 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3470 | LocationSummary* locations = |
| 3471 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3472 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3473 | InvokeRuntimeCallingConvention calling_convention; |
| 3474 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3475 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3476 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3480 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3481 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3482 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3483 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3484 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3485 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3486 | instruction, |
| 3487 | instruction->GetDexPc(), |
| 3488 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3489 | DCHECK(!codegen_->IsLeafMethod()); |
| 3490 | } |
| 3491 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3492 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3493 | LocationSummary* locations = |
| 3494 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3495 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3496 | if (location.IsStackSlot()) { |
| 3497 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3498 | } else if (location.IsDoubleStackSlot()) { |
| 3499 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3500 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3501 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3502 | } |
| 3503 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3504 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3505 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3506 | } |
| 3507 | |
| 3508 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3509 | LocationSummary* locations = |
| 3510 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3511 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3512 | } |
| 3513 | |
| 3514 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3517 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3518 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3519 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3520 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3521 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3522 | } |
| 3523 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3524 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3525 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3526 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3527 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3528 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3529 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3530 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3531 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3532 | break; |
| 3533 | |
| 3534 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3535 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3536 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3537 | break; |
| 3538 | |
| 3539 | default: |
| 3540 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3541 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3542 | } |
| 3543 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3544 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3545 | LocationSummary* locations = |
| 3546 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3547 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3548 | locations->SetOut(Location::SameAsFirstInput()); |
| 3549 | } |
| 3550 | |
| 3551 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3552 | LocationSummary* locations = bool_not->GetLocations(); |
| 3553 | Location in = locations->InAt(0); |
| 3554 | Location out = locations->Out(); |
| 3555 | DCHECK(in.Equals(out)); |
| 3556 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3557 | } |
| 3558 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3559 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3560 | LocationSummary* locations = |
| 3561 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3562 | switch (compare->InputAt(0)->GetType()) { |
| 3563 | case Primitive::kPrimLong: { |
| 3564 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3565 | locations->SetInAt(1, Location::Any()); |
| 3566 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3567 | break; |
| 3568 | } |
| 3569 | case Primitive::kPrimFloat: |
| 3570 | case Primitive::kPrimDouble: { |
| 3571 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3572 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3573 | locations->SetOut(Location::RequiresRegister()); |
| 3574 | break; |
| 3575 | } |
| 3576 | default: |
| 3577 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3578 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3582 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3583 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3584 | Location left = locations->InAt(0); |
| 3585 | Location right = locations->InAt(1); |
| 3586 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3587 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3588 | switch (compare->InputAt(0)->GetType()) { |
| 3589 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3590 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3591 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3592 | int32_t val_low = 0; |
| 3593 | int32_t val_high = 0; |
| 3594 | bool right_is_const = false; |
| 3595 | |
| 3596 | if (right.IsConstant()) { |
| 3597 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3598 | right_is_const = true; |
| 3599 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3600 | val_low = Low32Bits(val); |
| 3601 | val_high = High32Bits(val); |
| 3602 | } |
| 3603 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3604 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3605 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3606 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3607 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3608 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3609 | DCHECK(right_is_const) << right; |
| 3610 | if (val_high == 0) { |
| 3611 | __ testl(left_high, left_high); |
| 3612 | } else { |
| 3613 | __ cmpl(left_high, Immediate(val_high)); |
| 3614 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3615 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3616 | __ j(kLess, &less); // Signed compare. |
| 3617 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3618 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3619 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3620 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3621 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3622 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3623 | DCHECK(right_is_const) << right; |
| 3624 | if (val_low == 0) { |
| 3625 | __ testl(left_low, left_low); |
| 3626 | } else { |
| 3627 | __ cmpl(left_low, Immediate(val_low)); |
| 3628 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3629 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3630 | break; |
| 3631 | } |
| 3632 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3633 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3634 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3635 | break; |
| 3636 | } |
| 3637 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3638 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3639 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3640 | break; |
| 3641 | } |
| 3642 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3643 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3644 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3645 | __ movl(out, Immediate(0)); |
| 3646 | __ j(kEqual, &done); |
| 3647 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3648 | |
| 3649 | __ Bind(&greater); |
| 3650 | __ movl(out, Immediate(1)); |
| 3651 | __ jmp(&done); |
| 3652 | |
| 3653 | __ Bind(&less); |
| 3654 | __ movl(out, Immediate(-1)); |
| 3655 | |
| 3656 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3657 | } |
| 3658 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3659 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3660 | LocationSummary* locations = |
| 3661 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3662 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3663 | locations->SetInAt(i, Location::Any()); |
| 3664 | } |
| 3665 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3669 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3670 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3671 | } |
| 3672 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3673 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3674 | /* |
| 3675 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3676 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3677 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3678 | */ |
| 3679 | switch (kind) { |
| 3680 | case MemBarrierKind::kAnyAny: { |
| 3681 | __ mfence(); |
| 3682 | break; |
| 3683 | } |
| 3684 | case MemBarrierKind::kAnyStore: |
| 3685 | case MemBarrierKind::kLoadAny: |
| 3686 | case MemBarrierKind::kStoreStore: { |
| 3687 | // nop |
| 3688 | break; |
| 3689 | } |
| 3690 | default: |
| 3691 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3692 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3693 | } |
| 3694 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3695 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3696 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3697 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3698 | switch (invoke->GetMethodLoadKind()) { |
| 3699 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3700 | // temp = thread->string_init_entrypoint |
| 3701 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3702 | break; |
| 3703 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3704 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3705 | break; |
| 3706 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3707 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3708 | break; |
| 3709 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3710 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3711 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3712 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3713 | break; |
| 3714 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3715 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3716 | FALLTHROUGH_INTENDED; |
| 3717 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3718 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3719 | Register method_reg; |
| 3720 | Register reg = temp.AsRegister<Register>(); |
| 3721 | if (current_method.IsRegister()) { |
| 3722 | method_reg = current_method.AsRegister<Register>(); |
| 3723 | } else { |
| 3724 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3725 | DCHECK(!current_method.IsValid()); |
| 3726 | method_reg = reg; |
| 3727 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3728 | } |
| 3729 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3730 | __ movl(reg, Address(method_reg, |
| 3731 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3732 | // temp = temp[index_in_cache] |
| 3733 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3734 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3735 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3736 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | switch (invoke->GetCodePtrLocation()) { |
| 3740 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3741 | __ call(GetFrameEntryLabel()); |
| 3742 | break; |
| 3743 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3744 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3745 | Label* label = &relative_call_patches_.back().label; |
| 3746 | __ call(label); // Bind to the patch label, override at link time. |
| 3747 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3748 | break; |
| 3749 | } |
| 3750 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3751 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3752 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3753 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3754 | FALLTHROUGH_INTENDED; |
| 3755 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3756 | // (callee_method + offset_of_quick_compiled_code)() |
| 3757 | __ call(Address(callee_method.AsRegister<Register>(), |
| 3758 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3759 | kX86WordSize).Int32Value())); |
| 3760 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3764 | } |
| 3765 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3766 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 3767 | Register temp = temp_in.AsRegister<Register>(); |
| 3768 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3769 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| 3770 | LocationSummary* locations = invoke->GetLocations(); |
| 3771 | Location receiver = locations->InAt(0); |
| 3772 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3773 | // temp = object->GetClass(); |
| 3774 | DCHECK(receiver.IsRegister()); |
| 3775 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| 3776 | MaybeRecordImplicitNullCheck(invoke); |
| 3777 | __ MaybeUnpoisonHeapReference(temp); |
| 3778 | // temp = temp->GetMethodAt(method_offset); |
| 3779 | __ movl(temp, Address(temp, method_offset)); |
| 3780 | // call temp->GetEntryPoint(); |
| 3781 | __ call(Address( |
| 3782 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3783 | } |
| 3784 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3785 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3786 | DCHECK(linker_patches->empty()); |
| 3787 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3788 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3789 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3790 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3791 | uint32_t literal_offset = info.label.Position() - 4; |
| 3792 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3793 | info.target_method.dex_file, |
| 3794 | info.target_method.dex_method_index)); |
| 3795 | } |
| 3796 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3797 | // The label points to the end of the "call" insn but the literal offset for method |
| 3798 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3799 | uint32_t literal_offset = info.label.Position() - 4; |
| 3800 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3801 | info.target_method.dex_file, |
| 3802 | info.target_method.dex_method_index)); |
| 3803 | } |
| 3804 | } |
| 3805 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3806 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3807 | Register card, |
| 3808 | Register object, |
| 3809 | Register value, |
| 3810 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3811 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3812 | if (value_can_be_null) { |
| 3813 | __ testl(value, value); |
| 3814 | __ j(kEqual, &is_null); |
| 3815 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3816 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3817 | __ movl(temp, object); |
| 3818 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3819 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3820 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3821 | if (value_can_be_null) { |
| 3822 | __ Bind(&is_null); |
| 3823 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3824 | } |
| 3825 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3826 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3827 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3828 | LocationSummary* locations = |
| 3829 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3830 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3831 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3832 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3833 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3834 | } else { |
| 3835 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3836 | // the object's location. |
| 3837 | locations->SetOut(Location::RequiresRegister(), |
| 3838 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3839 | : Location::kNoOutputOverlap); |
| 3840 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3841 | |
| 3842 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3843 | // Long values can be loaded atomically into an XMM using movsd. |
| 3844 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3845 | // and then copy the XMM into the output 32bits at a time). |
| 3846 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3847 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3848 | } |
| 3849 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3850 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3851 | const FieldInfo& field_info) { |
| 3852 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3853 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3854 | LocationSummary* locations = instruction->GetLocations(); |
| 3855 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3856 | Location out = locations->Out(); |
| 3857 | bool is_volatile = field_info.IsVolatile(); |
| 3858 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3859 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3860 | |
| 3861 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3862 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3863 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3864 | break; |
| 3865 | } |
| 3866 | |
| 3867 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3868 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3869 | break; |
| 3870 | } |
| 3871 | |
| 3872 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3873 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3874 | break; |
| 3875 | } |
| 3876 | |
| 3877 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3878 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3879 | break; |
| 3880 | } |
| 3881 | |
| 3882 | case Primitive::kPrimInt: |
| 3883 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3884 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3885 | break; |
| 3886 | } |
| 3887 | |
| 3888 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3889 | if (is_volatile) { |
| 3890 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3891 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3892 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3893 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3894 | __ psrlq(temp, Immediate(32)); |
| 3895 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3896 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3897 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3898 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3899 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3900 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3901 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3902 | break; |
| 3903 | } |
| 3904 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3905 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3906 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3907 | break; |
| 3908 | } |
| 3909 | |
| 3910 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3911 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3912 | break; |
| 3913 | } |
| 3914 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3915 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3916 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3917 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3918 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3919 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3920 | // Longs are handled in the switch. |
| 3921 | if (field_type != Primitive::kPrimLong) { |
| 3922 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3923 | } |
| 3924 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3925 | if (is_volatile) { |
| 3926 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3927 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3928 | |
| 3929 | if (field_type == Primitive::kPrimNot) { |
| 3930 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3931 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3935 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3936 | |
| 3937 | LocationSummary* locations = |
| 3938 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3939 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3940 | bool is_volatile = field_info.IsVolatile(); |
| 3941 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3942 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3943 | || (field_type == Primitive::kPrimByte); |
| 3944 | |
| 3945 | // The register allocator does not support multiple |
| 3946 | // inputs that die at entry with one in a specific register. |
| 3947 | if (is_byte_type) { |
| 3948 | // Ensure the value is in a byte register. |
| 3949 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3950 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3951 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3952 | } else { |
| 3953 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3954 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3955 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3956 | // Temporary registers for the write barrier. |
| 3957 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3958 | // Ensure the card is in a byte register. |
| 3959 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3960 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3961 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3962 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3963 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3964 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3965 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3966 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3967 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3972 | const FieldInfo& field_info, |
| 3973 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3974 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3975 | |
| 3976 | LocationSummary* locations = instruction->GetLocations(); |
| 3977 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3978 | Location value = locations->InAt(1); |
| 3979 | bool is_volatile = field_info.IsVolatile(); |
| 3980 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3981 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3982 | bool needs_write_barrier = |
| 3983 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3984 | |
| 3985 | if (is_volatile) { |
| 3986 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3987 | } |
| 3988 | |
| 3989 | switch (field_type) { |
| 3990 | case Primitive::kPrimBoolean: |
| 3991 | case Primitive::kPrimByte: { |
| 3992 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3993 | break; |
| 3994 | } |
| 3995 | |
| 3996 | case Primitive::kPrimShort: |
| 3997 | case Primitive::kPrimChar: { |
| 3998 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3999 | break; |
| 4000 | } |
| 4001 | |
| 4002 | case Primitive::kPrimInt: |
| 4003 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4004 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4005 | // Note that in the case where `value` is a null reference, |
| 4006 | // we do not enter this block, as the reference does not |
| 4007 | // need poisoning. |
| 4008 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4009 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4010 | __ movl(temp, value.AsRegister<Register>()); |
| 4011 | __ PoisonHeapReference(temp); |
| 4012 | __ movl(Address(base, offset), temp); |
| 4013 | } else { |
| 4014 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4015 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4016 | break; |
| 4017 | } |
| 4018 | |
| 4019 | case Primitive::kPrimLong: { |
| 4020 | if (is_volatile) { |
| 4021 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4022 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4023 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4024 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4025 | __ punpckldq(temp1, temp2); |
| 4026 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4027 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4028 | } else { |
| 4029 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4030 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4031 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4032 | } |
| 4033 | break; |
| 4034 | } |
| 4035 | |
| 4036 | case Primitive::kPrimFloat: { |
| 4037 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4038 | break; |
| 4039 | } |
| 4040 | |
| 4041 | case Primitive::kPrimDouble: { |
| 4042 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4043 | break; |
| 4044 | } |
| 4045 | |
| 4046 | case Primitive::kPrimVoid: |
| 4047 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4048 | UNREACHABLE(); |
| 4049 | } |
| 4050 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4051 | // Longs are handled in the switch. |
| 4052 | if (field_type != Primitive::kPrimLong) { |
| 4053 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4054 | } |
| 4055 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4056 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4057 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4058 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4059 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4060 | } |
| 4061 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4062 | if (is_volatile) { |
| 4063 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4068 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4069 | } |
| 4070 | |
| 4071 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4072 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4073 | } |
| 4074 | |
| 4075 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4076 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4077 | } |
| 4078 | |
| 4079 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4080 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4084 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4085 | } |
| 4086 | |
| 4087 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4088 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
| 4091 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4092 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4093 | } |
| 4094 | |
| 4095 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4096 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4097 | } |
| 4098 | |
Calin Juravle | 23a8e35 | 2015-09-08 19:56:31 +0100 | [diff] [blame] | 4099 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4100 | HUnresolvedInstanceFieldGet* instruction) { |
| 4101 | FieldAccessCallingConvetionX86 calling_convention; |
| 4102 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4103 | instruction, instruction->GetFieldType(), calling_convention); |
| 4104 | } |
| 4105 | |
| 4106 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4107 | HUnresolvedInstanceFieldGet* instruction) { |
| 4108 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4109 | instruction->GetFieldType(), |
| 4110 | instruction->GetFieldIndex(), |
| 4111 | instruction->GetDexPc()); |
| 4112 | } |
| 4113 | |
| 4114 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4115 | HUnresolvedInstanceFieldSet* instruction) { |
| 4116 | FieldAccessCallingConvetionX86 calling_convention; |
| 4117 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4118 | instruction, instruction->GetFieldType(), calling_convention); |
| 4119 | } |
| 4120 | |
| 4121 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4122 | HUnresolvedInstanceFieldSet* instruction) { |
| 4123 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4124 | instruction->GetFieldType(), |
| 4125 | instruction->GetFieldIndex(), |
| 4126 | instruction->GetDexPc()); |
| 4127 | } |
| 4128 | |
| 4129 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4130 | HUnresolvedStaticFieldGet* instruction) { |
| 4131 | FieldAccessCallingConvetionX86 calling_convention; |
| 4132 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4133 | instruction, instruction->GetFieldType(), calling_convention); |
| 4134 | } |
| 4135 | |
| 4136 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4137 | HUnresolvedStaticFieldGet* instruction) { |
| 4138 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4139 | instruction->GetFieldType(), |
| 4140 | instruction->GetFieldIndex(), |
| 4141 | instruction->GetDexPc()); |
| 4142 | } |
| 4143 | |
| 4144 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4145 | HUnresolvedStaticFieldSet* instruction) { |
| 4146 | FieldAccessCallingConvetionX86 calling_convention; |
| 4147 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4148 | instruction, instruction->GetFieldType(), calling_convention); |
| 4149 | } |
| 4150 | |
| 4151 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4152 | HUnresolvedStaticFieldSet* instruction) { |
| 4153 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4154 | instruction->GetFieldType(), |
| 4155 | instruction->GetFieldIndex(), |
| 4156 | instruction->GetDexPc()); |
| 4157 | } |
| 4158 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4159 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4160 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4161 | ? LocationSummary::kCallOnSlowPath |
| 4162 | : LocationSummary::kNoCall; |
| 4163 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4164 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4165 | ? Location::RequiresRegister() |
| 4166 | : Location::Any(); |
| 4167 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4168 | if (instruction->HasUses()) { |
| 4169 | locations->SetOut(Location::SameAsFirstInput()); |
| 4170 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4171 | } |
| 4172 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4173 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4174 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4175 | return; |
| 4176 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4177 | LocationSummary* locations = instruction->GetLocations(); |
| 4178 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4179 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4180 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4181 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4182 | } |
| 4183 | |
| 4184 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 4185 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4186 | codegen_->AddSlowPath(slow_path); |
| 4187 | |
| 4188 | LocationSummary* locations = instruction->GetLocations(); |
| 4189 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4190 | |
| 4191 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4192 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4193 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4194 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4195 | } else { |
| 4196 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4197 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4198 | __ jmp(slow_path->GetEntryLabel()); |
| 4199 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4200 | } |
| 4201 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4202 | } |
| 4203 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4204 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4205 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4206 | GenerateImplicitNullCheck(instruction); |
| 4207 | } else { |
| 4208 | GenerateExplicitNullCheck(instruction); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4212 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4213 | LocationSummary* locations = |
| 4214 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4215 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4216 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4217 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4218 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4219 | } else { |
| 4220 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 4221 | // the array's location. |
| 4222 | locations->SetOut(Location::RequiresRegister(), |
| 4223 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 4224 | : Location::kNoOutputOverlap); |
| 4225 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4229 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4230 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4231 | Location index = locations->InAt(1); |
| 4232 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4233 | Primitive::Type type = instruction->GetType(); |
| 4234 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4235 | case Primitive::kPrimBoolean: { |
| 4236 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4237 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4238 | if (index.IsConstant()) { |
| 4239 | __ movzxb(out, Address(obj, |
| 4240 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4241 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4242 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4243 | } |
| 4244 | break; |
| 4245 | } |
| 4246 | |
| 4247 | case Primitive::kPrimByte: { |
| 4248 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4249 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4250 | if (index.IsConstant()) { |
| 4251 | __ movsxb(out, Address(obj, |
| 4252 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4253 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4254 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4255 | } |
| 4256 | break; |
| 4257 | } |
| 4258 | |
| 4259 | case Primitive::kPrimShort: { |
| 4260 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4261 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4262 | if (index.IsConstant()) { |
| 4263 | __ movsxw(out, Address(obj, |
| 4264 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4265 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4266 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4267 | } |
| 4268 | break; |
| 4269 | } |
| 4270 | |
| 4271 | case Primitive::kPrimChar: { |
| 4272 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4273 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4274 | if (index.IsConstant()) { |
| 4275 | __ movzxw(out, Address(obj, |
| 4276 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4277 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4278 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4279 | } |
| 4280 | break; |
| 4281 | } |
| 4282 | |
| 4283 | case Primitive::kPrimInt: |
| 4284 | case Primitive::kPrimNot: { |
| 4285 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4286 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4287 | if (index.IsConstant()) { |
| 4288 | __ movl(out, Address(obj, |
| 4289 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4290 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4291 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4292 | } |
| 4293 | break; |
| 4294 | } |
| 4295 | |
| 4296 | case Primitive::kPrimLong: { |
| 4297 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4298 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4299 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4300 | if (index.IsConstant()) { |
| 4301 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4302 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4304 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4305 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4306 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4307 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4308 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4309 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4310 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4311 | } |
| 4312 | break; |
| 4313 | } |
| 4314 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4315 | case Primitive::kPrimFloat: { |
| 4316 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4317 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4318 | if (index.IsConstant()) { |
| 4319 | __ movss(out, Address(obj, |
| 4320 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4321 | } else { |
| 4322 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4323 | } |
| 4324 | break; |
| 4325 | } |
| 4326 | |
| 4327 | case Primitive::kPrimDouble: { |
| 4328 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4329 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4330 | if (index.IsConstant()) { |
| 4331 | __ movsd(out, Address(obj, |
| 4332 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4333 | } else { |
| 4334 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4335 | } |
| 4336 | break; |
| 4337 | } |
| 4338 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4339 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4340 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4341 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4342 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4343 | |
| 4344 | if (type != Primitive::kPrimLong) { |
| 4345 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4346 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4347 | |
| 4348 | if (type == Primitive::kPrimNot) { |
| 4349 | Register out = locations->Out().AsRegister<Register>(); |
| 4350 | __ MaybeUnpoisonHeapReference(out); |
| 4351 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4355 | // This location builder might end up asking to up to four registers, which is |
| 4356 | // not currently possible for baseline. The situation in which we need four |
| 4357 | // registers cannot be met by baseline though, because it has not run any |
| 4358 | // optimization. |
| 4359 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4360 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4361 | bool needs_write_barrier = |
| 4362 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4363 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4364 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4365 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4366 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4367 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4368 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4369 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4370 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4371 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4372 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4373 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4374 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4375 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4376 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4377 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4378 | // We need the inputs to be different than the output in case of long operation. |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4379 | // In case of a byte operation, the register allocator does not support multiple |
| 4380 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4381 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4382 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4383 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4384 | // Ensure the value is in a byte register. |
| 4385 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4386 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4387 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4388 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4389 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4390 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4391 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4392 | // Temporary registers for the write barrier. |
| 4393 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4394 | // Ensure the card is in a byte register. |
| 4395 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4396 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4397 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4401 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4402 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4403 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4404 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4405 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4406 | bool needs_runtime_call = locations->WillCall(); |
| 4407 | bool needs_write_barrier = |
| 4408 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4409 | |
| 4410 | switch (value_type) { |
| 4411 | case Primitive::kPrimBoolean: |
| 4412 | case Primitive::kPrimByte: { |
| 4413 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4414 | if (index.IsConstant()) { |
| 4415 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4416 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4417 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4418 | } else { |
| 4419 | __ movb(Address(obj, offset), |
| 4420 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4421 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4422 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4423 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4424 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4425 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4426 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4427 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4428 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4429 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4430 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4431 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4432 | break; |
| 4433 | } |
| 4434 | |
| 4435 | case Primitive::kPrimShort: |
| 4436 | case Primitive::kPrimChar: { |
| 4437 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4438 | if (index.IsConstant()) { |
| 4439 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4440 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4441 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4442 | } else { |
| 4443 | __ movw(Address(obj, offset), |
| 4444 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4445 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4446 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4447 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4448 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4449 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4450 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4451 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4452 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4453 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4454 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4455 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4456 | break; |
| 4457 | } |
| 4458 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4459 | case Primitive::kPrimInt: |
| 4460 | case Primitive::kPrimNot: { |
| 4461 | if (!needs_runtime_call) { |
| 4462 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4463 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4464 | size_t offset = |
| 4465 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4466 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4467 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4468 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4469 | __ movl(temp, value.AsRegister<Register>()); |
| 4470 | __ PoisonHeapReference(temp); |
| 4471 | __ movl(Address(obj, offset), temp); |
| 4472 | } else { |
| 4473 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4474 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4475 | } else { |
| 4476 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4477 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4478 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4479 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4480 | // Note: if heap poisoning is enabled, no need to poison |
| 4481 | // (negate) `v` if it is a reference, as it would be null. |
| 4482 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4483 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4484 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4485 | DCHECK(index.IsRegister()) << index; |
| 4486 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4487 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4488 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4489 | __ movl(temp, value.AsRegister<Register>()); |
| 4490 | __ PoisonHeapReference(temp); |
| 4491 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4492 | } else { |
| 4493 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4494 | value.AsRegister<Register>()); |
| 4495 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4496 | } else { |
| 4497 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4498 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4499 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4500 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4501 | // Note: if heap poisoning is enabled, no need to poison |
| 4502 | // (negate) `v` if it is a reference, as it would be null. |
| 4503 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4504 | } |
| 4505 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4506 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4507 | |
| 4508 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4509 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4510 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4511 | codegen_->MarkGCCard( |
| 4512 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4513 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4514 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4515 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4516 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4517 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4518 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4519 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4520 | instruction, |
| 4521 | instruction->GetDexPc(), |
| 4522 | nullptr); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4523 | } |
| 4524 | break; |
| 4525 | } |
| 4526 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4527 | case Primitive::kPrimLong: { |
| 4528 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4529 | if (index.IsConstant()) { |
| 4530 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4531 | if (value.IsRegisterPair()) { |
| 4532 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4533 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4534 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4535 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4536 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4537 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4538 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4539 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4540 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4541 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4542 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4543 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4544 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4545 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4546 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4547 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4548 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4549 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4550 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4551 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4552 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4553 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4554 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4555 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4556 | Immediate(High32Bits(val))); |
| 4557 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4558 | } |
| 4559 | break; |
| 4560 | } |
| 4561 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4562 | case Primitive::kPrimFloat: { |
| 4563 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4564 | DCHECK(value.IsFpuRegister()); |
| 4565 | if (index.IsConstant()) { |
| 4566 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4567 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4568 | } else { |
| 4569 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4570 | value.AsFpuRegister<XmmRegister>()); |
| 4571 | } |
| 4572 | break; |
| 4573 | } |
| 4574 | |
| 4575 | case Primitive::kPrimDouble: { |
| 4576 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4577 | DCHECK(value.IsFpuRegister()); |
| 4578 | if (index.IsConstant()) { |
| 4579 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4580 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4581 | } else { |
| 4582 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4583 | value.AsFpuRegister<XmmRegister>()); |
| 4584 | } |
| 4585 | break; |
| 4586 | } |
| 4587 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4588 | case Primitive::kPrimVoid: |
| 4589 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4590 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4595 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4596 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4597 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4601 | LocationSummary* locations = instruction->GetLocations(); |
| 4602 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4603 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4604 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4605 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4606 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4607 | } |
| 4608 | |
| 4609 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4610 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4611 | ? LocationSummary::kCallOnSlowPath |
| 4612 | : LocationSummary::kNoCall; |
| 4613 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4614 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4615 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4616 | if (instruction->HasUses()) { |
| 4617 | locations->SetOut(Location::SameAsFirstInput()); |
| 4618 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4622 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4623 | Location index_loc = locations->InAt(0); |
| 4624 | Location length_loc = locations->InAt(1); |
| 4625 | SlowPathCodeX86* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4626 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4627 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4628 | if (length_loc.IsConstant()) { |
| 4629 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4630 | if (index_loc.IsConstant()) { |
| 4631 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4632 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4633 | if (index < 0 || index >= length) { |
| 4634 | codegen_->AddSlowPath(slow_path); |
| 4635 | __ jmp(slow_path->GetEntryLabel()); |
| 4636 | } else { |
| 4637 | // Some optimization after BCE may have generated this, and we should not |
| 4638 | // generate a bounds check if it is a valid range. |
| 4639 | } |
| 4640 | return; |
| 4641 | } |
| 4642 | |
| 4643 | // We have to reverse the jump condition because the length is the constant. |
| 4644 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4645 | __ cmpl(index_reg, Immediate(length)); |
| 4646 | codegen_->AddSlowPath(slow_path); |
| 4647 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4648 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4649 | Register length = length_loc.AsRegister<Register>(); |
| 4650 | if (index_loc.IsConstant()) { |
| 4651 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4652 | __ cmpl(length, Immediate(value)); |
| 4653 | } else { |
| 4654 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4655 | } |
| 4656 | codegen_->AddSlowPath(slow_path); |
| 4657 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4658 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4659 | } |
| 4660 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4661 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4662 | temp->SetLocations(nullptr); |
| 4663 | } |
| 4664 | |
| 4665 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4666 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4667 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4668 | } |
| 4669 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4670 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4671 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4672 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4676 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4677 | } |
| 4678 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4679 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4680 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4681 | } |
| 4682 | |
| 4683 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4684 | HBasicBlock* block = instruction->GetBlock(); |
| 4685 | if (block->GetLoopInformation() != nullptr) { |
| 4686 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4687 | // The back edge will generate the suspend check. |
| 4688 | return; |
| 4689 | } |
| 4690 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4691 | // The goto will generate the suspend check. |
| 4692 | return; |
| 4693 | } |
| 4694 | GenerateSuspendCheck(instruction, nullptr); |
| 4695 | } |
| 4696 | |
| 4697 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4698 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4699 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4700 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4701 | if (slow_path == nullptr) { |
| 4702 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4703 | instruction->SetSlowPath(slow_path); |
| 4704 | codegen_->AddSlowPath(slow_path); |
| 4705 | if (successor != nullptr) { |
| 4706 | DCHECK(successor->IsLoopHeader()); |
| 4707 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4708 | } |
| 4709 | } else { |
| 4710 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4711 | } |
| 4712 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4713 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4714 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4715 | if (successor == nullptr) { |
| 4716 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4717 | __ Bind(slow_path->GetReturnLabel()); |
| 4718 | } else { |
| 4719 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4720 | __ jmp(slow_path->GetEntryLabel()); |
| 4721 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4722 | } |
| 4723 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4724 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4725 | return codegen_->GetAssembler(); |
| 4726 | } |
| 4727 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4728 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4729 | ScratchRegisterScope ensure_scratch( |
| 4730 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4731 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4732 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4733 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4734 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4738 | ScratchRegisterScope ensure_scratch( |
| 4739 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4740 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4741 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4742 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4743 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4744 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4745 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4749 | MoveOperands* move = moves_.Get(index); |
| 4750 | Location source = move->GetSource(); |
| 4751 | Location destination = move->GetDestination(); |
| 4752 | |
| 4753 | if (source.IsRegister()) { |
| 4754 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4755 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4756 | } else { |
| 4757 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4758 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4759 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4760 | } else if (source.IsFpuRegister()) { |
| 4761 | if (destination.IsFpuRegister()) { |
| 4762 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4763 | } else if (destination.IsStackSlot()) { |
| 4764 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4765 | } else { |
| 4766 | DCHECK(destination.IsDoubleStackSlot()); |
| 4767 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4768 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4769 | } else if (source.IsStackSlot()) { |
| 4770 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4771 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4772 | } else if (destination.IsFpuRegister()) { |
| 4773 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4774 | } else { |
| 4775 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4776 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4777 | } |
| 4778 | } else if (source.IsDoubleStackSlot()) { |
| 4779 | if (destination.IsFpuRegister()) { |
| 4780 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4781 | } else { |
| 4782 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4783 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4784 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4785 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4786 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4787 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4788 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4789 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4790 | if (value == 0) { |
| 4791 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4792 | } else { |
| 4793 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4794 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4795 | } else { |
| 4796 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4797 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4798 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4799 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4800 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4801 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4802 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4803 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4804 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4805 | if (value == 0) { |
| 4806 | // Easy handling of 0.0. |
| 4807 | __ xorps(dest, dest); |
| 4808 | } else { |
| 4809 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4810 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4811 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4812 | __ movl(temp, Immediate(value)); |
| 4813 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4814 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4815 | } else { |
| 4816 | DCHECK(destination.IsStackSlot()) << destination; |
| 4817 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4818 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4819 | } else if (constant->IsLongConstant()) { |
| 4820 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4821 | int32_t low_value = Low32Bits(value); |
| 4822 | int32_t high_value = High32Bits(value); |
| 4823 | Immediate low(low_value); |
| 4824 | Immediate high(high_value); |
| 4825 | if (destination.IsDoubleStackSlot()) { |
| 4826 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4827 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4828 | } else { |
| 4829 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4830 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4831 | } |
| 4832 | } else { |
| 4833 | DCHECK(constant->IsDoubleConstant()); |
| 4834 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4835 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4836 | int32_t low_value = Low32Bits(value); |
| 4837 | int32_t high_value = High32Bits(value); |
| 4838 | Immediate low(low_value); |
| 4839 | Immediate high(high_value); |
| 4840 | if (destination.IsFpuRegister()) { |
| 4841 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4842 | if (value == 0) { |
| 4843 | // Easy handling of 0.0. |
| 4844 | __ xorpd(dest, dest); |
| 4845 | } else { |
| 4846 | __ pushl(high); |
| 4847 | __ pushl(low); |
| 4848 | __ movsd(dest, Address(ESP, 0)); |
| 4849 | __ addl(ESP, Immediate(8)); |
| 4850 | } |
| 4851 | } else { |
| 4852 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4853 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4854 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4855 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4856 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4857 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4858 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4859 | } |
| 4860 | } |
| 4861 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4862 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4863 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4864 | ScratchRegisterScope ensure_scratch( |
| 4865 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4866 | |
| 4867 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4868 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4869 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4870 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4871 | } |
| 4872 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4873 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4874 | ScratchRegisterScope ensure_scratch( |
| 4875 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4876 | |
| 4877 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4878 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4879 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4880 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4881 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4882 | } |
| 4883 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4884 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4885 | ScratchRegisterScope ensure_scratch1( |
| 4886 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4887 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4888 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4889 | ScratchRegisterScope ensure_scratch2( |
| 4890 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4891 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4892 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4893 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4894 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4895 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4896 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4897 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4901 | MoveOperands* move = moves_.Get(index); |
| 4902 | Location source = move->GetSource(); |
| 4903 | Location destination = move->GetDestination(); |
| 4904 | |
| 4905 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4906 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4907 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4908 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4909 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4910 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4911 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4912 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4913 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4914 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4915 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4916 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4917 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4918 | // Use XOR Swap algorithm to avoid a temporary. |
| 4919 | DCHECK_NE(source.reg(), destination.reg()); |
| 4920 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4921 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4922 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4923 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4924 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4925 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4926 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4927 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4928 | // Take advantage of the 16 bytes in the XMM register. |
| 4929 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4930 | Address stack(ESP, destination.GetStackIndex()); |
| 4931 | // Load the double into the high doubleword. |
| 4932 | __ movhpd(reg, stack); |
| 4933 | |
| 4934 | // Store the low double into the destination. |
| 4935 | __ movsd(stack, reg); |
| 4936 | |
| 4937 | // Move the high double to the low double. |
| 4938 | __ psrldq(reg, Immediate(8)); |
| 4939 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4940 | // Take advantage of the 16 bytes in the XMM register. |
| 4941 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4942 | Address stack(ESP, source.GetStackIndex()); |
| 4943 | // Load the double into the high doubleword. |
| 4944 | __ movhpd(reg, stack); |
| 4945 | |
| 4946 | // Store the low double into the destination. |
| 4947 | __ movsd(stack, reg); |
| 4948 | |
| 4949 | // Move the high double to the low double. |
| 4950 | __ psrldq(reg, Immediate(8)); |
| 4951 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4952 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4953 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4954 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4955 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4956 | } |
| 4957 | } |
| 4958 | |
| 4959 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4960 | __ pushl(static_cast<Register>(reg)); |
| 4961 | } |
| 4962 | |
| 4963 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4964 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4965 | } |
| 4966 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4967 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4968 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4969 | ? LocationSummary::kCallOnSlowPath |
| 4970 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4971 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4972 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4973 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4974 | locations->SetOut(Location::RequiresRegister()); |
| 4975 | } |
| 4976 | |
| 4977 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4978 | LocationSummary* locations = cls->GetLocations(); |
| 4979 | Register out = locations->Out().AsRegister<Register>(); |
| 4980 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4981 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4982 | DCHECK(!cls->CanCallRuntime()); |
| 4983 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4984 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4985 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4986 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4987 | __ movl(out, Address( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4988 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4989 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4990 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4991 | |
| 4992 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4993 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4994 | codegen_->AddSlowPath(slow_path); |
| 4995 | __ testl(out, out); |
| 4996 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4997 | if (cls->MustGenerateClinitCheck()) { |
| 4998 | GenerateClassInitializationCheck(slow_path, out); |
| 4999 | } else { |
| 5000 | __ Bind(slow_path->GetExitLabel()); |
| 5001 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5006 | LocationSummary* locations = |
| 5007 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5009 | if (check->HasUses()) { |
| 5010 | locations->SetOut(Location::SameAsFirstInput()); |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5015 | // We assume the class to not be null. |
| 5016 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5017 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5018 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5019 | GenerateClassInitializationCheck(slow_path, |
| 5020 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5021 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5022 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5023 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 5024 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5025 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5026 | Immediate(mirror::Class::kStatusInitialized)); |
| 5027 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5028 | __ Bind(slow_path->GetExitLabel()); |
| 5029 | // No need for memory fence, thanks to the X86 memory model. |
| 5030 | } |
| 5031 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5032 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 5033 | LocationSummary* locations = |
| 5034 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5035 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5036 | locations->SetOut(Location::RequiresRegister()); |
| 5037 | } |
| 5038 | |
| 5039 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 5040 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5041 | codegen_->AddSlowPath(slow_path); |
| 5042 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5043 | LocationSummary* locations = load->GetLocations(); |
| 5044 | Register out = locations->Out().AsRegister<Register>(); |
| 5045 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 5046 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5047 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5048 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5049 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5050 | __ testl(out, out); |
| 5051 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5052 | __ Bind(slow_path->GetExitLabel()); |
| 5053 | } |
| 5054 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5055 | static Address GetExceptionTlsAddress() { |
| 5056 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5057 | } |
| 5058 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5059 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5060 | LocationSummary* locations = |
| 5061 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5062 | locations->SetOut(Location::RequiresRegister()); |
| 5063 | } |
| 5064 | |
| 5065 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5066 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5067 | } |
| 5068 | |
| 5069 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5070 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5071 | } |
| 5072 | |
| 5073 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5074 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
| 5077 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5078 | LocationSummary* locations = |
| 5079 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5080 | InvokeRuntimeCallingConvention calling_convention; |
| 5081 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5082 | } |
| 5083 | |
| 5084 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5085 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5086 | instruction, |
| 5087 | instruction->GetDexPc(), |
| 5088 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5091 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5092 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5093 | switch (instruction->GetTypeCheckKind()) { |
| 5094 | case TypeCheckKind::kExactCheck: |
| 5095 | case TypeCheckKind::kAbstractClassCheck: |
| 5096 | case TypeCheckKind::kClassHierarchyCheck: |
| 5097 | case TypeCheckKind::kArrayObjectCheck: |
| 5098 | call_kind = LocationSummary::kNoCall; |
| 5099 | break; |
| 5100 | case TypeCheckKind::kInterfaceCheck: |
| 5101 | call_kind = LocationSummary::kCall; |
| 5102 | break; |
| 5103 | case TypeCheckKind::kArrayCheck: |
| 5104 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5105 | break; |
| 5106 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5107 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5108 | if (call_kind != LocationSummary::kCall) { |
| 5109 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5110 | locations->SetInAt(1, Location::Any()); |
| 5111 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5112 | locations->SetOut(Location::RequiresRegister()); |
| 5113 | } else { |
| 5114 | InvokeRuntimeCallingConvention calling_convention; |
| 5115 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5116 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5117 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 5118 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5121 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5122 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5123 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5124 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5125 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5126 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5127 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5128 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5129 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5130 | SlowPathCodeX86* slow_path = nullptr; |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5131 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5132 | |
| 5133 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5134 | // Avoid null check if we know obj is not null. |
| 5135 | if (instruction->MustDoNullCheck()) { |
| 5136 | __ testl(obj, obj); |
| 5137 | __ j(kEqual, &zero); |
| 5138 | } |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5139 | |
| 5140 | // In case of an interface check, we put the object class into the object register. |
| 5141 | // This is safe, as the register is caller-save, and the object must be in another |
| 5142 | // register if it survives the runtime call. |
| 5143 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) |
| 5144 | ? obj |
| 5145 | : out; |
| 5146 | __ movl(target, Address(obj, class_offset)); |
| 5147 | __ MaybeUnpoisonHeapReference(target); |
| 5148 | |
| 5149 | switch (instruction->GetTypeCheckKind()) { |
| 5150 | case TypeCheckKind::kExactCheck: { |
| 5151 | if (cls.IsRegister()) { |
| 5152 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5153 | } else { |
| 5154 | DCHECK(cls.IsStackSlot()) << cls; |
| 5155 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5156 | } |
| 5157 | // Classes must be equal for the instanceof to succeed. |
| 5158 | __ j(kNotEqual, &zero); |
| 5159 | __ movl(out, Immediate(1)); |
| 5160 | __ jmp(&done); |
| 5161 | break; |
| 5162 | } |
| 5163 | case TypeCheckKind::kAbstractClassCheck: { |
| 5164 | // If the class is abstract, we eagerly fetch the super class of the |
| 5165 | // object to avoid doing a comparison we know will fail. |
| 5166 | NearLabel loop; |
| 5167 | __ Bind(&loop); |
| 5168 | __ movl(out, Address(out, super_offset)); |
| 5169 | __ MaybeUnpoisonHeapReference(out); |
| 5170 | __ testl(out, out); |
| 5171 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5172 | __ j(kEqual, &done); |
| 5173 | if (cls.IsRegister()) { |
| 5174 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5175 | } else { |
| 5176 | DCHECK(cls.IsStackSlot()) << cls; |
| 5177 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5178 | } |
| 5179 | __ j(kNotEqual, &loop); |
| 5180 | __ movl(out, Immediate(1)); |
| 5181 | if (zero.IsLinked()) { |
| 5182 | __ jmp(&done); |
| 5183 | } |
| 5184 | break; |
| 5185 | } |
| 5186 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5187 | // Walk over the class hierarchy to find a match. |
| 5188 | NearLabel loop, success; |
| 5189 | __ Bind(&loop); |
| 5190 | if (cls.IsRegister()) { |
| 5191 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5192 | } else { |
| 5193 | DCHECK(cls.IsStackSlot()) << cls; |
| 5194 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5195 | } |
| 5196 | __ j(kEqual, &success); |
| 5197 | __ movl(out, Address(out, super_offset)); |
| 5198 | __ MaybeUnpoisonHeapReference(out); |
| 5199 | __ testl(out, out); |
| 5200 | __ j(kNotEqual, &loop); |
| 5201 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5202 | __ jmp(&done); |
| 5203 | __ Bind(&success); |
| 5204 | __ movl(out, Immediate(1)); |
| 5205 | if (zero.IsLinked()) { |
| 5206 | __ jmp(&done); |
| 5207 | } |
| 5208 | break; |
| 5209 | } |
| 5210 | case TypeCheckKind::kArrayObjectCheck: { |
| 5211 | // Just need to check that the object's class is a non primitive array. |
| 5212 | __ movl(out, Address(out, component_offset)); |
| 5213 | __ MaybeUnpoisonHeapReference(out); |
| 5214 | __ testl(out, out); |
| 5215 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5216 | __ j(kEqual, &done); |
| 5217 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5218 | __ j(kNotEqual, &zero); |
| 5219 | __ movl(out, Immediate(1)); |
| 5220 | __ jmp(&done); |
| 5221 | break; |
| 5222 | } |
| 5223 | case TypeCheckKind::kArrayCheck: { |
| 5224 | if (cls.IsRegister()) { |
| 5225 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5226 | } else { |
| 5227 | DCHECK(cls.IsStackSlot()) << cls; |
| 5228 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5229 | } |
| 5230 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5231 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 5232 | instruction, /* is_fatal */ false); |
| 5233 | codegen_->AddSlowPath(slow_path); |
| 5234 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5235 | __ movl(out, Immediate(1)); |
| 5236 | if (zero.IsLinked()) { |
| 5237 | __ jmp(&done); |
| 5238 | } |
| 5239 | break; |
| 5240 | } |
| 5241 | |
| 5242 | case TypeCheckKind::kInterfaceCheck: |
| 5243 | default: { |
| 5244 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 5245 | instruction, |
| 5246 | instruction->GetDexPc(), |
| 5247 | nullptr); |
| 5248 | if (zero.IsLinked()) { |
| 5249 | __ jmp(&done); |
| 5250 | } |
| 5251 | break; |
| 5252 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5253 | } |
| 5254 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5255 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5256 | __ Bind(&zero); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5257 | __ xorl(out, out); |
| 5258 | } |
| 5259 | |
| 5260 | if (done.IsLinked()) { |
| 5261 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5262 | } |
| 5263 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5264 | if (slow_path != nullptr) { |
| 5265 | __ Bind(slow_path->GetExitLabel()); |
| 5266 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5267 | } |
| 5268 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5269 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5270 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5271 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5272 | |
| 5273 | switch (instruction->GetTypeCheckKind()) { |
| 5274 | case TypeCheckKind::kExactCheck: |
| 5275 | case TypeCheckKind::kAbstractClassCheck: |
| 5276 | case TypeCheckKind::kClassHierarchyCheck: |
| 5277 | case TypeCheckKind::kArrayObjectCheck: |
| 5278 | call_kind = throws_into_catch |
| 5279 | ? LocationSummary::kCallOnSlowPath |
| 5280 | : LocationSummary::kNoCall; |
| 5281 | break; |
| 5282 | case TypeCheckKind::kInterfaceCheck: |
| 5283 | call_kind = LocationSummary::kCall; |
| 5284 | break; |
| 5285 | case TypeCheckKind::kArrayCheck: |
| 5286 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5287 | break; |
| 5288 | } |
| 5289 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5290 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5291 | instruction, call_kind); |
| 5292 | if (call_kind != LocationSummary::kCall) { |
| 5293 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5294 | locations->SetInAt(1, Location::Any()); |
| 5295 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5296 | locations->AddTemp(Location::RequiresRegister()); |
| 5297 | } else { |
| 5298 | InvokeRuntimeCallingConvention calling_convention; |
| 5299 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5300 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5301 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 5305 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5306 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5307 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5308 | Register temp = locations->WillCall() |
| 5309 | ? kNoRegister |
| 5310 | : locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5311 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5312 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5313 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5314 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5315 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5316 | SlowPathCodeX86* slow_path = nullptr; |
| 5317 | |
| 5318 | if (!locations->WillCall()) { |
| 5319 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 5320 | instruction, !locations->CanCall()); |
| 5321 | codegen_->AddSlowPath(slow_path); |
| 5322 | } |
| 5323 | |
| 5324 | NearLabel done, abstract_entry; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5325 | // Avoid null check if we know obj is not null. |
| 5326 | if (instruction->MustDoNullCheck()) { |
| 5327 | __ testl(obj, obj); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5328 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5329 | } |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5330 | |
| 5331 | if (locations->WillCall()) { |
| 5332 | __ movl(obj, Address(obj, class_offset)); |
| 5333 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5334 | } else { |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5335 | __ movl(temp, Address(obj, class_offset)); |
| 5336 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5337 | } |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 5338 | |
| 5339 | switch (instruction->GetTypeCheckKind()) { |
| 5340 | case TypeCheckKind::kExactCheck: |
| 5341 | case TypeCheckKind::kArrayCheck: { |
| 5342 | if (cls.IsRegister()) { |
| 5343 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5344 | } else { |
| 5345 | DCHECK(cls.IsStackSlot()) << cls; |
| 5346 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5347 | } |
| 5348 | // Jump to slow path for throwing the exception or doing a |
| 5349 | // more involved array check. |
| 5350 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5351 | break; |
| 5352 | } |
| 5353 | case TypeCheckKind::kAbstractClassCheck: { |
| 5354 | // If the class is abstract, we eagerly fetch the super class of the |
| 5355 | // object to avoid doing a comparison we know will fail. |
| 5356 | NearLabel loop, success; |
| 5357 | __ Bind(&loop); |
| 5358 | __ movl(temp, Address(temp, super_offset)); |
| 5359 | __ MaybeUnpoisonHeapReference(temp); |
| 5360 | __ testl(temp, temp); |
| 5361 | // Jump to the slow path to throw the exception. |
| 5362 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5363 | if (cls.IsRegister()) { |
| 5364 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5365 | } else { |
| 5366 | DCHECK(cls.IsStackSlot()) << cls; |
| 5367 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5368 | } |
| 5369 | __ j(kNotEqual, &loop); |
| 5370 | break; |
| 5371 | } |
| 5372 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5373 | // Walk over the class hierarchy to find a match. |
| 5374 | NearLabel loop, success; |
| 5375 | __ Bind(&loop); |
| 5376 | if (cls.IsRegister()) { |
| 5377 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5378 | } else { |
| 5379 | DCHECK(cls.IsStackSlot()) << cls; |
| 5380 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5381 | } |
| 5382 | __ j(kEqual, &success); |
| 5383 | __ movl(temp, Address(temp, super_offset)); |
| 5384 | __ MaybeUnpoisonHeapReference(temp); |
| 5385 | __ testl(temp, temp); |
| 5386 | __ j(kNotEqual, &loop); |
| 5387 | // Jump to the slow path to throw the exception. |
| 5388 | __ jmp(slow_path->GetEntryLabel()); |
| 5389 | __ Bind(&success); |
| 5390 | break; |
| 5391 | } |
| 5392 | case TypeCheckKind::kArrayObjectCheck: { |
| 5393 | // Just need to check that the object's class is a non primitive array. |
| 5394 | __ movl(temp, Address(temp, component_offset)); |
| 5395 | __ MaybeUnpoisonHeapReference(temp); |
| 5396 | __ testl(temp, temp); |
| 5397 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5398 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5399 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5400 | break; |
| 5401 | } |
| 5402 | case TypeCheckKind::kInterfaceCheck: |
| 5403 | default: |
| 5404 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5405 | instruction, |
| 5406 | instruction->GetDexPc(), |
| 5407 | nullptr); |
| 5408 | break; |
| 5409 | } |
| 5410 | __ Bind(&done); |
| 5411 | |
| 5412 | if (slow_path != nullptr) { |
| 5413 | __ Bind(slow_path->GetExitLabel()); |
| 5414 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5415 | } |
| 5416 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5417 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5418 | LocationSummary* locations = |
| 5419 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5420 | InvokeRuntimeCallingConvention calling_convention; |
| 5421 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5422 | } |
| 5423 | |
| 5424 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5425 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5426 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5427 | instruction, |
| 5428 | instruction->GetDexPc(), |
| 5429 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5430 | } |
| 5431 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5432 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5433 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5434 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5435 | |
| 5436 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5437 | LocationSummary* locations = |
| 5438 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5439 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5440 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5441 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5442 | locations->SetInAt(1, Location::Any()); |
| 5443 | locations->SetOut(Location::SameAsFirstInput()); |
| 5444 | } |
| 5445 | |
| 5446 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 5447 | HandleBitwiseOperation(instruction); |
| 5448 | } |
| 5449 | |
| 5450 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 5451 | HandleBitwiseOperation(instruction); |
| 5452 | } |
| 5453 | |
| 5454 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 5455 | HandleBitwiseOperation(instruction); |
| 5456 | } |
| 5457 | |
| 5458 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5459 | LocationSummary* locations = instruction->GetLocations(); |
| 5460 | Location first = locations->InAt(0); |
| 5461 | Location second = locations->InAt(1); |
| 5462 | DCHECK(first.Equals(locations->Out())); |
| 5463 | |
| 5464 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5465 | if (second.IsRegister()) { |
| 5466 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5467 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5468 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5469 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5470 | } else { |
| 5471 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5472 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5473 | } |
| 5474 | } else if (second.IsConstant()) { |
| 5475 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5476 | __ andl(first.AsRegister<Register>(), |
| 5477 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5478 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5479 | __ orl(first.AsRegister<Register>(), |
| 5480 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5481 | } else { |
| 5482 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5483 | __ xorl(first.AsRegister<Register>(), |
| 5484 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5485 | } |
| 5486 | } else { |
| 5487 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5488 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5489 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5490 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5491 | } else { |
| 5492 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5493 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5494 | } |
| 5495 | } |
| 5496 | } else { |
| 5497 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5498 | if (second.IsRegisterPair()) { |
| 5499 | if (instruction->IsAnd()) { |
| 5500 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5501 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5502 | } else if (instruction->IsOr()) { |
| 5503 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5504 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5505 | } else { |
| 5506 | DCHECK(instruction->IsXor()); |
| 5507 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5508 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5509 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5510 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5511 | if (instruction->IsAnd()) { |
| 5512 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5513 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5514 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5515 | } else if (instruction->IsOr()) { |
| 5516 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5517 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5518 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5519 | } else { |
| 5520 | DCHECK(instruction->IsXor()); |
| 5521 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5522 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5523 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5524 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5525 | } else { |
| 5526 | DCHECK(second.IsConstant()) << second; |
| 5527 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5528 | int32_t low_value = Low32Bits(value); |
| 5529 | int32_t high_value = High32Bits(value); |
| 5530 | Immediate low(low_value); |
| 5531 | Immediate high(high_value); |
| 5532 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5533 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5534 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5535 | if (low_value == 0) { |
| 5536 | __ xorl(first_low, first_low); |
| 5537 | } else if (low_value != -1) { |
| 5538 | __ andl(first_low, low); |
| 5539 | } |
| 5540 | if (high_value == 0) { |
| 5541 | __ xorl(first_high, first_high); |
| 5542 | } else if (high_value != -1) { |
| 5543 | __ andl(first_high, high); |
| 5544 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5545 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5546 | if (low_value != 0) { |
| 5547 | __ orl(first_low, low); |
| 5548 | } |
| 5549 | if (high_value != 0) { |
| 5550 | __ orl(first_high, high); |
| 5551 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5552 | } else { |
| 5553 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5554 | if (low_value != 0) { |
| 5555 | __ xorl(first_low, low); |
| 5556 | } |
| 5557 | if (high_value != 0) { |
| 5558 | __ xorl(first_high, high); |
| 5559 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5560 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5561 | } |
| 5562 | } |
| 5563 | } |
| 5564 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5565 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5566 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5567 | UNUSED(instruction); |
| 5568 | LOG(FATAL) << "Unreachable"; |
| 5569 | } |
| 5570 | |
| 5571 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5572 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5573 | UNUSED(instruction); |
| 5574 | LOG(FATAL) << "Unreachable"; |
| 5575 | } |
| 5576 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5577 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5578 | DCHECK(codegen_->IsBaseline()); |
| 5579 | LocationSummary* locations = |
| 5580 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5581 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5582 | } |
| 5583 | |
| 5584 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5585 | DCHECK(codegen_->IsBaseline()); |
| 5586 | // Will be generated at use site. |
| 5587 | } |
| 5588 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5589 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 5590 | HX86ComputeBaseMethodAddress* insn) { |
| 5591 | LocationSummary* locations = |
| 5592 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5593 | locations->SetOut(Location::RequiresRegister()); |
| 5594 | } |
| 5595 | |
| 5596 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 5597 | HX86ComputeBaseMethodAddress* insn) { |
| 5598 | LocationSummary* locations = insn->GetLocations(); |
| 5599 | Register reg = locations->Out().AsRegister<Register>(); |
| 5600 | |
| 5601 | // Generate call to next instruction. |
| 5602 | Label next_instruction; |
| 5603 | __ call(&next_instruction); |
| 5604 | __ Bind(&next_instruction); |
| 5605 | |
| 5606 | // Remember this offset for later use with constant area. |
| 5607 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 5608 | |
| 5609 | // Grab the return address off the stack. |
| 5610 | __ popl(reg); |
| 5611 | } |
| 5612 | |
| 5613 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 5614 | HX86LoadFromConstantTable* insn) { |
| 5615 | LocationSummary* locations = |
| 5616 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5617 | |
| 5618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5619 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 5620 | |
| 5621 | // If we don't need to be materialized, we only need the inputs to be set. |
| 5622 | if (!insn->NeedsMaterialization()) { |
| 5623 | return; |
| 5624 | } |
| 5625 | |
| 5626 | switch (insn->GetType()) { |
| 5627 | case Primitive::kPrimFloat: |
| 5628 | case Primitive::kPrimDouble: |
| 5629 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5630 | break; |
| 5631 | |
| 5632 | case Primitive::kPrimInt: |
| 5633 | locations->SetOut(Location::RequiresRegister()); |
| 5634 | break; |
| 5635 | |
| 5636 | default: |
| 5637 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 5642 | if (!insn->NeedsMaterialization()) { |
| 5643 | return; |
| 5644 | } |
| 5645 | |
| 5646 | LocationSummary* locations = insn->GetLocations(); |
| 5647 | Location out = locations->Out(); |
| 5648 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 5649 | HConstant *value = insn->GetConstant(); |
| 5650 | |
| 5651 | switch (insn->GetType()) { |
| 5652 | case Primitive::kPrimFloat: |
| 5653 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 5654 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 5655 | break; |
| 5656 | |
| 5657 | case Primitive::kPrimDouble: |
| 5658 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 5659 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 5660 | break; |
| 5661 | |
| 5662 | case Primitive::kPrimInt: |
| 5663 | __ movl(out.AsRegister<Register>(), |
| 5664 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 5665 | break; |
| 5666 | |
| 5667 | default: |
| 5668 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5669 | } |
| 5670 | } |
| 5671 | |
| 5672 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 5673 | // Generate the constant area if needed. |
| 5674 | X86Assembler* assembler = GetAssembler(); |
| 5675 | if (!assembler->IsConstantAreaEmpty()) { |
| 5676 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5677 | // byte values. |
| 5678 | assembler->Align(4, 0); |
| 5679 | constant_area_start_ = assembler->CodeSize(); |
| 5680 | assembler->AddConstantArea(); |
| 5681 | } |
| 5682 | |
| 5683 | // And finish up. |
| 5684 | CodeGenerator::Finalize(allocator); |
| 5685 | } |
| 5686 | |
| 5687 | /** |
| 5688 | * Class to handle late fixup of offsets into constant area. |
| 5689 | */ |
| 5690 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 5691 | public: |
| 5692 | RIPFixup(const CodeGeneratorX86& codegen, int offset) |
| 5693 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5694 | |
| 5695 | private: |
| 5696 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5697 | // Patch the correct offset for the instruction. The place to patch is the |
| 5698 | // last 4 bytes of the instruction. |
| 5699 | // The value to patch is the distance from the offset in the constant area |
| 5700 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| 5701 | int32_t constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5702 | int32_t relative_position = constant_offset - codegen_.GetMethodAddressOffset();; |
| 5703 | |
| 5704 | // Patch in the right value. |
| 5705 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5706 | } |
| 5707 | |
| 5708 | const CodeGeneratorX86& codegen_; |
| 5709 | |
| 5710 | // Location in constant area that the fixup refers to. |
| 5711 | int offset_into_constant_area_; |
| 5712 | }; |
| 5713 | |
| 5714 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 5715 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5716 | return Address(reg, kDummy32BitOffset, fixup); |
| 5717 | } |
| 5718 | |
| 5719 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 5720 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5721 | return Address(reg, kDummy32BitOffset, fixup); |
| 5722 | } |
| 5723 | |
| 5724 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 5725 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5726 | return Address(reg, kDummy32BitOffset, fixup); |
| 5727 | } |
| 5728 | |
| 5729 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 5730 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5731 | return Address(reg, kDummy32BitOffset, fixup); |
| 5732 | } |
| 5733 | |
| 5734 | /** |
| 5735 | * Finds instructions that need the constant area base as an input. |
| 5736 | */ |
| 5737 | class ConstantHandlerVisitor : public HGraphVisitor { |
| 5738 | public: |
| 5739 | explicit ConstantHandlerVisitor(HGraph* graph) : HGraphVisitor(graph), base_(nullptr) {} |
| 5740 | |
| 5741 | private: |
| 5742 | void VisitAdd(HAdd* add) OVERRIDE { |
| 5743 | BinaryFP(add); |
| 5744 | } |
| 5745 | |
| 5746 | void VisitSub(HSub* sub) OVERRIDE { |
| 5747 | BinaryFP(sub); |
| 5748 | } |
| 5749 | |
| 5750 | void VisitMul(HMul* mul) OVERRIDE { |
| 5751 | BinaryFP(mul); |
| 5752 | } |
| 5753 | |
| 5754 | void VisitDiv(HDiv* div) OVERRIDE { |
| 5755 | BinaryFP(div); |
| 5756 | } |
| 5757 | |
| 5758 | void VisitReturn(HReturn* ret) OVERRIDE { |
| 5759 | HConstant* value = ret->InputAt(0)->AsConstant(); |
| 5760 | if ((value != nullptr && Primitive::IsFloatingPointType(value->GetType()))) { |
| 5761 | ReplaceInput(ret, value, 0, true); |
| 5762 | } |
| 5763 | } |
| 5764 | |
| 5765 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 5766 | HandleInvoke(invoke); |
| 5767 | } |
| 5768 | |
| 5769 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 5770 | HandleInvoke(invoke); |
| 5771 | } |
| 5772 | |
| 5773 | void VisitInvokeInterface(HInvokeInterface* invoke) OVERRIDE { |
| 5774 | HandleInvoke(invoke); |
| 5775 | } |
| 5776 | |
| 5777 | void BinaryFP(HBinaryOperation* bin) { |
| 5778 | HConstant* rhs = bin->InputAt(1)->AsConstant(); |
| 5779 | if (rhs != nullptr && Primitive::IsFloatingPointType(bin->GetResultType())) { |
| 5780 | ReplaceInput(bin, rhs, 1, false); |
| 5781 | } |
| 5782 | } |
| 5783 | |
| 5784 | void InitializeConstantAreaPointer(HInstruction* user) { |
| 5785 | // Ensure we only initialize the pointer once. |
| 5786 | if (base_ != nullptr) { |
| 5787 | return; |
| 5788 | } |
| 5789 | |
| 5790 | HGraph* graph = GetGraph(); |
| 5791 | HBasicBlock* entry = graph->GetEntryBlock(); |
| 5792 | base_ = new (graph->GetArena()) HX86ComputeBaseMethodAddress(); |
| 5793 | HInstruction* insert_pos = (user->GetBlock() == entry) ? user : entry->GetLastInstruction(); |
| 5794 | entry->InsertInstructionBefore(base_, insert_pos); |
| 5795 | DCHECK(base_ != nullptr); |
| 5796 | } |
| 5797 | |
| 5798 | void ReplaceInput(HInstruction* insn, HConstant* value, int input_index, bool materialize) { |
| 5799 | InitializeConstantAreaPointer(insn); |
| 5800 | HGraph* graph = GetGraph(); |
| 5801 | HBasicBlock* block = insn->GetBlock(); |
| 5802 | HX86LoadFromConstantTable* load_constant = |
| 5803 | new (graph->GetArena()) HX86LoadFromConstantTable(base_, value, materialize); |
| 5804 | block->InsertInstructionBefore(load_constant, insn); |
| 5805 | insn->ReplaceInput(load_constant, input_index); |
| 5806 | } |
| 5807 | |
| 5808 | void HandleInvoke(HInvoke* invoke) { |
| 5809 | // Ensure that we can load FP arguments from the constant area. |
| 5810 | for (size_t i = 0, e = invoke->InputCount(); i < e; i++) { |
| 5811 | HConstant* input = invoke->InputAt(i)->AsConstant(); |
| 5812 | if (input != nullptr && Primitive::IsFloatingPointType(input->GetType())) { |
| 5813 | ReplaceInput(invoke, input, i, true); |
| 5814 | } |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | // The generated HX86ComputeBaseMethodAddress in the entry block needed as an |
| 5819 | // input to the HX86LoadFromConstantTable instructions. |
| 5820 | HX86ComputeBaseMethodAddress* base_; |
| 5821 | }; |
| 5822 | |
| 5823 | void ConstantAreaFixups::Run() { |
| 5824 | ConstantHandlerVisitor visitor(graph_); |
| 5825 | visitor.VisitInsertionOrder(); |
| 5826 | } |
| 5827 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5828 | #undef __ |
| 5829 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5830 | } // namespace x86 |
| 5831 | } // namespace art |