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())-> |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 50 | #define QUICK_ENTRY_POINT(x) Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x)) |
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()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 60 | instruction_, |
| 61 | instruction_->GetDexPc(), |
| 62 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | bool IsFatal() const OVERRIDE { return true; } |
| 66 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 67 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 68 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 70 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 71 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 72 | }; |
| 73 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 74 | class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 { |
| 75 | public: |
| 76 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 77 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 78 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 79 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 | __ Bind(GetEntryLabel()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 81 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 82 | instruction_, |
| 83 | instruction_->GetDexPc(), |
| 84 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 87 | bool IsFatal() const OVERRIDE { return true; } |
| 88 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 89 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 90 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 91 | private: |
| 92 | HDivZeroCheck* const instruction_; |
| 93 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 94 | }; |
| 95 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 96 | class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 98 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 100 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 102 | if (is_div_) { |
| 103 | __ negl(reg_); |
| 104 | } else { |
| 105 | __ movl(reg_, Immediate(0)); |
| 106 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | __ jmp(GetExitLabel()); |
| 108 | } |
| 109 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 110 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 111 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | private: |
| 113 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | bool is_div_; |
| 115 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 118 | class BoundsCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 119 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 120 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 121 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 122 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 123 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 124 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 125 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 126 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 127 | // move resolver. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 128 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 129 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 130 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 131 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 132 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 134 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 135 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 136 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 137 | instruction_, |
| 138 | instruction_->GetDexPc(), |
| 139 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 142 | bool IsFatal() const OVERRIDE { return true; } |
| 143 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 144 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 145 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 146 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 147 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 148 | |
| 149 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 150 | }; |
| 151 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 152 | class SuspendCheckSlowPathX86 : public SlowPathCodeX86 { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 153 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 154 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 155 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 156 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 157 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 158 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 159 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 160 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 161 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 162 | instruction_, |
| 163 | instruction_->GetDexPc(), |
| 164 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 165 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 166 | if (successor_ == nullptr) { |
| 167 | __ jmp(GetReturnLabel()); |
| 168 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 169 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 170 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 173 | Label* GetReturnLabel() { |
| 174 | DCHECK(successor_ == nullptr); |
| 175 | return &return_label_; |
| 176 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 178 | HBasicBlock* GetSuccessor() const { |
| 179 | return successor_; |
| 180 | } |
| 181 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 182 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 183 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | private: |
| 185 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 186 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 187 | Label return_label_; |
| 188 | |
| 189 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 190 | }; |
| 191 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 192 | class LoadStringSlowPathX86 : public SlowPathCodeX86 { |
| 193 | public: |
| 194 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 195 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 196 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 197 | LocationSummary* locations = instruction_->GetLocations(); |
| 198 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 199 | |
| 200 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 201 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 202 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 203 | |
| 204 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 205 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 206 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 207 | instruction_, |
| 208 | instruction_->GetDexPc(), |
| 209 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 210 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 211 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 212 | |
| 213 | __ jmp(GetExitLabel()); |
| 214 | } |
| 215 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 216 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 217 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 218 | private: |
| 219 | HLoadString* const instruction_; |
| 220 | |
| 221 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 222 | }; |
| 223 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 224 | class LoadClassSlowPathX86 : public SlowPathCodeX86 { |
| 225 | public: |
| 226 | LoadClassSlowPathX86(HLoadClass* cls, |
| 227 | HInstruction* at, |
| 228 | uint32_t dex_pc, |
| 229 | bool do_clinit) |
| 230 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 231 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 232 | } |
| 233 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 234 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 235 | LocationSummary* locations = at_->GetLocations(); |
| 236 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 237 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 238 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | |
| 240 | InvokeRuntimeCallingConvention calling_convention; |
| 241 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 242 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 243 | : QUICK_ENTRY_POINT(pInitializeType), |
| 244 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | |
| 246 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 247 | Location out = locations->Out(); |
| 248 | if (out.IsValid()) { |
| 249 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 250 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 252 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 253 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 254 | __ jmp(GetExitLabel()); |
| 255 | } |
| 256 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 257 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 258 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 259 | private: |
| 260 | // The class this slow path will load. |
| 261 | HLoadClass* const cls_; |
| 262 | |
| 263 | // The instruction where this slow path is happening. |
| 264 | // (Might be the load class or an initialization check). |
| 265 | HInstruction* const at_; |
| 266 | |
| 267 | // The dex PC of `at_`. |
| 268 | const uint32_t dex_pc_; |
| 269 | |
| 270 | // Whether to initialize the class. |
| 271 | const bool do_clinit_; |
| 272 | |
| 273 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 274 | }; |
| 275 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | class TypeCheckSlowPathX86 : public SlowPathCodeX86 { |
| 277 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 278 | explicit TypeCheckSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 279 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 280 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 281 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 282 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 283 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 284 | DCHECK(instruction_->IsCheckCast() |
| 285 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 286 | |
| 287 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 288 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 289 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 290 | |
| 291 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 292 | // move resolver. |
| 293 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 294 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 295 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 296 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 297 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 298 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 299 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 300 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 302 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 303 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 304 | instruction_, |
| 305 | instruction_->GetDexPc(), |
| 306 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 307 | } else { |
| 308 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 309 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 310 | instruction_, |
| 311 | instruction_->GetDexPc(), |
| 312 | this); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 315 | if (instruction_->IsInstanceOf()) { |
| 316 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 317 | } |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 318 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 319 | |
| 320 | __ jmp(GetExitLabel()); |
| 321 | } |
| 322 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 323 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
| 324 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 325 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 326 | HInstruction* const instruction_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 327 | |
| 328 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 329 | }; |
| 330 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 331 | class DeoptimizationSlowPathX86 : public SlowPathCodeX86 { |
| 332 | public: |
| 333 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 334 | : instruction_(instruction) {} |
| 335 | |
| 336 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 337 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 338 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 339 | __ Bind(GetEntryLabel()); |
| 340 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 341 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 342 | instruction_, |
| 343 | instruction_->GetDexPc(), |
| 344 | this); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 347 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 348 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 349 | private: |
| 350 | HInstruction* const instruction_; |
| 351 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 352 | }; |
| 353 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 354 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 355 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 356 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 357 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 358 | switch (cond) { |
| 359 | case kCondEQ: return kEqual; |
| 360 | case kCondNE: return kNotEqual; |
| 361 | case kCondLT: return kLess; |
| 362 | case kCondLE: return kLessEqual; |
| 363 | case kCondGT: return kGreater; |
| 364 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 365 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 366 | LOG(FATAL) << "Unreachable"; |
| 367 | UNREACHABLE(); |
| 368 | } |
| 369 | |
| 370 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 371 | switch (cond) { |
| 372 | case kCondEQ: return kEqual; |
| 373 | case kCondNE: return kNotEqual; |
| 374 | case kCondLT: return kBelow; |
| 375 | case kCondLE: return kBelowEqual; |
| 376 | case kCondGT: return kAbove; |
| 377 | case kCondGE: return kAboveEqual; |
| 378 | } |
| 379 | LOG(FATAL) << "Unreachable"; |
| 380 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 383 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 384 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 388 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 391 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 392 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 393 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 394 | } |
| 395 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 396 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 397 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 398 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 401 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 402 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 403 | return GetFloatingPointSpillSlotSize(); |
| 404 | } |
| 405 | |
| 406 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 407 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 408 | return GetFloatingPointSpillSlotSize(); |
| 409 | } |
| 410 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 411 | void CodeGeneratorX86::InvokeRuntime(Address entry_point, |
| 412 | HInstruction* instruction, |
| 413 | uint32_t dex_pc, |
| 414 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 415 | ValidateInvokeRuntime(instruction, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 416 | __ fs()->call(entry_point); |
| 417 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 420 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 421 | const X86InstructionSetFeatures& isa_features, |
| 422 | const CompilerOptions& compiler_options) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 423 | : CodeGenerator(graph, |
| 424 | kNumberOfCpuRegisters, |
| 425 | kNumberOfXmmRegisters, |
| 426 | kNumberOfRegisterPairs, |
| 427 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 428 | arraysize(kCoreCalleeSaves)) |
| 429 | | (1 << kFakeReturnRegister), |
| 430 | 0, |
| 431 | compiler_options), |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 432 | block_labels_(graph->GetArena(), 0), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 433 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 434 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 435 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 436 | isa_features_(isa_features), |
| 437 | method_patches_(graph->GetArena()->Adapter()), |
| 438 | relative_call_patches_(graph->GetArena()->Adapter()) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 439 | // Use a fake return address register to mimic Quick. |
| 440 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 441 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 442 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 443 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 444 | switch (type) { |
| 445 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 446 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 447 | X86ManagedRegister pair = |
| 448 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 449 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 450 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 451 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 452 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 453 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 454 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | case Primitive::kPrimByte: |
| 458 | case Primitive::kPrimBoolean: |
| 459 | case Primitive::kPrimChar: |
| 460 | case Primitive::kPrimShort: |
| 461 | case Primitive::kPrimInt: |
| 462 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 463 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 464 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 465 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 466 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 467 | X86ManagedRegister current = |
| 468 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 469 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 470 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 471 | } |
| 472 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 473 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 477 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 478 | return Location::FpuRegisterLocation( |
| 479 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 480 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 481 | |
| 482 | case Primitive::kPrimVoid: |
| 483 | LOG(FATAL) << "Unreachable type " << type; |
| 484 | } |
| 485 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 486 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 487 | } |
| 488 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 489 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 490 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 491 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 492 | |
| 493 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 494 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 495 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 496 | if (is_baseline) { |
| 497 | blocked_core_registers_[EBP] = true; |
| 498 | blocked_core_registers_[ESI] = true; |
| 499 | blocked_core_registers_[EDI] = true; |
| 500 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 501 | |
| 502 | UpdateBlockedPairRegisters(); |
| 503 | } |
| 504 | |
| 505 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 506 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 507 | X86ManagedRegister current = |
| 508 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 509 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 510 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 511 | blocked_register_pairs_[i] = true; |
| 512 | } |
| 513 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 516 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 517 | : HGraphVisitor(graph), |
| 518 | assembler_(codegen->GetAssembler()), |
| 519 | codegen_(codegen) {} |
| 520 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 521 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 522 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 525 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 526 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 527 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 528 | bool skip_overflow_check = |
| 529 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 530 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 531 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 532 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 533 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 534 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 537 | if (HasEmptyFrame()) { |
| 538 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 539 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 540 | |
| 541 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 542 | Register reg = kCoreCalleeSaves[i]; |
| 543 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 544 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 545 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 546 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 550 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 551 | __ subl(ESP, Immediate(adjust)); |
| 552 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 553 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 557 | __ cfi().RememberState(); |
| 558 | if (!HasEmptyFrame()) { |
| 559 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 560 | __ addl(ESP, Immediate(adjust)); |
| 561 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 562 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 563 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 564 | Register reg = kCoreCalleeSaves[i]; |
| 565 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 566 | __ popl(reg); |
| 567 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 568 | __ cfi().Restore(DWARFReg(reg)); |
| 569 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 570 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 571 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 572 | __ ret(); |
| 573 | __ cfi().RestoreState(); |
| 574 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 577 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 578 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 581 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 582 | switch (load->GetType()) { |
| 583 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 584 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 585 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 586 | |
| 587 | case Primitive::kPrimInt: |
| 588 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 589 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 590 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 591 | |
| 592 | case Primitive::kPrimBoolean: |
| 593 | case Primitive::kPrimByte: |
| 594 | case Primitive::kPrimChar: |
| 595 | case Primitive::kPrimShort: |
| 596 | case Primitive::kPrimVoid: |
| 597 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 598 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 602 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 605 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 606 | switch (type) { |
| 607 | case Primitive::kPrimBoolean: |
| 608 | case Primitive::kPrimByte: |
| 609 | case Primitive::kPrimChar: |
| 610 | case Primitive::kPrimShort: |
| 611 | case Primitive::kPrimInt: |
| 612 | case Primitive::kPrimNot: |
| 613 | return Location::RegisterLocation(EAX); |
| 614 | |
| 615 | case Primitive::kPrimLong: |
| 616 | return Location::RegisterPairLocation(EAX, EDX); |
| 617 | |
| 618 | case Primitive::kPrimVoid: |
| 619 | return Location::NoLocation(); |
| 620 | |
| 621 | case Primitive::kPrimDouble: |
| 622 | case Primitive::kPrimFloat: |
| 623 | return Location::FpuRegisterLocation(XMM0); |
| 624 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 625 | |
| 626 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 630 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 631 | } |
| 632 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 633 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 634 | switch (type) { |
| 635 | case Primitive::kPrimBoolean: |
| 636 | case Primitive::kPrimByte: |
| 637 | case Primitive::kPrimChar: |
| 638 | case Primitive::kPrimShort: |
| 639 | case Primitive::kPrimInt: |
| 640 | case Primitive::kPrimNot: { |
| 641 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 642 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 643 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 644 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 645 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 646 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 647 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 648 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 649 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 650 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 651 | uint32_t index = gp_index_; |
| 652 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 653 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 654 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 655 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 656 | calling_convention.GetRegisterPairAt(index)); |
| 657 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 658 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 659 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 664 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 665 | stack_index_++; |
| 666 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 667 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 668 | } else { |
| 669 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 674 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 675 | stack_index_ += 2; |
| 676 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 677 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 678 | } else { |
| 679 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 683 | case Primitive::kPrimVoid: |
| 684 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 685 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 686 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 687 | return Location(); |
| 688 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 689 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 690 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 691 | if (source.Equals(destination)) { |
| 692 | return; |
| 693 | } |
| 694 | if (destination.IsRegister()) { |
| 695 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 696 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 697 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 698 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 699 | } else { |
| 700 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 701 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 703 | } else if (destination.IsFpuRegister()) { |
| 704 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 705 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 706 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 707 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 708 | } else { |
| 709 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 710 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 711 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 712 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 713 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 714 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 715 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 716 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 717 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 718 | } else if (source.IsConstant()) { |
| 719 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 720 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 721 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 722 | } else { |
| 723 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 724 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 725 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 731 | if (source.Equals(destination)) { |
| 732 | return; |
| 733 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 734 | if (destination.IsRegisterPair()) { |
| 735 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 736 | EmitParallelMoves( |
| 737 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 738 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 739 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 740 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 741 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 742 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 743 | } else if (source.IsFpuRegister()) { |
| 744 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 745 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 746 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 747 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 748 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 749 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 750 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 751 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 752 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 753 | if (source.IsFpuRegister()) { |
| 754 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 755 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 756 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 757 | } else { |
| 758 | LOG(FATAL) << "Unimplemented"; |
| 759 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 760 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 761 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 762 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 763 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 764 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 765 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 766 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 767 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 768 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 769 | } else if (source.IsConstant()) { |
| 770 | HConstant* constant = source.GetConstant(); |
| 771 | int64_t value; |
| 772 | if (constant->IsLongConstant()) { |
| 773 | value = constant->AsLongConstant()->GetValue(); |
| 774 | } else { |
| 775 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 776 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 777 | } |
| 778 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 779 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 780 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 781 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 782 | EmitParallelMoves( |
| 783 | Location::StackSlot(source.GetStackIndex()), |
| 784 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 785 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 786 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 787 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 788 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 793 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 794 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 795 | if (instruction->IsCurrentMethod()) { |
| 796 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 797 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 798 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 799 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 800 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 801 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 802 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 803 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 804 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 805 | } else if (location.IsStackSlot()) { |
| 806 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 807 | } else { |
| 808 | DCHECK(location.IsConstant()); |
| 809 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 810 | } |
| 811 | } else if (const_to_move->IsLongConstant()) { |
| 812 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 813 | if (location.IsRegisterPair()) { |
| 814 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 815 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 816 | } else if (location.IsDoubleStackSlot()) { |
| 817 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 818 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 819 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 820 | } else { |
| 821 | DCHECK(location.IsConstant()); |
| 822 | DCHECK_EQ(location.GetConstant(), instruction); |
| 823 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 824 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 825 | } else if (instruction->IsTemporary()) { |
| 826 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 827 | if (temp_location.IsStackSlot()) { |
| 828 | Move32(location, temp_location); |
| 829 | } else { |
| 830 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 831 | Move64(location, temp_location); |
| 832 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 833 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 834 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 835 | switch (instruction->GetType()) { |
| 836 | case Primitive::kPrimBoolean: |
| 837 | case Primitive::kPrimByte: |
| 838 | case Primitive::kPrimChar: |
| 839 | case Primitive::kPrimShort: |
| 840 | case Primitive::kPrimInt: |
| 841 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 842 | case Primitive::kPrimFloat: |
| 843 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 844 | break; |
| 845 | |
| 846 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 847 | case Primitive::kPrimDouble: |
| 848 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 849 | break; |
| 850 | |
| 851 | default: |
| 852 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 853 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 854 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 855 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 856 | switch (instruction->GetType()) { |
| 857 | case Primitive::kPrimBoolean: |
| 858 | case Primitive::kPrimByte: |
| 859 | case Primitive::kPrimChar: |
| 860 | case Primitive::kPrimShort: |
| 861 | case Primitive::kPrimInt: |
| 862 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 863 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 864 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 865 | break; |
| 866 | |
| 867 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 868 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 869 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 870 | break; |
| 871 | |
| 872 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 873 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 874 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 878 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 879 | DCHECK(!successor->IsExitBlock()); |
| 880 | |
| 881 | HBasicBlock* block = got->GetBlock(); |
| 882 | HInstruction* previous = got->GetPrevious(); |
| 883 | |
| 884 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 885 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 886 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 891 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 892 | } |
| 893 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 894 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 898 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 899 | got->SetLocations(nullptr); |
| 900 | } |
| 901 | |
| 902 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 903 | HandleGoto(got, got->GetSuccessor()); |
| 904 | } |
| 905 | |
| 906 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 907 | try_boundary->SetLocations(nullptr); |
| 908 | } |
| 909 | |
| 910 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 911 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 912 | if (!successor->IsExitBlock()) { |
| 913 | HandleGoto(try_boundary, successor); |
| 914 | } |
| 915 | } |
| 916 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 917 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 918 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 921 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 922 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 925 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 926 | Label* true_label, |
| 927 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 928 | if (cond->IsFPConditionTrueIfNaN()) { |
| 929 | __ j(kUnordered, true_label); |
| 930 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 931 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 932 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 933 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 937 | Label* true_label, |
| 938 | Label* false_label) { |
| 939 | LocationSummary* locations = cond->GetLocations(); |
| 940 | Location left = locations->InAt(0); |
| 941 | Location right = locations->InAt(1); |
| 942 | IfCondition if_cond = cond->GetCondition(); |
| 943 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 944 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 945 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 946 | IfCondition true_high_cond = if_cond; |
| 947 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 949 | |
| 950 | // Set the conditions for the test, remembering that == needs to be |
| 951 | // decided using the low words. |
| 952 | switch (if_cond) { |
| 953 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 954 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 955 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 956 | break; |
| 957 | case kCondLT: |
| 958 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 959 | break; |
| 960 | case kCondLE: |
| 961 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 962 | break; |
| 963 | case kCondGT: |
| 964 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 965 | break; |
| 966 | case kCondGE: |
| 967 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 968 | break; |
| 969 | } |
| 970 | |
| 971 | if (right.IsConstant()) { |
| 972 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 973 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 974 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 975 | |
| 976 | if (val_high == 0) { |
| 977 | __ testl(left_high, left_high); |
| 978 | } else { |
| 979 | __ cmpl(left_high, Immediate(val_high)); |
| 980 | } |
| 981 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 982 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 983 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 984 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 985 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 986 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 987 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 988 | } |
| 989 | // Must be equal high, so compare the lows. |
| 990 | if (val_low == 0) { |
| 991 | __ testl(left_low, left_low); |
| 992 | } else { |
| 993 | __ cmpl(left_low, Immediate(val_low)); |
| 994 | } |
| 995 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 996 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 997 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 998 | |
| 999 | __ cmpl(left_high, right_high); |
| 1000 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1001 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1002 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1003 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1004 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1005 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1006 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1007 | } |
| 1008 | // Must be equal high, so compare the lows. |
| 1009 | __ cmpl(left_low, right_low); |
| 1010 | } |
| 1011 | // The last comparison might be unsigned. |
| 1012 | __ j(final_condition, true_label); |
| 1013 | } |
| 1014 | |
| 1015 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1016 | HCondition* condition, |
| 1017 | Label* true_target, |
| 1018 | Label* false_target, |
| 1019 | Label* always_true_target) { |
| 1020 | LocationSummary* locations = condition->GetLocations(); |
| 1021 | Location left = locations->InAt(0); |
| 1022 | Location right = locations->InAt(1); |
| 1023 | |
| 1024 | // We don't want true_target as a nullptr. |
| 1025 | if (true_target == nullptr) { |
| 1026 | true_target = always_true_target; |
| 1027 | } |
| 1028 | bool falls_through = (false_target == nullptr); |
| 1029 | |
| 1030 | // FP compares don't like null false_targets. |
| 1031 | if (false_target == nullptr) { |
| 1032 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1033 | } |
| 1034 | |
| 1035 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1036 | switch (type) { |
| 1037 | case Primitive::kPrimLong: |
| 1038 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1039 | break; |
| 1040 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1041 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1042 | GenerateFPJumps(condition, true_target, false_target); |
| 1043 | break; |
| 1044 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1045 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1046 | GenerateFPJumps(condition, true_target, false_target); |
| 1047 | break; |
| 1048 | default: |
| 1049 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1050 | } |
| 1051 | |
| 1052 | if (!falls_through) { |
| 1053 | __ jmp(false_target); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1057 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1058 | Label* true_target, |
| 1059 | Label* false_target, |
| 1060 | Label* always_true_target) { |
| 1061 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1062 | if (cond->IsIntConstant()) { |
| 1063 | // Constant condition, statically compared against 1. |
| 1064 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1065 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1066 | if (always_true_target != nullptr) { |
| 1067 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1068 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1069 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1070 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1071 | DCHECK_EQ(cond_value, 0); |
| 1072 | } |
| 1073 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1074 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1075 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1076 | // Moves do not affect the eflags register, so if the condition is |
| 1077 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1078 | // again. We can't use the eflags on long/FP conditions if they are |
| 1079 | // materialized due to the complex branching. |
| 1080 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1081 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1082 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1083 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1084 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1085 | if (!eflags_set) { |
| 1086 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1087 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1088 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1089 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1090 | } else { |
| 1091 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1092 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1093 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1094 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1095 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1096 | } |
| 1097 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1098 | // Condition has not been materialized, use its inputs as the |
| 1099 | // comparison and its condition as the branch condition. |
| 1100 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1101 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1102 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1103 | // Generate the comparison directly. |
| 1104 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1105 | cond->AsCondition(), |
| 1106 | true_target, |
| 1107 | false_target, |
| 1108 | always_true_target); |
| 1109 | return; |
| 1110 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1111 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1112 | Location lhs = cond->GetLocations()->InAt(0); |
| 1113 | Location rhs = cond->GetLocations()->InAt(1); |
| 1114 | // LHS is guaranteed to be in a register (see |
| 1115 | // LocationsBuilderX86::VisitCondition). |
| 1116 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1117 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1118 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1119 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1120 | if (constant == 0) { |
| 1121 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1122 | } else { |
| 1123 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1124 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1125 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1126 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1127 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1128 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1129 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1130 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1131 | if (false_target != nullptr) { |
| 1132 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1136 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1137 | LocationSummary* locations = |
| 1138 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1139 | HInstruction* cond = if_instr->InputAt(0); |
| 1140 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1141 | locations->SetInAt(0, Location::Any()); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1146 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1147 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1148 | Label* always_true_target = true_target; |
| 1149 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1150 | if_instr->IfTrueSuccessor())) { |
| 1151 | always_true_target = nullptr; |
| 1152 | } |
| 1153 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1154 | if_instr->IfFalseSuccessor())) { |
| 1155 | false_target = nullptr; |
| 1156 | } |
| 1157 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1158 | } |
| 1159 | |
| 1160 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1161 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1162 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1163 | HInstruction* cond = deoptimize->InputAt(0); |
| 1164 | DCHECK(cond->IsCondition()); |
| 1165 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1166 | locations->SetInAt(0, Location::Any()); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1171 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) |
| 1172 | DeoptimizationSlowPathX86(deoptimize); |
| 1173 | codegen_->AddSlowPath(slow_path); |
| 1174 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1175 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1176 | } |
| 1177 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1178 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1179 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1182 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1183 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1186 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1187 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1190 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1191 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1192 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1195 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1196 | LocationSummary* locations = |
| 1197 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1198 | switch (store->InputAt(1)->GetType()) { |
| 1199 | case Primitive::kPrimBoolean: |
| 1200 | case Primitive::kPrimByte: |
| 1201 | case Primitive::kPrimChar: |
| 1202 | case Primitive::kPrimShort: |
| 1203 | case Primitive::kPrimInt: |
| 1204 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1205 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1206 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1207 | break; |
| 1208 | |
| 1209 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1210 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1211 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1212 | break; |
| 1213 | |
| 1214 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1215 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1216 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1219 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1220 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1223 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1224 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1225 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1226 | // Handle the long/FP comparisons made in instruction simplification. |
| 1227 | switch (cond->InputAt(0)->GetType()) { |
| 1228 | case Primitive::kPrimLong: { |
| 1229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1230 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1231 | if (cond->NeedsMaterialization()) { |
| 1232 | locations->SetOut(Location::RequiresRegister()); |
| 1233 | } |
| 1234 | break; |
| 1235 | } |
| 1236 | case Primitive::kPrimFloat: |
| 1237 | case Primitive::kPrimDouble: { |
| 1238 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1239 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1240 | if (cond->NeedsMaterialization()) { |
| 1241 | locations->SetOut(Location::RequiresRegister()); |
| 1242 | } |
| 1243 | break; |
| 1244 | } |
| 1245 | default: |
| 1246 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1247 | locations->SetInAt(1, Location::Any()); |
| 1248 | if (cond->NeedsMaterialization()) { |
| 1249 | // We need a byte register. |
| 1250 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1251 | } |
| 1252 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1253 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1256 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1257 | if (!cond->NeedsMaterialization()) { |
| 1258 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1259 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 | |
| 1261 | LocationSummary* locations = cond->GetLocations(); |
| 1262 | Location lhs = locations->InAt(0); |
| 1263 | Location rhs = locations->InAt(1); |
| 1264 | Register reg = locations->Out().AsRegister<Register>(); |
| 1265 | Label true_label, false_label; |
| 1266 | |
| 1267 | switch (cond->InputAt(0)->GetType()) { |
| 1268 | default: { |
| 1269 | // Integer case. |
| 1270 | |
| 1271 | // Clear output register: setcc only sets the low byte. |
| 1272 | __ xorl(reg, reg); |
| 1273 | |
| 1274 | if (rhs.IsRegister()) { |
| 1275 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1276 | } else if (rhs.IsConstant()) { |
| 1277 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1278 | if (constant == 0) { |
| 1279 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1280 | } else { |
| 1281 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1282 | } |
| 1283 | } else { |
| 1284 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1285 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1286 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1287 | return; |
| 1288 | } |
| 1289 | case Primitive::kPrimLong: |
| 1290 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1291 | break; |
| 1292 | case Primitive::kPrimFloat: |
| 1293 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1294 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1295 | break; |
| 1296 | case Primitive::kPrimDouble: |
| 1297 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1298 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1299 | break; |
| 1300 | } |
| 1301 | |
| 1302 | // Convert the jumps into the result. |
| 1303 | Label done_label; |
| 1304 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1305 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1306 | __ Bind(&false_label); |
| 1307 | __ xorl(reg, reg); |
| 1308 | __ jmp(&done_label); |
| 1309 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1310 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1311 | __ Bind(&true_label); |
| 1312 | __ movl(reg, Immediate(1)); |
| 1313 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1317 | VisitCondition(comp); |
| 1318 | } |
| 1319 | |
| 1320 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1321 | VisitCondition(comp); |
| 1322 | } |
| 1323 | |
| 1324 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1325 | VisitCondition(comp); |
| 1326 | } |
| 1327 | |
| 1328 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1329 | VisitCondition(comp); |
| 1330 | } |
| 1331 | |
| 1332 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1333 | VisitCondition(comp); |
| 1334 | } |
| 1335 | |
| 1336 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1337 | VisitCondition(comp); |
| 1338 | } |
| 1339 | |
| 1340 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1341 | VisitCondition(comp); |
| 1342 | } |
| 1343 | |
| 1344 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1345 | VisitCondition(comp); |
| 1346 | } |
| 1347 | |
| 1348 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1349 | VisitCondition(comp); |
| 1350 | } |
| 1351 | |
| 1352 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1353 | VisitCondition(comp); |
| 1354 | } |
| 1355 | |
| 1356 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1357 | VisitCondition(comp); |
| 1358 | } |
| 1359 | |
| 1360 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1361 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1365 | LocationSummary* locations = |
| 1366 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1367 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1370 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1371 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1372 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1375 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1376 | LocationSummary* locations = |
| 1377 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1378 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1379 | } |
| 1380 | |
| 1381 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1382 | // Will be generated at use site. |
| 1383 | UNUSED(constant); |
| 1384 | } |
| 1385 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1386 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1387 | LocationSummary* locations = |
| 1388 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1389 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1393 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1394 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1395 | } |
| 1396 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1397 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1398 | LocationSummary* locations = |
| 1399 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1400 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1401 | } |
| 1402 | |
| 1403 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1404 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1405 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1409 | LocationSummary* locations = |
| 1410 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1411 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1412 | } |
| 1413 | |
| 1414 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1415 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1416 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1417 | } |
| 1418 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1419 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1420 | memory_barrier->SetLocations(nullptr); |
| 1421 | } |
| 1422 | |
| 1423 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1424 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1425 | } |
| 1426 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1427 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1428 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1431 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1432 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1433 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1434 | } |
| 1435 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1436 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1437 | LocationSummary* locations = |
| 1438 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1439 | switch (ret->InputAt(0)->GetType()) { |
| 1440 | case Primitive::kPrimBoolean: |
| 1441 | case Primitive::kPrimByte: |
| 1442 | case Primitive::kPrimChar: |
| 1443 | case Primitive::kPrimShort: |
| 1444 | case Primitive::kPrimInt: |
| 1445 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1446 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1447 | break; |
| 1448 | |
| 1449 | case Primitive::kPrimLong: |
| 1450 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1451 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1452 | break; |
| 1453 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1454 | case Primitive::kPrimFloat: |
| 1455 | case Primitive::kPrimDouble: |
| 1456 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1457 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1458 | break; |
| 1459 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1460 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1461 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1462 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1465 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1466 | if (kIsDebugBuild) { |
| 1467 | switch (ret->InputAt(0)->GetType()) { |
| 1468 | case Primitive::kPrimBoolean: |
| 1469 | case Primitive::kPrimByte: |
| 1470 | case Primitive::kPrimChar: |
| 1471 | case Primitive::kPrimShort: |
| 1472 | case Primitive::kPrimInt: |
| 1473 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1474 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1475 | break; |
| 1476 | |
| 1477 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1478 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1479 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1480 | break; |
| 1481 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1482 | case Primitive::kPrimFloat: |
| 1483 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1484 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1485 | break; |
| 1486 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1487 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1488 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1489 | } |
| 1490 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1491 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1494 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1495 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1496 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1497 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1498 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1499 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1500 | if (intrinsic.TryDispatch(invoke)) { |
| 1501 | return; |
| 1502 | } |
| 1503 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1504 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1505 | |
| 1506 | if (codegen_->IsBaseline()) { |
| 1507 | // Baseline does not have enough registers if the current method also |
| 1508 | // needs a register. We therefore do not require a register for it, and let |
| 1509 | // the code generation of the invoke handle it. |
| 1510 | LocationSummary* locations = invoke->GetLocations(); |
| 1511 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1512 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1513 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1514 | } |
| 1515 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1516 | } |
| 1517 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1518 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1519 | if (invoke->GetLocations()->Intrinsified()) { |
| 1520 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1521 | intrinsic.Dispatch(invoke); |
| 1522 | return true; |
| 1523 | } |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1527 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1528 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1529 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1530 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1531 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1532 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1533 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1534 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1535 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1536 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1537 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1538 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1539 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1543 | HandleInvoke(invoke); |
| 1544 | } |
| 1545 | |
| 1546 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1547 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1548 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1551 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1552 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1553 | return; |
| 1554 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1555 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1556 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1557 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1558 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1561 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1562 | HandleInvoke(invoke); |
| 1563 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1564 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1568 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1569 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1570 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1571 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1572 | LocationSummary* locations = invoke->GetLocations(); |
| 1573 | Location receiver = locations->InAt(0); |
| 1574 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1575 | |
| 1576 | // Set the hidden argument. |
| 1577 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1578 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1579 | |
| 1580 | // temp = object->GetClass(); |
| 1581 | if (receiver.IsStackSlot()) { |
| 1582 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1583 | __ movl(temp, Address(temp, class_offset)); |
| 1584 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1585 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1586 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1587 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1588 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1589 | // temp = temp->GetImtEntryAt(method_offset); |
| 1590 | __ movl(temp, Address(temp, method_offset)); |
| 1591 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1592 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1593 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1594 | |
| 1595 | DCHECK(!codegen_->IsLeafMethod()); |
| 1596 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1597 | } |
| 1598 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1599 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1600 | LocationSummary* locations = |
| 1601 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1602 | switch (neg->GetResultType()) { |
| 1603 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1604 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1605 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1606 | locations->SetOut(Location::SameAsFirstInput()); |
| 1607 | break; |
| 1608 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1609 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1610 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1611 | locations->SetOut(Location::SameAsFirstInput()); |
| 1612 | locations->AddTemp(Location::RequiresRegister()); |
| 1613 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1614 | break; |
| 1615 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1616 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1617 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1618 | locations->SetOut(Location::SameAsFirstInput()); |
| 1619 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1620 | break; |
| 1621 | |
| 1622 | default: |
| 1623 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1628 | LocationSummary* locations = neg->GetLocations(); |
| 1629 | Location out = locations->Out(); |
| 1630 | Location in = locations->InAt(0); |
| 1631 | switch (neg->GetResultType()) { |
| 1632 | case Primitive::kPrimInt: |
| 1633 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1634 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1635 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1636 | break; |
| 1637 | |
| 1638 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1639 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1640 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1641 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1642 | // Negation is similar to subtraction from zero. The least |
| 1643 | // significant byte triggers a borrow when it is different from |
| 1644 | // zero; to take it into account, add 1 to the most significant |
| 1645 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1646 | // operation. |
| 1647 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1648 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1649 | break; |
| 1650 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1651 | case Primitive::kPrimFloat: { |
| 1652 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1653 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1654 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1655 | // Implement float negation with an exclusive or with value |
| 1656 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1657 | // single-precision floating-point number). |
| 1658 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1659 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1660 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1661 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1662 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1663 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1664 | case Primitive::kPrimDouble: { |
| 1665 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1666 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1667 | // Implement double negation with an exclusive or with value |
| 1668 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1669 | // a double-precision floating-point number). |
| 1670 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1671 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1672 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1673 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1674 | |
| 1675 | default: |
| 1676 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1677 | } |
| 1678 | } |
| 1679 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1680 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1681 | Primitive::Type result_type = conversion->GetResultType(); |
| 1682 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1683 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1684 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1685 | // The float-to-long and double-to-long type conversions rely on a |
| 1686 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1687 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1688 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1689 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1690 | ? LocationSummary::kCall |
| 1691 | : LocationSummary::kNoCall; |
| 1692 | LocationSummary* locations = |
| 1693 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1694 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1695 | // The Java language does not allow treating boolean as an integral type but |
| 1696 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1697 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1698 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1699 | case Primitive::kPrimByte: |
| 1700 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1701 | case Primitive::kPrimBoolean: |
| 1702 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1703 | case Primitive::kPrimShort: |
| 1704 | case Primitive::kPrimInt: |
| 1705 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1706 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1707 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1708 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1709 | // the validation of the linear scan implementation |
| 1710 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1711 | break; |
| 1712 | |
| 1713 | default: |
| 1714 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1715 | << " to " << result_type; |
| 1716 | } |
| 1717 | break; |
| 1718 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1719 | case Primitive::kPrimShort: |
| 1720 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1721 | case Primitive::kPrimBoolean: |
| 1722 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1723 | case Primitive::kPrimByte: |
| 1724 | case Primitive::kPrimInt: |
| 1725 | case Primitive::kPrimChar: |
| 1726 | // Processing a Dex `int-to-short' instruction. |
| 1727 | locations->SetInAt(0, Location::Any()); |
| 1728 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1729 | break; |
| 1730 | |
| 1731 | default: |
| 1732 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1733 | << " to " << result_type; |
| 1734 | } |
| 1735 | break; |
| 1736 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1737 | case Primitive::kPrimInt: |
| 1738 | switch (input_type) { |
| 1739 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1740 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1741 | locations->SetInAt(0, Location::Any()); |
| 1742 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1743 | break; |
| 1744 | |
| 1745 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1746 | // Processing a Dex `float-to-int' instruction. |
| 1747 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1748 | locations->SetOut(Location::RequiresRegister()); |
| 1749 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1750 | break; |
| 1751 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1752 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1753 | // Processing a Dex `double-to-int' instruction. |
| 1754 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1755 | locations->SetOut(Location::RequiresRegister()); |
| 1756 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1757 | break; |
| 1758 | |
| 1759 | default: |
| 1760 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1761 | << " to " << result_type; |
| 1762 | } |
| 1763 | break; |
| 1764 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1765 | case Primitive::kPrimLong: |
| 1766 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1767 | case Primitive::kPrimBoolean: |
| 1768 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1769 | case Primitive::kPrimByte: |
| 1770 | case Primitive::kPrimShort: |
| 1771 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1772 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1773 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1774 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1775 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1776 | break; |
| 1777 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1778 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1779 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1780 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1781 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1782 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1783 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1784 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1785 | // The runtime helper puts the result in EAX, EDX. |
| 1786 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1787 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1788 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1789 | |
| 1790 | default: |
| 1791 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1792 | << " to " << result_type; |
| 1793 | } |
| 1794 | break; |
| 1795 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1796 | case Primitive::kPrimChar: |
| 1797 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1798 | case Primitive::kPrimBoolean: |
| 1799 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1800 | case Primitive::kPrimByte: |
| 1801 | case Primitive::kPrimShort: |
| 1802 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1803 | // Processing a Dex `int-to-char' instruction. |
| 1804 | locations->SetInAt(0, Location::Any()); |
| 1805 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1806 | break; |
| 1807 | |
| 1808 | default: |
| 1809 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1810 | << " to " << result_type; |
| 1811 | } |
| 1812 | break; |
| 1813 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1814 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1815 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1816 | case Primitive::kPrimBoolean: |
| 1817 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1818 | case Primitive::kPrimByte: |
| 1819 | case Primitive::kPrimShort: |
| 1820 | case Primitive::kPrimInt: |
| 1821 | case Primitive::kPrimChar: |
| 1822 | // Processing a Dex `int-to-float' instruction. |
| 1823 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1824 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1825 | break; |
| 1826 | |
| 1827 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1828 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1829 | locations->SetInAt(0, Location::Any()); |
| 1830 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1831 | break; |
| 1832 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1833 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1834 | // Processing a Dex `double-to-float' instruction. |
| 1835 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1836 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1837 | break; |
| 1838 | |
| 1839 | default: |
| 1840 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1841 | << " to " << result_type; |
| 1842 | }; |
| 1843 | break; |
| 1844 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1845 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1846 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1847 | case Primitive::kPrimBoolean: |
| 1848 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1849 | case Primitive::kPrimByte: |
| 1850 | case Primitive::kPrimShort: |
| 1851 | case Primitive::kPrimInt: |
| 1852 | case Primitive::kPrimChar: |
| 1853 | // Processing a Dex `int-to-double' instruction. |
| 1854 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1855 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1856 | break; |
| 1857 | |
| 1858 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1859 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1860 | locations->SetInAt(0, Location::Any()); |
| 1861 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1862 | break; |
| 1863 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1864 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1865 | // Processing a Dex `float-to-double' instruction. |
| 1866 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1867 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1868 | break; |
| 1869 | |
| 1870 | default: |
| 1871 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1872 | << " to " << result_type; |
| 1873 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1874 | break; |
| 1875 | |
| 1876 | default: |
| 1877 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1878 | << " to " << result_type; |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1883 | LocationSummary* locations = conversion->GetLocations(); |
| 1884 | Location out = locations->Out(); |
| 1885 | Location in = locations->InAt(0); |
| 1886 | Primitive::Type result_type = conversion->GetResultType(); |
| 1887 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1888 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1889 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1890 | case Primitive::kPrimByte: |
| 1891 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1892 | case Primitive::kPrimBoolean: |
| 1893 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1894 | case Primitive::kPrimShort: |
| 1895 | case Primitive::kPrimInt: |
| 1896 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1897 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1898 | if (in.IsRegister()) { |
| 1899 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 1900 | } else { |
| 1901 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1902 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 1903 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 1904 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1905 | break; |
| 1906 | |
| 1907 | default: |
| 1908 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1909 | << " to " << result_type; |
| 1910 | } |
| 1911 | break; |
| 1912 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1913 | case Primitive::kPrimShort: |
| 1914 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1915 | case Primitive::kPrimBoolean: |
| 1916 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1917 | case Primitive::kPrimByte: |
| 1918 | case Primitive::kPrimInt: |
| 1919 | case Primitive::kPrimChar: |
| 1920 | // Processing a Dex `int-to-short' instruction. |
| 1921 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1922 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1923 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1924 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1925 | } else { |
| 1926 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 1927 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1928 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1929 | } |
| 1930 | break; |
| 1931 | |
| 1932 | default: |
| 1933 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1934 | << " to " << result_type; |
| 1935 | } |
| 1936 | break; |
| 1937 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1938 | case Primitive::kPrimInt: |
| 1939 | switch (input_type) { |
| 1940 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1941 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1942 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1943 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1944 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1945 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1946 | } else { |
| 1947 | DCHECK(in.IsConstant()); |
| 1948 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 1949 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1950 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1951 | } |
| 1952 | break; |
| 1953 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1954 | case Primitive::kPrimFloat: { |
| 1955 | // Processing a Dex `float-to-int' instruction. |
| 1956 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1957 | Register output = out.AsRegister<Register>(); |
| 1958 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1959 | Label done, nan; |
| 1960 | |
| 1961 | __ movl(output, Immediate(kPrimIntMax)); |
| 1962 | // temp = int-to-float(output) |
| 1963 | __ cvtsi2ss(temp, output); |
| 1964 | // if input >= temp goto done |
| 1965 | __ comiss(input, temp); |
| 1966 | __ j(kAboveEqual, &done); |
| 1967 | // if input == NaN goto nan |
| 1968 | __ j(kUnordered, &nan); |
| 1969 | // output = float-to-int-truncate(input) |
| 1970 | __ cvttss2si(output, input); |
| 1971 | __ jmp(&done); |
| 1972 | __ Bind(&nan); |
| 1973 | // output = 0 |
| 1974 | __ xorl(output, output); |
| 1975 | __ Bind(&done); |
| 1976 | break; |
| 1977 | } |
| 1978 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1979 | case Primitive::kPrimDouble: { |
| 1980 | // Processing a Dex `double-to-int' instruction. |
| 1981 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 1982 | Register output = out.AsRegister<Register>(); |
| 1983 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1984 | Label done, nan; |
| 1985 | |
| 1986 | __ movl(output, Immediate(kPrimIntMax)); |
| 1987 | // temp = int-to-double(output) |
| 1988 | __ cvtsi2sd(temp, output); |
| 1989 | // if input >= temp goto done |
| 1990 | __ comisd(input, temp); |
| 1991 | __ j(kAboveEqual, &done); |
| 1992 | // if input == NaN goto nan |
| 1993 | __ j(kUnordered, &nan); |
| 1994 | // output = double-to-int-truncate(input) |
| 1995 | __ cvttsd2si(output, input); |
| 1996 | __ jmp(&done); |
| 1997 | __ Bind(&nan); |
| 1998 | // output = 0 |
| 1999 | __ xorl(output, output); |
| 2000 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2001 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2002 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2003 | |
| 2004 | default: |
| 2005 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2006 | << " to " << result_type; |
| 2007 | } |
| 2008 | break; |
| 2009 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2010 | case Primitive::kPrimLong: |
| 2011 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2012 | case Primitive::kPrimBoolean: |
| 2013 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2014 | case Primitive::kPrimByte: |
| 2015 | case Primitive::kPrimShort: |
| 2016 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2017 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2018 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2019 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2020 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2021 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2022 | __ cdq(); |
| 2023 | break; |
| 2024 | |
| 2025 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2026 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2027 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2028 | conversion, |
| 2029 | conversion->GetDexPc(), |
| 2030 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2031 | break; |
| 2032 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2033 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2034 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2035 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2036 | conversion, |
| 2037 | conversion->GetDexPc(), |
| 2038 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2039 | break; |
| 2040 | |
| 2041 | default: |
| 2042 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2043 | << " to " << result_type; |
| 2044 | } |
| 2045 | break; |
| 2046 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2047 | case Primitive::kPrimChar: |
| 2048 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2049 | case Primitive::kPrimBoolean: |
| 2050 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2051 | case Primitive::kPrimByte: |
| 2052 | case Primitive::kPrimShort: |
| 2053 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2054 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2055 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2056 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2057 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2058 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2059 | } else { |
| 2060 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2061 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2062 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2063 | } |
| 2064 | break; |
| 2065 | |
| 2066 | default: |
| 2067 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2068 | << " to " << result_type; |
| 2069 | } |
| 2070 | break; |
| 2071 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2072 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2073 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2074 | case Primitive::kPrimBoolean: |
| 2075 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2076 | case Primitive::kPrimByte: |
| 2077 | case Primitive::kPrimShort: |
| 2078 | case Primitive::kPrimInt: |
| 2079 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2080 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2081 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2084 | case Primitive::kPrimLong: { |
| 2085 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2086 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2087 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2088 | // Create stack space for the call to |
| 2089 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2090 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2091 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2092 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2093 | __ subl(ESP, Immediate(adjustment)); |
| 2094 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2095 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2096 | // Load the value to the FP stack, using temporaries if needed. |
| 2097 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2098 | |
| 2099 | if (out.IsStackSlot()) { |
| 2100 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2101 | } else { |
| 2102 | __ fstps(Address(ESP, 0)); |
| 2103 | Location stack_temp = Location::StackSlot(0); |
| 2104 | codegen_->Move32(out, stack_temp); |
| 2105 | } |
| 2106 | |
| 2107 | // Remove the temporary stack space we allocated. |
| 2108 | if (adjustment != 0) { |
| 2109 | __ addl(ESP, Immediate(adjustment)); |
| 2110 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2111 | break; |
| 2112 | } |
| 2113 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2115 | // Processing a Dex `double-to-float' instruction. |
| 2116 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | |
| 2119 | default: |
| 2120 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2121 | << " to " << result_type; |
| 2122 | }; |
| 2123 | break; |
| 2124 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2125 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2126 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2127 | case Primitive::kPrimBoolean: |
| 2128 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2129 | case Primitive::kPrimByte: |
| 2130 | case Primitive::kPrimShort: |
| 2131 | case Primitive::kPrimInt: |
| 2132 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2133 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2134 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2135 | break; |
| 2136 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2137 | case Primitive::kPrimLong: { |
| 2138 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2139 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2140 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2141 | // Create stack space for the call to |
| 2142 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2143 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2144 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2145 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2146 | __ subl(ESP, Immediate(adjustment)); |
| 2147 | } |
| 2148 | |
| 2149 | // Load the value to the FP stack, using temporaries if needed. |
| 2150 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2151 | |
| 2152 | if (out.IsDoubleStackSlot()) { |
| 2153 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2154 | } else { |
| 2155 | __ fstpl(Address(ESP, 0)); |
| 2156 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2157 | codegen_->Move64(out, stack_temp); |
| 2158 | } |
| 2159 | |
| 2160 | // Remove the temporary stack space we allocated. |
| 2161 | if (adjustment != 0) { |
| 2162 | __ addl(ESP, Immediate(adjustment)); |
| 2163 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2164 | break; |
| 2165 | } |
| 2166 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2167 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2168 | // Processing a Dex `float-to-double' instruction. |
| 2169 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | |
| 2172 | default: |
| 2173 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2174 | << " to " << result_type; |
| 2175 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | |
| 2178 | default: |
| 2179 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2180 | << " to " << result_type; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2184 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2185 | LocationSummary* locations = |
| 2186 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2187 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2188 | case Primitive::kPrimInt: { |
| 2189 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2190 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2191 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2192 | break; |
| 2193 | } |
| 2194 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2195 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2196 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2197 | locations->SetInAt(1, Location::Any()); |
| 2198 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2199 | break; |
| 2200 | } |
| 2201 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2202 | case Primitive::kPrimFloat: |
| 2203 | case Primitive::kPrimDouble: { |
| 2204 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2205 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2206 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2207 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2208 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2209 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2210 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2211 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2212 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2213 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2217 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2218 | Location first = locations->InAt(0); |
| 2219 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2220 | Location out = locations->Out(); |
| 2221 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2222 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2223 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2224 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2225 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2226 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2227 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2228 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2229 | } else { |
| 2230 | __ leal(out.AsRegister<Register>(), Address( |
| 2231 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2232 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2233 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2234 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2235 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2236 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2237 | } else { |
| 2238 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2239 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2240 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2241 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2242 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2243 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2244 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2248 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2249 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2250 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2251 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2252 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2253 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2254 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2255 | } else { |
| 2256 | DCHECK(second.IsConstant()) << second; |
| 2257 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2258 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2259 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2260 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2261 | break; |
| 2262 | } |
| 2263 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2264 | case Primitive::kPrimFloat: { |
| 2265 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2266 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2267 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2268 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2269 | DCHECK(!const_area->NeedsMaterialization()); |
| 2270 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2271 | codegen_->LiteralFloatAddress( |
| 2272 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2273 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2274 | } else { |
| 2275 | DCHECK(second.IsStackSlot()); |
| 2276 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2277 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2278 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | case Primitive::kPrimDouble: { |
| 2282 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2283 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2284 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2285 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2286 | DCHECK(!const_area->NeedsMaterialization()); |
| 2287 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2288 | codegen_->LiteralDoubleAddress( |
| 2289 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2290 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2291 | } else { |
| 2292 | DCHECK(second.IsDoubleStackSlot()); |
| 2293 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2294 | } |
| 2295 | break; |
| 2296 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2297 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2298 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2299 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2303 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2304 | LocationSummary* locations = |
| 2305 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2306 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2307 | case Primitive::kPrimInt: |
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 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2314 | case Primitive::kPrimFloat: |
| 2315 | case Primitive::kPrimDouble: { |
| 2316 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2317 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2318 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2319 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2320 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2321 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2322 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2323 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2324 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2328 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2329 | Location first = locations->InAt(0); |
| 2330 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2331 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2332 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2333 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2334 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2335 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2336 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2337 | __ subl(first.AsRegister<Register>(), |
| 2338 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2339 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2340 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2341 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2342 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2346 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2347 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2348 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2349 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2350 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2351 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2352 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2353 | } else { |
| 2354 | DCHECK(second.IsConstant()) << second; |
| 2355 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2356 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2357 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2358 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2359 | break; |
| 2360 | } |
| 2361 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2362 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2363 | if (second.IsFpuRegister()) { |
| 2364 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2365 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2366 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2367 | DCHECK(!const_area->NeedsMaterialization()); |
| 2368 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2369 | codegen_->LiteralFloatAddress( |
| 2370 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2371 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2372 | } else { |
| 2373 | DCHECK(second.IsStackSlot()); |
| 2374 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2375 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2376 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2380 | if (second.IsFpuRegister()) { |
| 2381 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2382 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2383 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2384 | DCHECK(!const_area->NeedsMaterialization()); |
| 2385 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2386 | codegen_->LiteralDoubleAddress( |
| 2387 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2388 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2389 | } else { |
| 2390 | DCHECK(second.IsDoubleStackSlot()); |
| 2391 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2392 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2393 | break; |
| 2394 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2395 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2396 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2397 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2401 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2402 | LocationSummary* locations = |
| 2403 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2404 | switch (mul->GetResultType()) { |
| 2405 | case Primitive::kPrimInt: |
| 2406 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2407 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2408 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2409 | // Can use 3 operand multiply. |
| 2410 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2411 | } else { |
| 2412 | locations->SetOut(Location::SameAsFirstInput()); |
| 2413 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2414 | break; |
| 2415 | case Primitive::kPrimLong: { |
| 2416 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2417 | locations->SetInAt(1, Location::Any()); |
| 2418 | locations->SetOut(Location::SameAsFirstInput()); |
| 2419 | // Needed for imul on 32bits with 64bits output. |
| 2420 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2421 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2422 | break; |
| 2423 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2424 | case Primitive::kPrimFloat: |
| 2425 | case Primitive::kPrimDouble: { |
| 2426 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2427 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2428 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2429 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2430 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2431 | |
| 2432 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2433 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2434 | } |
| 2435 | } |
| 2436 | |
| 2437 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2438 | LocationSummary* locations = mul->GetLocations(); |
| 2439 | Location first = locations->InAt(0); |
| 2440 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2441 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2442 | |
| 2443 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2444 | case Primitive::kPrimInt: |
| 2445 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2446 | // problems where the output may not be the same as the first operand. |
| 2447 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2448 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2449 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2450 | } else if (second.IsRegister()) { |
| 2451 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2452 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2453 | } else { |
| 2454 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2455 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2456 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2457 | } |
| 2458 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2459 | |
| 2460 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2461 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2462 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2463 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2464 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2465 | |
| 2466 | DCHECK_EQ(EAX, eax); |
| 2467 | DCHECK_EQ(EDX, edx); |
| 2468 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2469 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2470 | // output: in1 |
| 2471 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2472 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2473 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2474 | if (second.IsConstant()) { |
| 2475 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2476 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2477 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2478 | int32_t low_value = Low32Bits(value); |
| 2479 | int32_t high_value = High32Bits(value); |
| 2480 | Immediate low(low_value); |
| 2481 | Immediate high(high_value); |
| 2482 | |
| 2483 | __ movl(eax, high); |
| 2484 | // eax <- in1.lo * in2.hi |
| 2485 | __ imull(eax, in1_lo); |
| 2486 | // in1.hi <- in1.hi * in2.lo |
| 2487 | __ imull(in1_hi, low); |
| 2488 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2489 | __ addl(in1_hi, eax); |
| 2490 | // move in2_lo to eax to prepare for double precision |
| 2491 | __ movl(eax, low); |
| 2492 | // edx:eax <- in1.lo * in2.lo |
| 2493 | __ mull(in1_lo); |
| 2494 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2495 | __ addl(in1_hi, edx); |
| 2496 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2497 | __ movl(in1_lo, eax); |
| 2498 | } else if (second.IsRegisterPair()) { |
| 2499 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2500 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2501 | |
| 2502 | __ movl(eax, in2_hi); |
| 2503 | // eax <- in1.lo * in2.hi |
| 2504 | __ imull(eax, in1_lo); |
| 2505 | // in1.hi <- in1.hi * in2.lo |
| 2506 | __ imull(in1_hi, in2_lo); |
| 2507 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2508 | __ addl(in1_hi, eax); |
| 2509 | // move in1_lo to eax to prepare for double precision |
| 2510 | __ movl(eax, in1_lo); |
| 2511 | // edx:eax <- in1.lo * in2.lo |
| 2512 | __ mull(in2_lo); |
| 2513 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2514 | __ addl(in1_hi, edx); |
| 2515 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2516 | __ movl(in1_lo, eax); |
| 2517 | } else { |
| 2518 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2519 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2520 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2521 | |
| 2522 | __ movl(eax, in2_hi); |
| 2523 | // eax <- in1.lo * in2.hi |
| 2524 | __ imull(eax, in1_lo); |
| 2525 | // in1.hi <- in1.hi * in2.lo |
| 2526 | __ imull(in1_hi, in2_lo); |
| 2527 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2528 | __ addl(in1_hi, eax); |
| 2529 | // move in1_lo to eax to prepare for double precision |
| 2530 | __ movl(eax, in1_lo); |
| 2531 | // edx:eax <- in1.lo * in2.lo |
| 2532 | __ mull(in2_lo); |
| 2533 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2534 | __ addl(in1_hi, edx); |
| 2535 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2536 | __ movl(in1_lo, eax); |
| 2537 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2538 | |
| 2539 | break; |
| 2540 | } |
| 2541 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2542 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2543 | DCHECK(first.Equals(locations->Out())); |
| 2544 | if (second.IsFpuRegister()) { |
| 2545 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2546 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2547 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2548 | DCHECK(!const_area->NeedsMaterialization()); |
| 2549 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2550 | codegen_->LiteralFloatAddress( |
| 2551 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2552 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2553 | } else { |
| 2554 | DCHECK(second.IsStackSlot()); |
| 2555 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2556 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2557 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2561 | DCHECK(first.Equals(locations->Out())); |
| 2562 | if (second.IsFpuRegister()) { |
| 2563 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2564 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2565 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2566 | DCHECK(!const_area->NeedsMaterialization()); |
| 2567 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2568 | codegen_->LiteralDoubleAddress( |
| 2569 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2570 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2571 | } else { |
| 2572 | DCHECK(second.IsDoubleStackSlot()); |
| 2573 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2574 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2575 | break; |
| 2576 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2577 | |
| 2578 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2579 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2580 | } |
| 2581 | } |
| 2582 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2583 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2584 | uint32_t temp_offset, |
| 2585 | uint32_t stack_adjustment, |
| 2586 | bool is_fp, |
| 2587 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2588 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2589 | DCHECK(!is_wide); |
| 2590 | if (is_fp) { |
| 2591 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2592 | } else { |
| 2593 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2594 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2595 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2596 | DCHECK(is_wide); |
| 2597 | if (is_fp) { |
| 2598 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2599 | } else { |
| 2600 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2601 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2602 | } else { |
| 2603 | // 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] | 2604 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2605 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2606 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2607 | if (is_fp) { |
| 2608 | __ flds(Address(ESP, temp_offset)); |
| 2609 | } else { |
| 2610 | __ filds(Address(ESP, temp_offset)); |
| 2611 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2612 | } else { |
| 2613 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2614 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2615 | if (is_fp) { |
| 2616 | __ fldl(Address(ESP, temp_offset)); |
| 2617 | } else { |
| 2618 | __ fildl(Address(ESP, temp_offset)); |
| 2619 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2625 | Primitive::Type type = rem->GetResultType(); |
| 2626 | bool is_float = type == Primitive::kPrimFloat; |
| 2627 | size_t elem_size = Primitive::ComponentSize(type); |
| 2628 | LocationSummary* locations = rem->GetLocations(); |
| 2629 | Location first = locations->InAt(0); |
| 2630 | Location second = locations->InAt(1); |
| 2631 | Location out = locations->Out(); |
| 2632 | |
| 2633 | // Create stack space for 2 elements. |
| 2634 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2635 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2636 | |
| 2637 | // 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] | 2638 | const bool is_wide = !is_float; |
| 2639 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2640 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2641 | |
| 2642 | // Loop doing FPREM until we stabilize. |
| 2643 | Label retry; |
| 2644 | __ Bind(&retry); |
| 2645 | __ fprem(); |
| 2646 | |
| 2647 | // Move FP status to AX. |
| 2648 | __ fstsw(); |
| 2649 | |
| 2650 | // And see if the argument reduction is complete. This is signaled by the |
| 2651 | // C2 FPU flag bit set to 0. |
| 2652 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2653 | __ j(kNotEqual, &retry); |
| 2654 | |
| 2655 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2656 | // Store FP top of stack to real stack. |
| 2657 | if (is_float) { |
| 2658 | __ fsts(Address(ESP, 0)); |
| 2659 | } else { |
| 2660 | __ fstl(Address(ESP, 0)); |
| 2661 | } |
| 2662 | |
| 2663 | // Pop the 2 items from the FP stack. |
| 2664 | __ fucompp(); |
| 2665 | |
| 2666 | // Load the value from the stack into an XMM register. |
| 2667 | DCHECK(out.IsFpuRegister()) << out; |
| 2668 | if (is_float) { |
| 2669 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2670 | } else { |
| 2671 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2672 | } |
| 2673 | |
| 2674 | // And remove the temporary stack space we allocated. |
| 2675 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2676 | } |
| 2677 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2678 | |
| 2679 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2680 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2681 | |
| 2682 | LocationSummary* locations = instruction->GetLocations(); |
| 2683 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2684 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2685 | |
| 2686 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2687 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2688 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2689 | |
| 2690 | DCHECK(imm == 1 || imm == -1); |
| 2691 | |
| 2692 | if (instruction->IsRem()) { |
| 2693 | __ xorl(out_register, out_register); |
| 2694 | } else { |
| 2695 | __ movl(out_register, input_register); |
| 2696 | if (imm == -1) { |
| 2697 | __ negl(out_register); |
| 2698 | } |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2703 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2704 | LocationSummary* locations = instruction->GetLocations(); |
| 2705 | |
| 2706 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2707 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2708 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2709 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2710 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2711 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2712 | |
| 2713 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2714 | __ testl(input_register, input_register); |
| 2715 | __ cmovl(kGreaterEqual, num, input_register); |
| 2716 | int shift = CTZ(imm); |
| 2717 | __ sarl(num, Immediate(shift)); |
| 2718 | |
| 2719 | if (imm < 0) { |
| 2720 | __ negl(num); |
| 2721 | } |
| 2722 | |
| 2723 | __ movl(out_register, num); |
| 2724 | } |
| 2725 | |
| 2726 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2727 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2728 | |
| 2729 | LocationSummary* locations = instruction->GetLocations(); |
| 2730 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2731 | |
| 2732 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2733 | Register out = locations->Out().AsRegister<Register>(); |
| 2734 | Register num; |
| 2735 | Register edx; |
| 2736 | |
| 2737 | if (instruction->IsDiv()) { |
| 2738 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2739 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2740 | } else { |
| 2741 | edx = locations->Out().AsRegister<Register>(); |
| 2742 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2743 | } |
| 2744 | |
| 2745 | DCHECK_EQ(EAX, eax); |
| 2746 | DCHECK_EQ(EDX, edx); |
| 2747 | if (instruction->IsDiv()) { |
| 2748 | DCHECK_EQ(EAX, out); |
| 2749 | } else { |
| 2750 | DCHECK_EQ(EDX, out); |
| 2751 | } |
| 2752 | |
| 2753 | int64_t magic; |
| 2754 | int shift; |
| 2755 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2756 | |
| 2757 | Label ndiv; |
| 2758 | Label end; |
| 2759 | // If numerator is 0, the result is 0, no computation needed. |
| 2760 | __ testl(eax, eax); |
| 2761 | __ j(kNotEqual, &ndiv); |
| 2762 | |
| 2763 | __ xorl(out, out); |
| 2764 | __ jmp(&end); |
| 2765 | |
| 2766 | __ Bind(&ndiv); |
| 2767 | |
| 2768 | // Save the numerator. |
| 2769 | __ movl(num, eax); |
| 2770 | |
| 2771 | // EAX = magic |
| 2772 | __ movl(eax, Immediate(magic)); |
| 2773 | |
| 2774 | // EDX:EAX = magic * numerator |
| 2775 | __ imull(num); |
| 2776 | |
| 2777 | if (imm > 0 && magic < 0) { |
| 2778 | // EDX += num |
| 2779 | __ addl(edx, num); |
| 2780 | } else if (imm < 0 && magic > 0) { |
| 2781 | __ subl(edx, num); |
| 2782 | } |
| 2783 | |
| 2784 | // Shift if needed. |
| 2785 | if (shift != 0) { |
| 2786 | __ sarl(edx, Immediate(shift)); |
| 2787 | } |
| 2788 | |
| 2789 | // EDX += 1 if EDX < 0 |
| 2790 | __ movl(eax, edx); |
| 2791 | __ shrl(edx, Immediate(31)); |
| 2792 | __ addl(edx, eax); |
| 2793 | |
| 2794 | if (instruction->IsRem()) { |
| 2795 | __ movl(eax, num); |
| 2796 | __ imull(edx, Immediate(imm)); |
| 2797 | __ subl(eax, edx); |
| 2798 | __ movl(edx, eax); |
| 2799 | } else { |
| 2800 | __ movl(eax, edx); |
| 2801 | } |
| 2802 | __ Bind(&end); |
| 2803 | } |
| 2804 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2805 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2806 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2807 | |
| 2808 | LocationSummary* locations = instruction->GetLocations(); |
| 2809 | Location out = locations->Out(); |
| 2810 | Location first = locations->InAt(0); |
| 2811 | Location second = locations->InAt(1); |
| 2812 | bool is_div = instruction->IsDiv(); |
| 2813 | |
| 2814 | switch (instruction->GetResultType()) { |
| 2815 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2816 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2817 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2818 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2819 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2820 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2821 | |
| 2822 | if (imm == 0) { |
| 2823 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2824 | } else if (imm == 1 || imm == -1) { |
| 2825 | DivRemOneOrMinusOne(instruction); |
| 2826 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2827 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2828 | } else { |
| 2829 | DCHECK(imm <= -2 || imm >= 2); |
| 2830 | GenerateDivRemWithAnyConstant(instruction); |
| 2831 | } |
| 2832 | } else { |
| 2833 | SlowPathCodeX86* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2834 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2835 | is_div); |
| 2836 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2837 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2838 | Register second_reg = second.AsRegister<Register>(); |
| 2839 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2840 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2841 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2842 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2843 | __ cmpl(second_reg, Immediate(-1)); |
| 2844 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2845 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2846 | // edx:eax <- sign-extended of eax |
| 2847 | __ cdq(); |
| 2848 | // eax = quotient, edx = remainder |
| 2849 | __ idivl(second_reg); |
| 2850 | __ Bind(slow_path->GetExitLabel()); |
| 2851 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | } |
| 2854 | |
| 2855 | case Primitive::kPrimLong: { |
| 2856 | InvokeRuntimeCallingConvention calling_convention; |
| 2857 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2858 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2859 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2860 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2861 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2862 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2863 | |
| 2864 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2865 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2866 | instruction, |
| 2867 | instruction->GetDexPc(), |
| 2868 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2869 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2870 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2871 | instruction, |
| 2872 | instruction->GetDexPc(), |
| 2873 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2874 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2875 | break; |
| 2876 | } |
| 2877 | |
| 2878 | default: |
| 2879 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2880 | } |
| 2881 | } |
| 2882 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2883 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2884 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2885 | ? LocationSummary::kCall |
| 2886 | : LocationSummary::kNoCall; |
| 2887 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2888 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2889 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2890 | case Primitive::kPrimInt: { |
| 2891 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2892 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2893 | locations->SetOut(Location::SameAsFirstInput()); |
| 2894 | // Intel uses edx:eax as the dividend. |
| 2895 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2896 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2897 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 2898 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2899 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2900 | locations->AddTemp(Location::RequiresRegister()); |
| 2901 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2904 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2905 | InvokeRuntimeCallingConvention calling_convention; |
| 2906 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 2907 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 2908 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 2909 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 2910 | // Runtime helper puts the result in EAX, EDX. |
| 2911 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2912 | break; |
| 2913 | } |
| 2914 | case Primitive::kPrimFloat: |
| 2915 | case Primitive::kPrimDouble: { |
| 2916 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2917 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2918 | locations->SetOut(Location::SameAsFirstInput()); |
| 2919 | break; |
| 2920 | } |
| 2921 | |
| 2922 | default: |
| 2923 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2924 | } |
| 2925 | } |
| 2926 | |
| 2927 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 2928 | LocationSummary* locations = div->GetLocations(); |
| 2929 | Location first = locations->InAt(0); |
| 2930 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2931 | |
| 2932 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2933 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2934 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2935 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2936 | break; |
| 2937 | } |
| 2938 | |
| 2939 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2940 | if (second.IsFpuRegister()) { |
| 2941 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2942 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2943 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2944 | DCHECK(!const_area->NeedsMaterialization()); |
| 2945 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 2946 | codegen_->LiteralFloatAddress( |
| 2947 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2948 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2949 | } else { |
| 2950 | DCHECK(second.IsStackSlot()); |
| 2951 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2952 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2953 | break; |
| 2954 | } |
| 2955 | |
| 2956 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2957 | if (second.IsFpuRegister()) { |
| 2958 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2959 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2960 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2961 | DCHECK(!const_area->NeedsMaterialization()); |
| 2962 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 2963 | codegen_->LiteralDoubleAddress( |
| 2964 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2965 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2966 | } else { |
| 2967 | DCHECK(second.IsDoubleStackSlot()); |
| 2968 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2969 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2970 | break; |
| 2971 | } |
| 2972 | |
| 2973 | default: |
| 2974 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 2975 | } |
| 2976 | } |
| 2977 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2978 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2979 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2980 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2981 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 2982 | ? LocationSummary::kCall |
| 2983 | : LocationSummary::kNoCall; |
| 2984 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2985 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 2986 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2987 | case Primitive::kPrimInt: { |
| 2988 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2989 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2990 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2991 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2992 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 2993 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2994 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2995 | locations->AddTemp(Location::RequiresRegister()); |
| 2996 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2997 | break; |
| 2998 | } |
| 2999 | case Primitive::kPrimLong: { |
| 3000 | InvokeRuntimeCallingConvention calling_convention; |
| 3001 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3002 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3003 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3004 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3005 | // Runtime helper puts the result in EAX, EDX. |
| 3006 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3007 | break; |
| 3008 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3009 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3010 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3011 | locations->SetInAt(0, Location::Any()); |
| 3012 | locations->SetInAt(1, Location::Any()); |
| 3013 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3014 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3015 | break; |
| 3016 | } |
| 3017 | |
| 3018 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3019 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3024 | Primitive::Type type = rem->GetResultType(); |
| 3025 | switch (type) { |
| 3026 | case Primitive::kPrimInt: |
| 3027 | case Primitive::kPrimLong: { |
| 3028 | GenerateDivRemIntegral(rem); |
| 3029 | break; |
| 3030 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3031 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3032 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3033 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3034 | break; |
| 3035 | } |
| 3036 | default: |
| 3037 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3038 | } |
| 3039 | } |
| 3040 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3041 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 659562a | 2015-09-14 21:26:33 +0000 | [diff] [blame^] | 3042 | LocationSummary* locations = |
| 3043 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3044 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3045 | case Primitive::kPrimByte: |
| 3046 | case Primitive::kPrimChar: |
| 3047 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3048 | case Primitive::kPrimInt: { |
| 3049 | locations->SetInAt(0, Location::Any()); |
| 3050 | break; |
| 3051 | } |
| 3052 | case Primitive::kPrimLong: { |
| 3053 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3054 | if (!instruction->IsConstant()) { |
| 3055 | locations->AddTemp(Location::RequiresRegister()); |
| 3056 | } |
| 3057 | break; |
| 3058 | } |
| 3059 | default: |
| 3060 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3061 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3062 | if (instruction->HasUses()) { |
| 3063 | locations->SetOut(Location::SameAsFirstInput()); |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
| 3068 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
| 3069 | codegen_->AddSlowPath(slow_path); |
| 3070 | |
| 3071 | LocationSummary* locations = instruction->GetLocations(); |
| 3072 | Location value = locations->InAt(0); |
| 3073 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3074 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3075 | case Primitive::kPrimByte: |
| 3076 | case Primitive::kPrimChar: |
| 3077 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3078 | case Primitive::kPrimInt: { |
| 3079 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3080 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3081 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3082 | } else if (value.IsStackSlot()) { |
| 3083 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3084 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3085 | } else { |
| 3086 | DCHECK(value.IsConstant()) << value; |
| 3087 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3088 | __ jmp(slow_path->GetEntryLabel()); |
| 3089 | } |
| 3090 | } |
| 3091 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3092 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3093 | case Primitive::kPrimLong: { |
| 3094 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3095 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3096 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3097 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3098 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3099 | } else { |
| 3100 | DCHECK(value.IsConstant()) << value; |
| 3101 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3102 | __ jmp(slow_path->GetEntryLabel()); |
| 3103 | } |
| 3104 | } |
| 3105 | break; |
| 3106 | } |
| 3107 | default: |
| 3108 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3109 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3112 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3113 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3114 | |
| 3115 | LocationSummary* locations = |
| 3116 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3117 | |
| 3118 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3119 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3120 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3121 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3122 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3123 | // The shift count needs to be in CL or a constant. |
| 3124 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3125 | locations->SetOut(Location::SameAsFirstInput()); |
| 3126 | break; |
| 3127 | } |
| 3128 | default: |
| 3129 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3134 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3135 | |
| 3136 | LocationSummary* locations = op->GetLocations(); |
| 3137 | Location first = locations->InAt(0); |
| 3138 | Location second = locations->InAt(1); |
| 3139 | DCHECK(first.Equals(locations->Out())); |
| 3140 | |
| 3141 | switch (op->GetResultType()) { |
| 3142 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3143 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3144 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3145 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3146 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3147 | DCHECK_EQ(ECX, second_reg); |
| 3148 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3149 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3150 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3151 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3152 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3153 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3154 | } |
| 3155 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3156 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3157 | if (shift == 0) { |
| 3158 | return; |
| 3159 | } |
| 3160 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3161 | if (op->IsShl()) { |
| 3162 | __ shll(first_reg, imm); |
| 3163 | } else if (op->IsShr()) { |
| 3164 | __ sarl(first_reg, imm); |
| 3165 | } else { |
| 3166 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3167 | } |
| 3168 | } |
| 3169 | break; |
| 3170 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3171 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3172 | if (second.IsRegister()) { |
| 3173 | Register second_reg = second.AsRegister<Register>(); |
| 3174 | DCHECK_EQ(ECX, second_reg); |
| 3175 | if (op->IsShl()) { |
| 3176 | GenerateShlLong(first, second_reg); |
| 3177 | } else if (op->IsShr()) { |
| 3178 | GenerateShrLong(first, second_reg); |
| 3179 | } else { |
| 3180 | GenerateUShrLong(first, second_reg); |
| 3181 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3182 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3183 | // Shift by a constant. |
| 3184 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3185 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3186 | if (shift != 0) { |
| 3187 | if (op->IsShl()) { |
| 3188 | GenerateShlLong(first, shift); |
| 3189 | } else if (op->IsShr()) { |
| 3190 | GenerateShrLong(first, shift); |
| 3191 | } else { |
| 3192 | GenerateUShrLong(first, shift); |
| 3193 | } |
| 3194 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3195 | } |
| 3196 | break; |
| 3197 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3198 | default: |
| 3199 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3200 | } |
| 3201 | } |
| 3202 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3203 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3204 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3205 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3206 | if (shift == 1) { |
| 3207 | // This is just an addition. |
| 3208 | __ addl(low, low); |
| 3209 | __ adcl(high, high); |
| 3210 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3211 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3212 | codegen_->EmitParallelMoves( |
| 3213 | loc.ToLow(), |
| 3214 | loc.ToHigh(), |
| 3215 | Primitive::kPrimInt, |
| 3216 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3217 | loc.ToLow(), |
| 3218 | Primitive::kPrimInt); |
| 3219 | } else if (shift > 32) { |
| 3220 | // Low part becomes 0. High part is low part << (shift-32). |
| 3221 | __ movl(high, low); |
| 3222 | __ shll(high, Immediate(shift - 32)); |
| 3223 | __ xorl(low, low); |
| 3224 | } else { |
| 3225 | // Between 1 and 31. |
| 3226 | __ shld(high, low, Immediate(shift)); |
| 3227 | __ shll(low, Immediate(shift)); |
| 3228 | } |
| 3229 | } |
| 3230 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3231 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
| 3232 | Label done; |
| 3233 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3234 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3235 | __ testl(shifter, Immediate(32)); |
| 3236 | __ j(kEqual, &done); |
| 3237 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3238 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3239 | __ Bind(&done); |
| 3240 | } |
| 3241 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3242 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3243 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3244 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3245 | if (shift == 32) { |
| 3246 | // Need to copy the sign. |
| 3247 | DCHECK_NE(low, high); |
| 3248 | __ movl(low, high); |
| 3249 | __ sarl(high, Immediate(31)); |
| 3250 | } else if (shift > 32) { |
| 3251 | DCHECK_NE(low, high); |
| 3252 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3253 | __ movl(low, high); |
| 3254 | __ sarl(high, Immediate(31)); |
| 3255 | __ sarl(low, Immediate(shift - 32)); |
| 3256 | } else { |
| 3257 | // Between 1 and 31. |
| 3258 | __ shrd(low, high, Immediate(shift)); |
| 3259 | __ sarl(high, Immediate(shift)); |
| 3260 | } |
| 3261 | } |
| 3262 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3263 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
| 3264 | Label done; |
| 3265 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3266 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3267 | __ testl(shifter, Immediate(32)); |
| 3268 | __ j(kEqual, &done); |
| 3269 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3270 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3271 | __ Bind(&done); |
| 3272 | } |
| 3273 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3274 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3275 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3276 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3277 | if (shift == 32) { |
| 3278 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3279 | codegen_->EmitParallelMoves( |
| 3280 | loc.ToHigh(), |
| 3281 | loc.ToLow(), |
| 3282 | Primitive::kPrimInt, |
| 3283 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3284 | loc.ToHigh(), |
| 3285 | Primitive::kPrimInt); |
| 3286 | } else if (shift > 32) { |
| 3287 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3288 | __ movl(low, high); |
| 3289 | __ shrl(low, Immediate(shift - 32)); |
| 3290 | __ xorl(high, high); |
| 3291 | } else { |
| 3292 | // Between 1 and 31. |
| 3293 | __ shrd(low, high, Immediate(shift)); |
| 3294 | __ shrl(high, Immediate(shift)); |
| 3295 | } |
| 3296 | } |
| 3297 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3298 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
| 3299 | Label done; |
| 3300 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3301 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3302 | __ testl(shifter, Immediate(32)); |
| 3303 | __ j(kEqual, &done); |
| 3304 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3305 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3306 | __ Bind(&done); |
| 3307 | } |
| 3308 | |
| 3309 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3310 | HandleShift(shl); |
| 3311 | } |
| 3312 | |
| 3313 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3314 | HandleShift(shl); |
| 3315 | } |
| 3316 | |
| 3317 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3318 | HandleShift(shr); |
| 3319 | } |
| 3320 | |
| 3321 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3322 | HandleShift(shr); |
| 3323 | } |
| 3324 | |
| 3325 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3326 | HandleShift(ushr); |
| 3327 | } |
| 3328 | |
| 3329 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3330 | HandleShift(ushr); |
| 3331 | } |
| 3332 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3333 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3334 | LocationSummary* locations = |
| 3335 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3336 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3337 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3338 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3339 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3343 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3344 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3345 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3346 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3347 | codegen_->InvokeRuntime( |
| 3348 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3349 | instruction, |
| 3350 | instruction->GetDexPc(), |
| 3351 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3352 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3353 | } |
| 3354 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3355 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3356 | LocationSummary* locations = |
| 3357 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3358 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3359 | InvokeRuntimeCallingConvention calling_convention; |
| 3360 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3361 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3362 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3366 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3367 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3368 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3369 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3370 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3371 | codegen_->InvokeRuntime( |
| 3372 | Address::Absolute(GetThreadOffset<kX86WordSize>(instruction->GetEntrypoint())), |
| 3373 | instruction, |
| 3374 | instruction->GetDexPc(), |
| 3375 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3376 | DCHECK(!codegen_->IsLeafMethod()); |
| 3377 | } |
| 3378 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3379 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3380 | LocationSummary* locations = |
| 3381 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3382 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3383 | if (location.IsStackSlot()) { |
| 3384 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3385 | } else if (location.IsDoubleStackSlot()) { |
| 3386 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3387 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3388 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3389 | } |
| 3390 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3391 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3392 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3393 | } |
| 3394 | |
| 3395 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3396 | LocationSummary* locations = |
| 3397 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3398 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3399 | } |
| 3400 | |
| 3401 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3402 | } |
| 3403 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3404 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3405 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3406 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3407 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3408 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3411 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3412 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3413 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3414 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3415 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3416 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3417 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3418 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3419 | break; |
| 3420 | |
| 3421 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3422 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3423 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3424 | break; |
| 3425 | |
| 3426 | default: |
| 3427 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3428 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3429 | } |
| 3430 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3431 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3432 | LocationSummary* locations = |
| 3433 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3434 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3435 | locations->SetOut(Location::SameAsFirstInput()); |
| 3436 | } |
| 3437 | |
| 3438 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3439 | LocationSummary* locations = bool_not->GetLocations(); |
| 3440 | Location in = locations->InAt(0); |
| 3441 | Location out = locations->Out(); |
| 3442 | DCHECK(in.Equals(out)); |
| 3443 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3444 | } |
| 3445 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3446 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3447 | LocationSummary* locations = |
| 3448 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3449 | switch (compare->InputAt(0)->GetType()) { |
| 3450 | case Primitive::kPrimLong: { |
| 3451 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3452 | locations->SetInAt(1, Location::Any()); |
| 3453 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3454 | break; |
| 3455 | } |
| 3456 | case Primitive::kPrimFloat: |
| 3457 | case Primitive::kPrimDouble: { |
| 3458 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3459 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3460 | locations->SetOut(Location::RequiresRegister()); |
| 3461 | break; |
| 3462 | } |
| 3463 | default: |
| 3464 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3465 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3469 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3470 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3471 | Location left = locations->InAt(0); |
| 3472 | Location right = locations->InAt(1); |
| 3473 | |
| 3474 | Label less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3475 | switch (compare->InputAt(0)->GetType()) { |
| 3476 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3477 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3478 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3479 | int32_t val_low = 0; |
| 3480 | int32_t val_high = 0; |
| 3481 | bool right_is_const = false; |
| 3482 | |
| 3483 | if (right.IsConstant()) { |
| 3484 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3485 | right_is_const = true; |
| 3486 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3487 | val_low = Low32Bits(val); |
| 3488 | val_high = High32Bits(val); |
| 3489 | } |
| 3490 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3491 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3492 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3493 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3494 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3495 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3496 | DCHECK(right_is_const) << right; |
| 3497 | if (val_high == 0) { |
| 3498 | __ testl(left_high, left_high); |
| 3499 | } else { |
| 3500 | __ cmpl(left_high, Immediate(val_high)); |
| 3501 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3502 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3503 | __ j(kLess, &less); // Signed compare. |
| 3504 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3505 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3506 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3507 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3508 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3509 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3510 | DCHECK(right_is_const) << right; |
| 3511 | if (val_low == 0) { |
| 3512 | __ testl(left_low, left_low); |
| 3513 | } else { |
| 3514 | __ cmpl(left_low, Immediate(val_low)); |
| 3515 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3516 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3517 | break; |
| 3518 | } |
| 3519 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3520 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3521 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3522 | break; |
| 3523 | } |
| 3524 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3525 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3526 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3527 | break; |
| 3528 | } |
| 3529 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3530 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3531 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3532 | __ movl(out, Immediate(0)); |
| 3533 | __ j(kEqual, &done); |
| 3534 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3535 | |
| 3536 | __ Bind(&greater); |
| 3537 | __ movl(out, Immediate(1)); |
| 3538 | __ jmp(&done); |
| 3539 | |
| 3540 | __ Bind(&less); |
| 3541 | __ movl(out, Immediate(-1)); |
| 3542 | |
| 3543 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3544 | } |
| 3545 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3546 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3547 | LocationSummary* locations = |
| 3548 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3549 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3550 | locations->SetInAt(i, Location::Any()); |
| 3551 | } |
| 3552 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3556 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3557 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3558 | } |
| 3559 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3560 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3561 | /* |
| 3562 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3563 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3564 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3565 | */ |
| 3566 | switch (kind) { |
| 3567 | case MemBarrierKind::kAnyAny: { |
| 3568 | __ mfence(); |
| 3569 | break; |
| 3570 | } |
| 3571 | case MemBarrierKind::kAnyStore: |
| 3572 | case MemBarrierKind::kLoadAny: |
| 3573 | case MemBarrierKind::kStoreStore: { |
| 3574 | // nop |
| 3575 | break; |
| 3576 | } |
| 3577 | default: |
| 3578 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3579 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3582 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3583 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3584 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3585 | switch (invoke->GetMethodLoadKind()) { |
| 3586 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3587 | // temp = thread->string_init_entrypoint |
| 3588 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3589 | break; |
| 3590 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3591 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3592 | break; |
| 3593 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3594 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3595 | break; |
| 3596 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3597 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3598 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3599 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3600 | break; |
| 3601 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3602 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3603 | FALLTHROUGH_INTENDED; |
| 3604 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3605 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3606 | Register method_reg; |
| 3607 | Register reg = temp.AsRegister<Register>(); |
| 3608 | if (current_method.IsRegister()) { |
| 3609 | method_reg = current_method.AsRegister<Register>(); |
| 3610 | } else { |
| 3611 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3612 | DCHECK(!current_method.IsValid()); |
| 3613 | method_reg = reg; |
| 3614 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3615 | } |
| 3616 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3617 | __ movl(reg, Address(method_reg, |
| 3618 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3619 | // temp = temp[index_in_cache] |
| 3620 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3621 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3622 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3623 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | switch (invoke->GetCodePtrLocation()) { |
| 3627 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3628 | __ call(GetFrameEntryLabel()); |
| 3629 | break; |
| 3630 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3631 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3632 | Label* label = &relative_call_patches_.back().label; |
| 3633 | __ call(label); // Bind to the patch label, override at link time. |
| 3634 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3635 | break; |
| 3636 | } |
| 3637 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3638 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3639 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3640 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3641 | FALLTHROUGH_INTENDED; |
| 3642 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3643 | // (callee_method + offset_of_quick_compiled_code)() |
| 3644 | __ call(Address(callee_method.AsRegister<Register>(), |
| 3645 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3646 | kX86WordSize).Int32Value())); |
| 3647 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3651 | } |
| 3652 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3653 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 3654 | Register temp = temp_in.AsRegister<Register>(); |
| 3655 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3656 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| 3657 | LocationSummary* locations = invoke->GetLocations(); |
| 3658 | Location receiver = locations->InAt(0); |
| 3659 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3660 | // temp = object->GetClass(); |
| 3661 | DCHECK(receiver.IsRegister()); |
| 3662 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| 3663 | MaybeRecordImplicitNullCheck(invoke); |
| 3664 | __ MaybeUnpoisonHeapReference(temp); |
| 3665 | // temp = temp->GetMethodAt(method_offset); |
| 3666 | __ movl(temp, Address(temp, method_offset)); |
| 3667 | // call temp->GetEntryPoint(); |
| 3668 | __ call(Address( |
| 3669 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3670 | } |
| 3671 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3672 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3673 | DCHECK(linker_patches->empty()); |
| 3674 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3675 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3676 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3677 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3678 | uint32_t literal_offset = info.label.Position() - 4; |
| 3679 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3680 | info.target_method.dex_file, |
| 3681 | info.target_method.dex_method_index)); |
| 3682 | } |
| 3683 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3684 | // The label points to the end of the "call" insn but the literal offset for method |
| 3685 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3686 | uint32_t literal_offset = info.label.Position() - 4; |
| 3687 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3688 | info.target_method.dex_file, |
| 3689 | info.target_method.dex_method_index)); |
| 3690 | } |
| 3691 | } |
| 3692 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3693 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3694 | Register card, |
| 3695 | Register object, |
| 3696 | Register value, |
| 3697 | bool value_can_be_null) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3698 | Label is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3699 | if (value_can_be_null) { |
| 3700 | __ testl(value, value); |
| 3701 | __ j(kEqual, &is_null); |
| 3702 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3703 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3704 | __ movl(temp, object); |
| 3705 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3706 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3707 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3708 | if (value_can_be_null) { |
| 3709 | __ Bind(&is_null); |
| 3710 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3711 | } |
| 3712 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3713 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3714 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3715 | LocationSummary* locations = |
| 3716 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3717 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3718 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3719 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3720 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3721 | } else { |
| 3722 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3723 | // the object's location. |
| 3724 | locations->SetOut(Location::RequiresRegister(), |
| 3725 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3726 | : Location::kNoOutputOverlap); |
| 3727 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3728 | |
| 3729 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3730 | // Long values can be loaded atomically into an XMM using movsd. |
| 3731 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3732 | // and then copy the XMM into the output 32bits at a time). |
| 3733 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3734 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3735 | } |
| 3736 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3737 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3738 | const FieldInfo& field_info) { |
| 3739 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3740 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3741 | LocationSummary* locations = instruction->GetLocations(); |
| 3742 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3743 | Location out = locations->Out(); |
| 3744 | bool is_volatile = field_info.IsVolatile(); |
| 3745 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3746 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3747 | |
| 3748 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3749 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3750 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3751 | break; |
| 3752 | } |
| 3753 | |
| 3754 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3755 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3756 | break; |
| 3757 | } |
| 3758 | |
| 3759 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3760 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3761 | break; |
| 3762 | } |
| 3763 | |
| 3764 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3765 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3766 | break; |
| 3767 | } |
| 3768 | |
| 3769 | case Primitive::kPrimInt: |
| 3770 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3771 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3772 | break; |
| 3773 | } |
| 3774 | |
| 3775 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3776 | if (is_volatile) { |
| 3777 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3778 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3779 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3780 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3781 | __ psrlq(temp, Immediate(32)); |
| 3782 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3783 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3784 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3785 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3786 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3787 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3788 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3789 | break; |
| 3790 | } |
| 3791 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3792 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3793 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3794 | break; |
| 3795 | } |
| 3796 | |
| 3797 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3798 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3799 | break; |
| 3800 | } |
| 3801 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3802 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3803 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3804 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3805 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3806 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3807 | // Longs are handled in the switch. |
| 3808 | if (field_type != Primitive::kPrimLong) { |
| 3809 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3810 | } |
| 3811 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3812 | if (is_volatile) { |
| 3813 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3814 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3815 | |
| 3816 | if (field_type == Primitive::kPrimNot) { |
| 3817 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3818 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3822 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3823 | |
| 3824 | LocationSummary* locations = |
| 3825 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3826 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3827 | bool is_volatile = field_info.IsVolatile(); |
| 3828 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3829 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3830 | || (field_type == Primitive::kPrimByte); |
| 3831 | |
| 3832 | // The register allocator does not support multiple |
| 3833 | // inputs that die at entry with one in a specific register. |
| 3834 | if (is_byte_type) { |
| 3835 | // Ensure the value is in a byte register. |
| 3836 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3837 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3838 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3839 | } else { |
| 3840 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3841 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3842 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3843 | // Temporary registers for the write barrier. |
| 3844 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3845 | // Ensure the card is in a byte register. |
| 3846 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3847 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3848 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3849 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3850 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3851 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3852 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3853 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3854 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3859 | const FieldInfo& field_info, |
| 3860 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3861 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3862 | |
| 3863 | LocationSummary* locations = instruction->GetLocations(); |
| 3864 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3865 | Location value = locations->InAt(1); |
| 3866 | bool is_volatile = field_info.IsVolatile(); |
| 3867 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3868 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3869 | bool needs_write_barrier = |
| 3870 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3871 | |
| 3872 | if (is_volatile) { |
| 3873 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3874 | } |
| 3875 | |
| 3876 | switch (field_type) { |
| 3877 | case Primitive::kPrimBoolean: |
| 3878 | case Primitive::kPrimByte: { |
| 3879 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3880 | break; |
| 3881 | } |
| 3882 | |
| 3883 | case Primitive::kPrimShort: |
| 3884 | case Primitive::kPrimChar: { |
| 3885 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3886 | break; |
| 3887 | } |
| 3888 | |
| 3889 | case Primitive::kPrimInt: |
| 3890 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3891 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3892 | // Note that in the case where `value` is a null reference, |
| 3893 | // we do not enter this block, as the reference does not |
| 3894 | // need poisoning. |
| 3895 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3896 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3897 | __ movl(temp, value.AsRegister<Register>()); |
| 3898 | __ PoisonHeapReference(temp); |
| 3899 | __ movl(Address(base, offset), temp); |
| 3900 | } else { |
| 3901 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 3902 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3903 | break; |
| 3904 | } |
| 3905 | |
| 3906 | case Primitive::kPrimLong: { |
| 3907 | if (is_volatile) { |
| 3908 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3909 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 3910 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 3911 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 3912 | __ punpckldq(temp1, temp2); |
| 3913 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3914 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3915 | } else { |
| 3916 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3917 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3918 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 3919 | } |
| 3920 | break; |
| 3921 | } |
| 3922 | |
| 3923 | case Primitive::kPrimFloat: { |
| 3924 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3925 | break; |
| 3926 | } |
| 3927 | |
| 3928 | case Primitive::kPrimDouble: { |
| 3929 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 3930 | break; |
| 3931 | } |
| 3932 | |
| 3933 | case Primitive::kPrimVoid: |
| 3934 | LOG(FATAL) << "Unreachable type " << field_type; |
| 3935 | UNREACHABLE(); |
| 3936 | } |
| 3937 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3938 | // Longs are handled in the switch. |
| 3939 | if (field_type != Primitive::kPrimLong) { |
| 3940 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3941 | } |
| 3942 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3943 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3944 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3945 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3946 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3949 | if (is_volatile) { |
| 3950 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3955 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3956 | } |
| 3957 | |
| 3958 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 3959 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3960 | } |
| 3961 | |
| 3962 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 3963 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3964 | } |
| 3965 | |
| 3966 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3967 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 3971 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 3972 | } |
| 3973 | |
| 3974 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3975 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3979 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 3980 | } |
| 3981 | |
| 3982 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 3983 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 659562a | 2015-09-14 21:26:33 +0000 | [diff] [blame^] | 3987 | LocationSummary* locations = |
| 3988 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3989 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3990 | ? Location::RequiresRegister() |
| 3991 | : Location::Any(); |
| 3992 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 3993 | if (instruction->HasUses()) { |
| 3994 | locations->SetOut(Location::SameAsFirstInput()); |
| 3995 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3996 | } |
| 3997 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 3998 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3999 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4000 | return; |
| 4001 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4002 | LocationSummary* locations = instruction->GetLocations(); |
| 4003 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4004 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4005 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4006 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4007 | } |
| 4008 | |
| 4009 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 4010 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4011 | codegen_->AddSlowPath(slow_path); |
| 4012 | |
| 4013 | LocationSummary* locations = instruction->GetLocations(); |
| 4014 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4015 | |
| 4016 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4017 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4018 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4019 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4020 | } else { |
| 4021 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 659562a | 2015-09-14 21:26:33 +0000 | [diff] [blame^] | 4022 | DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4023 | __ jmp(slow_path->GetEntryLabel()); |
| 4024 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4025 | } |
| 4026 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4027 | } |
| 4028 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4029 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 659562a | 2015-09-14 21:26:33 +0000 | [diff] [blame^] | 4030 | if (codegen_->GetCompilerOptions().GetImplicitNullChecks()) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4031 | GenerateImplicitNullCheck(instruction); |
| 4032 | } else { |
| 4033 | GenerateExplicitNullCheck(instruction); |
| 4034 | } |
| 4035 | } |
| 4036 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4037 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4038 | LocationSummary* locations = |
| 4039 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4040 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4041 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4042 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4043 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4044 | } else { |
| 4045 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 4046 | // the array's location. |
| 4047 | locations->SetOut(Location::RequiresRegister(), |
| 4048 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 4049 | : Location::kNoOutputOverlap); |
| 4050 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4054 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4055 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4056 | Location index = locations->InAt(1); |
| 4057 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4058 | Primitive::Type type = instruction->GetType(); |
| 4059 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4060 | case Primitive::kPrimBoolean: { |
| 4061 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4062 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4063 | if (index.IsConstant()) { |
| 4064 | __ movzxb(out, Address(obj, |
| 4065 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4066 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4067 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4068 | } |
| 4069 | break; |
| 4070 | } |
| 4071 | |
| 4072 | case Primitive::kPrimByte: { |
| 4073 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4074 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4075 | if (index.IsConstant()) { |
| 4076 | __ movsxb(out, Address(obj, |
| 4077 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4078 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4079 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4080 | } |
| 4081 | break; |
| 4082 | } |
| 4083 | |
| 4084 | case Primitive::kPrimShort: { |
| 4085 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4086 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4087 | if (index.IsConstant()) { |
| 4088 | __ movsxw(out, Address(obj, |
| 4089 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4090 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4091 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4092 | } |
| 4093 | break; |
| 4094 | } |
| 4095 | |
| 4096 | case Primitive::kPrimChar: { |
| 4097 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4098 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4099 | if (index.IsConstant()) { |
| 4100 | __ movzxw(out, Address(obj, |
| 4101 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4102 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4103 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4104 | } |
| 4105 | break; |
| 4106 | } |
| 4107 | |
| 4108 | case Primitive::kPrimInt: |
| 4109 | case Primitive::kPrimNot: { |
| 4110 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4111 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4112 | if (index.IsConstant()) { |
| 4113 | __ movl(out, Address(obj, |
| 4114 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4115 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4116 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4117 | } |
| 4118 | break; |
| 4119 | } |
| 4120 | |
| 4121 | case Primitive::kPrimLong: { |
| 4122 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4123 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4124 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4125 | if (index.IsConstant()) { |
| 4126 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4127 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4128 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4129 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4130 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4131 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4132 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4133 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4134 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4135 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4136 | } |
| 4137 | break; |
| 4138 | } |
| 4139 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4140 | case Primitive::kPrimFloat: { |
| 4141 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4142 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4143 | if (index.IsConstant()) { |
| 4144 | __ movss(out, Address(obj, |
| 4145 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4146 | } else { |
| 4147 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4148 | } |
| 4149 | break; |
| 4150 | } |
| 4151 | |
| 4152 | case Primitive::kPrimDouble: { |
| 4153 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4154 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4155 | if (index.IsConstant()) { |
| 4156 | __ movsd(out, Address(obj, |
| 4157 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4158 | } else { |
| 4159 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4160 | } |
| 4161 | break; |
| 4162 | } |
| 4163 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4164 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4165 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4166 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4167 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4168 | |
| 4169 | if (type != Primitive::kPrimLong) { |
| 4170 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4171 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4172 | |
| 4173 | if (type == Primitive::kPrimNot) { |
| 4174 | Register out = locations->Out().AsRegister<Register>(); |
| 4175 | __ MaybeUnpoisonHeapReference(out); |
| 4176 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4180 | // This location builder might end up asking to up to four registers, which is |
| 4181 | // not currently possible for baseline. The situation in which we need four |
| 4182 | // registers cannot be met by baseline though, because it has not run any |
| 4183 | // optimization. |
| 4184 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4185 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4186 | bool needs_write_barrier = |
| 4187 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4188 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4189 | bool needs_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4190 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4191 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4192 | instruction, |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4193 | needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4194 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4195 | if (needs_runtime_call) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4196 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4197 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4198 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4199 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4200 | } else { |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4201 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4202 | || (value_type == Primitive::kPrimByte); |
Nicolas Geoffray | 9ae0daa | 2014-09-30 22:40:23 +0100 | [diff] [blame] | 4203 | // 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] | 4204 | // In case of a byte operation, the register allocator does not support multiple |
| 4205 | // inputs that die at entry with one in a specific register. |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4206 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4207 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 7adfcc8 | 2014-10-07 12:24:52 +0100 | [diff] [blame] | 4208 | if (is_byte_type) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4209 | // Ensure the value is in a byte register. |
| 4210 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4211 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4212 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4213 | } else { |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4214 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4215 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4216 | if (needs_write_barrier) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4217 | // Temporary registers for the write barrier. |
| 4218 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4219 | // Ensure the card is in a byte register. |
| 4220 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4221 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4222 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4226 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4227 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4228 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4229 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4230 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4231 | bool needs_runtime_call = locations->WillCall(); |
| 4232 | bool needs_write_barrier = |
| 4233 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4234 | |
| 4235 | switch (value_type) { |
| 4236 | case Primitive::kPrimBoolean: |
| 4237 | case Primitive::kPrimByte: { |
| 4238 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4239 | if (index.IsConstant()) { |
| 4240 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4241 | if (value.IsRegister()) { |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4242 | __ movb(Address(obj, offset), value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4243 | } else { |
| 4244 | __ movb(Address(obj, offset), |
| 4245 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4246 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4247 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4248 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4249 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4250 | value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4251 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4252 | __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4253 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4254 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4255 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4256 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4257 | break; |
| 4258 | } |
| 4259 | |
| 4260 | case Primitive::kPrimShort: |
| 4261 | case Primitive::kPrimChar: { |
| 4262 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4263 | if (index.IsConstant()) { |
| 4264 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset; |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4265 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4266 | __ movw(Address(obj, offset), value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4267 | } else { |
| 4268 | __ movw(Address(obj, offset), |
| 4269 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4270 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4271 | } else { |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4272 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4273 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
| 4274 | value.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4275 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4276 | __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4277 | Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
| 4278 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4279 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4280 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4281 | break; |
| 4282 | } |
| 4283 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4284 | case Primitive::kPrimInt: |
| 4285 | case Primitive::kPrimNot: { |
| 4286 | if (!needs_runtime_call) { |
| 4287 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4288 | if (index.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4289 | size_t offset = |
| 4290 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4291 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4292 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4293 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4294 | __ movl(temp, value.AsRegister<Register>()); |
| 4295 | __ PoisonHeapReference(temp); |
| 4296 | __ movl(Address(obj, offset), temp); |
| 4297 | } else { |
| 4298 | __ movl(Address(obj, offset), value.AsRegister<Register>()); |
| 4299 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4300 | } else { |
| 4301 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4302 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4303 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4304 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4305 | // Note: if heap poisoning is enabled, no need to poison |
| 4306 | // (negate) `v` if it is a reference, as it would be null. |
| 4307 | __ movl(Address(obj, offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4308 | } |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4309 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4310 | DCHECK(index.IsRegister()) << index; |
| 4311 | if (value.IsRegister()) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4312 | if (kPoisonHeapReferences && value_type == Primitive::kPrimNot) { |
| 4313 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4314 | __ movl(temp, value.AsRegister<Register>()); |
| 4315 | __ PoisonHeapReference(temp); |
| 4316 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), temp); |
| 4317 | } else { |
| 4318 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4319 | value.AsRegister<Register>()); |
| 4320 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4321 | } else { |
| 4322 | DCHECK(value.IsConstant()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4323 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4324 | // `value_type == Primitive::kPrimNot` implies `v == 0`. |
| 4325 | DCHECK((value_type != Primitive::kPrimNot) || (v == 0)); |
| 4326 | // Note: if heap poisoning is enabled, no need to poison |
| 4327 | // (negate) `v` if it is a reference, as it would be null. |
| 4328 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), Immediate(v)); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4329 | } |
| 4330 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4331 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4332 | |
| 4333 | if (needs_write_barrier) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4334 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4335 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4336 | codegen_->MarkGCCard( |
| 4337 | temp, card, obj, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4338 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4339 | } else { |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4340 | DCHECK_EQ(value_type, Primitive::kPrimNot); |
| 4341 | DCHECK(!codegen_->IsLeafMethod()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4342 | // Note: if heap poisoning is enabled, pAputObject takes cares |
| 4343 | // of poisoning the reference. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4344 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 4345 | instruction, |
| 4346 | instruction->GetDexPc(), |
| 4347 | nullptr); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4348 | } |
| 4349 | break; |
| 4350 | } |
| 4351 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4352 | case Primitive::kPrimLong: { |
| 4353 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4354 | if (index.IsConstant()) { |
| 4355 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4356 | if (value.IsRegisterPair()) { |
| 4357 | __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4358 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4359 | __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4360 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4361 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4362 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
| 4363 | __ movl(Address(obj, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4364 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4365 | __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val))); |
| 4366 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4367 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4368 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4369 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4370 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4371 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4372 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4373 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4374 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4375 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4376 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4377 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4378 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4379 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4380 | __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4381 | Immediate(High32Bits(val))); |
| 4382 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4383 | } |
| 4384 | break; |
| 4385 | } |
| 4386 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4387 | case Primitive::kPrimFloat: { |
| 4388 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4389 | DCHECK(value.IsFpuRegister()); |
| 4390 | if (index.IsConstant()) { |
| 4391 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4392 | __ movss(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4393 | } else { |
| 4394 | __ movss(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset), |
| 4395 | value.AsFpuRegister<XmmRegister>()); |
| 4396 | } |
| 4397 | break; |
| 4398 | } |
| 4399 | |
| 4400 | case Primitive::kPrimDouble: { |
| 4401 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4402 | DCHECK(value.IsFpuRegister()); |
| 4403 | if (index.IsConstant()) { |
| 4404 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
| 4405 | __ movsd(Address(obj, offset), value.AsFpuRegister<XmmRegister>()); |
| 4406 | } else { |
| 4407 | __ movsd(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset), |
| 4408 | value.AsFpuRegister<XmmRegister>()); |
| 4409 | } |
| 4410 | break; |
| 4411 | } |
| 4412 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4413 | case Primitive::kPrimVoid: |
| 4414 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4415 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4420 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4421 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4422 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4426 | LocationSummary* locations = instruction->GetLocations(); |
| 4427 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4428 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4429 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4430 | __ movl(out, Address(obj, offset)); |
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 | } |
| 4433 | |
| 4434 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 659562a | 2015-09-14 21:26:33 +0000 | [diff] [blame^] | 4435 | LocationSummary* locations = |
| 4436 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4437 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4438 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4439 | if (instruction->HasUses()) { |
| 4440 | locations->SetOut(Location::SameAsFirstInput()); |
| 4441 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4445 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4446 | Location index_loc = locations->InAt(0); |
| 4447 | Location length_loc = locations->InAt(1); |
| 4448 | SlowPathCodeX86* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4449 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4450 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4451 | if (length_loc.IsConstant()) { |
| 4452 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4453 | if (index_loc.IsConstant()) { |
| 4454 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4455 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4456 | if (index < 0 || index >= length) { |
| 4457 | codegen_->AddSlowPath(slow_path); |
| 4458 | __ jmp(slow_path->GetEntryLabel()); |
| 4459 | } else { |
| 4460 | // Some optimization after BCE may have generated this, and we should not |
| 4461 | // generate a bounds check if it is a valid range. |
| 4462 | } |
| 4463 | return; |
| 4464 | } |
| 4465 | |
| 4466 | // We have to reverse the jump condition because the length is the constant. |
| 4467 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4468 | __ cmpl(index_reg, Immediate(length)); |
| 4469 | codegen_->AddSlowPath(slow_path); |
| 4470 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4471 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4472 | Register length = length_loc.AsRegister<Register>(); |
| 4473 | if (index_loc.IsConstant()) { |
| 4474 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4475 | __ cmpl(length, Immediate(value)); |
| 4476 | } else { |
| 4477 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4478 | } |
| 4479 | codegen_->AddSlowPath(slow_path); |
| 4480 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4481 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4482 | } |
| 4483 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4484 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4485 | temp->SetLocations(nullptr); |
| 4486 | } |
| 4487 | |
| 4488 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4489 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4490 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4491 | } |
| 4492 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4493 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4494 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4495 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4499 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4500 | } |
| 4501 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4502 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4503 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4504 | } |
| 4505 | |
| 4506 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4507 | HBasicBlock* block = instruction->GetBlock(); |
| 4508 | if (block->GetLoopInformation() != nullptr) { |
| 4509 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4510 | // The back edge will generate the suspend check. |
| 4511 | return; |
| 4512 | } |
| 4513 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4514 | // The goto will generate the suspend check. |
| 4515 | return; |
| 4516 | } |
| 4517 | GenerateSuspendCheck(instruction, nullptr); |
| 4518 | } |
| 4519 | |
| 4520 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4521 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4522 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4523 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4524 | if (slow_path == nullptr) { |
| 4525 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4526 | instruction->SetSlowPath(slow_path); |
| 4527 | codegen_->AddSlowPath(slow_path); |
| 4528 | if (successor != nullptr) { |
| 4529 | DCHECK(successor->IsLoopHeader()); |
| 4530 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4531 | } |
| 4532 | } else { |
| 4533 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4534 | } |
| 4535 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4536 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4537 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4538 | if (successor == nullptr) { |
| 4539 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4540 | __ Bind(slow_path->GetReturnLabel()); |
| 4541 | } else { |
| 4542 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4543 | __ jmp(slow_path->GetEntryLabel()); |
| 4544 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4547 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4548 | return codegen_->GetAssembler(); |
| 4549 | } |
| 4550 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4551 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4552 | ScratchRegisterScope ensure_scratch( |
| 4553 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4554 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4555 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4556 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4557 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4561 | ScratchRegisterScope ensure_scratch( |
| 4562 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4563 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4564 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4565 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4566 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4567 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4568 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
| 4572 | MoveOperands* move = moves_.Get(index); |
| 4573 | Location source = move->GetSource(); |
| 4574 | Location destination = move->GetDestination(); |
| 4575 | |
| 4576 | if (source.IsRegister()) { |
| 4577 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4578 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4579 | } else { |
| 4580 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4581 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4582 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4583 | } else if (source.IsFpuRegister()) { |
| 4584 | if (destination.IsFpuRegister()) { |
| 4585 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4586 | } else if (destination.IsStackSlot()) { |
| 4587 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4588 | } else { |
| 4589 | DCHECK(destination.IsDoubleStackSlot()); |
| 4590 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4591 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4592 | } else if (source.IsStackSlot()) { |
| 4593 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4594 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4595 | } else if (destination.IsFpuRegister()) { |
| 4596 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4597 | } else { |
| 4598 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4599 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4600 | } |
| 4601 | } else if (source.IsDoubleStackSlot()) { |
| 4602 | if (destination.IsFpuRegister()) { |
| 4603 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4604 | } else { |
| 4605 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4606 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4607 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4608 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4609 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4610 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4611 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4612 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4613 | if (value == 0) { |
| 4614 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4615 | } else { |
| 4616 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4617 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4618 | } else { |
| 4619 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4620 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4621 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4622 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4623 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4624 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4625 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4626 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4627 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4628 | if (value == 0) { |
| 4629 | // Easy handling of 0.0. |
| 4630 | __ xorps(dest, dest); |
| 4631 | } else { |
| 4632 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4633 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4634 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4635 | __ movl(temp, Immediate(value)); |
| 4636 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4637 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4638 | } else { |
| 4639 | DCHECK(destination.IsStackSlot()) << destination; |
| 4640 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4641 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4642 | } else if (constant->IsLongConstant()) { |
| 4643 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4644 | int32_t low_value = Low32Bits(value); |
| 4645 | int32_t high_value = High32Bits(value); |
| 4646 | Immediate low(low_value); |
| 4647 | Immediate high(high_value); |
| 4648 | if (destination.IsDoubleStackSlot()) { |
| 4649 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4650 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4651 | } else { |
| 4652 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4653 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4654 | } |
| 4655 | } else { |
| 4656 | DCHECK(constant->IsDoubleConstant()); |
| 4657 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4658 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4659 | int32_t low_value = Low32Bits(value); |
| 4660 | int32_t high_value = High32Bits(value); |
| 4661 | Immediate low(low_value); |
| 4662 | Immediate high(high_value); |
| 4663 | if (destination.IsFpuRegister()) { |
| 4664 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4665 | if (value == 0) { |
| 4666 | // Easy handling of 0.0. |
| 4667 | __ xorpd(dest, dest); |
| 4668 | } else { |
| 4669 | __ pushl(high); |
| 4670 | __ pushl(low); |
| 4671 | __ movsd(dest, Address(ESP, 0)); |
| 4672 | __ addl(ESP, Immediate(8)); |
| 4673 | } |
| 4674 | } else { |
| 4675 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4676 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4677 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4678 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4679 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4680 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4681 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4685 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4686 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4687 | ScratchRegisterScope ensure_scratch( |
| 4688 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4689 | |
| 4690 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4691 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4692 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4693 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4694 | } |
| 4695 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4696 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4697 | ScratchRegisterScope ensure_scratch( |
| 4698 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4699 | |
| 4700 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4701 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4702 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4703 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4704 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4705 | } |
| 4706 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4707 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4708 | ScratchRegisterScope ensure_scratch1( |
| 4709 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4710 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4711 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4712 | ScratchRegisterScope ensure_scratch2( |
| 4713 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4714 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4715 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4716 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4717 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4718 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4719 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4720 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
| 4724 | MoveOperands* move = moves_.Get(index); |
| 4725 | Location source = move->GetSource(); |
| 4726 | Location destination = move->GetDestination(); |
| 4727 | |
| 4728 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4729 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4730 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4731 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4732 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4733 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4734 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4735 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4736 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4737 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4738 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4739 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4740 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4741 | // Use XOR Swap algorithm to avoid a temporary. |
| 4742 | DCHECK_NE(source.reg(), destination.reg()); |
| 4743 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4744 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4745 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4746 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4747 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4748 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4749 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4750 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4751 | // Take advantage of the 16 bytes in the XMM register. |
| 4752 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4753 | Address stack(ESP, destination.GetStackIndex()); |
| 4754 | // Load the double into the high doubleword. |
| 4755 | __ movhpd(reg, stack); |
| 4756 | |
| 4757 | // Store the low double into the destination. |
| 4758 | __ movsd(stack, reg); |
| 4759 | |
| 4760 | // Move the high double to the low double. |
| 4761 | __ psrldq(reg, Immediate(8)); |
| 4762 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4763 | // Take advantage of the 16 bytes in the XMM register. |
| 4764 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4765 | Address stack(ESP, source.GetStackIndex()); |
| 4766 | // Load the double into the high doubleword. |
| 4767 | __ movhpd(reg, stack); |
| 4768 | |
| 4769 | // Store the low double into the destination. |
| 4770 | __ movsd(stack, reg); |
| 4771 | |
| 4772 | // Move the high double to the low double. |
| 4773 | __ psrldq(reg, Immediate(8)); |
| 4774 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4775 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4776 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4777 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4778 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4779 | } |
| 4780 | } |
| 4781 | |
| 4782 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4783 | __ pushl(static_cast<Register>(reg)); |
| 4784 | } |
| 4785 | |
| 4786 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4787 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4788 | } |
| 4789 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4790 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4791 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4792 | ? LocationSummary::kCallOnSlowPath |
| 4793 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4794 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4795 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4796 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4797 | locations->SetOut(Location::RequiresRegister()); |
| 4798 | } |
| 4799 | |
| 4800 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4801 | LocationSummary* locations = cls->GetLocations(); |
| 4802 | Register out = locations->Out().AsRegister<Register>(); |
| 4803 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4804 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4805 | DCHECK(!cls->CanCallRuntime()); |
| 4806 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4807 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4808 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4809 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4810 | __ movl(out, Address( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4811 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4812 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4813 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4814 | |
| 4815 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4816 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4817 | codegen_->AddSlowPath(slow_path); |
| 4818 | __ testl(out, out); |
| 4819 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4820 | if (cls->MustGenerateClinitCheck()) { |
| 4821 | GenerateClassInitializationCheck(slow_path, out); |
| 4822 | } else { |
| 4823 | __ Bind(slow_path->GetExitLabel()); |
| 4824 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4825 | } |
| 4826 | } |
| 4827 | |
| 4828 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4829 | LocationSummary* locations = |
| 4830 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4831 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4832 | if (check->HasUses()) { |
| 4833 | locations->SetOut(Location::SameAsFirstInput()); |
| 4834 | } |
| 4835 | } |
| 4836 | |
| 4837 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4838 | // We assume the class to not be null. |
| 4839 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 4840 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4841 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4842 | GenerateClassInitializationCheck(slow_path, |
| 4843 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4844 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4845 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4846 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
| 4847 | SlowPathCodeX86* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4848 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4849 | Immediate(mirror::Class::kStatusInitialized)); |
| 4850 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4851 | __ Bind(slow_path->GetExitLabel()); |
| 4852 | // No need for memory fence, thanks to the X86 memory model. |
| 4853 | } |
| 4854 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4855 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4856 | LocationSummary* locations = |
| 4857 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4858 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4859 | locations->SetOut(Location::RequiresRegister()); |
| 4860 | } |
| 4861 | |
| 4862 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
| 4863 | SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 4864 | codegen_->AddSlowPath(slow_path); |
| 4865 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4866 | LocationSummary* locations = load->GetLocations(); |
| 4867 | Register out = locations->Out().AsRegister<Register>(); |
| 4868 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4869 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4870 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4871 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4872 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4873 | __ testl(out, out); |
| 4874 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4875 | __ Bind(slow_path->GetExitLabel()); |
| 4876 | } |
| 4877 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4878 | static Address GetExceptionTlsAddress() { |
| 4879 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 4880 | } |
| 4881 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4882 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4883 | LocationSummary* locations = |
| 4884 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4885 | locations->SetOut(Location::RequiresRegister()); |
| 4886 | } |
| 4887 | |
| 4888 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4889 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 4890 | } |
| 4891 | |
| 4892 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 4893 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4894 | } |
| 4895 | |
| 4896 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4897 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 4901 | LocationSummary* locations = |
| 4902 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4903 | InvokeRuntimeCallingConvention calling_convention; |
| 4904 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4905 | } |
| 4906 | |
| 4907 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 4908 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 4909 | instruction, |
| 4910 | instruction->GetDexPc(), |
| 4911 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4914 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4915 | LocationSummary::CallKind call_kind = instruction->IsClassFinal() |
| 4916 | ? LocationSummary::kNoCall |
| 4917 | : LocationSummary::kCallOnSlowPath; |
| 4918 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4920 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4921 | // Note that TypeCheckSlowPathX86 uses this register too. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4922 | locations->SetOut(Location::RequiresRegister()); |
| 4923 | } |
| 4924 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4925 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4926 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4927 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4928 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4929 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4930 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4931 | Label done, zero; |
| 4932 | SlowPathCodeX86* slow_path = nullptr; |
| 4933 | |
| 4934 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4935 | // Avoid null check if we know obj is not null. |
| 4936 | if (instruction->MustDoNullCheck()) { |
| 4937 | __ testl(obj, obj); |
| 4938 | __ j(kEqual, &zero); |
| 4939 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4940 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4941 | __ movl(out, Address(obj, class_offset)); |
| 4942 | __ MaybeUnpoisonHeapReference(out); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4943 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4944 | __ cmpl(out, cls.AsRegister<Register>()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4945 | } else { |
| 4946 | DCHECK(cls.IsStackSlot()) << cls; |
| 4947 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 4948 | } |
| 4949 | |
| 4950 | if (instruction->IsClassFinal()) { |
| 4951 | // Classes must be equal for the instanceof to succeed. |
| 4952 | __ j(kNotEqual, &zero); |
| 4953 | __ movl(out, Immediate(1)); |
| 4954 | __ jmp(&done); |
| 4955 | } else { |
| 4956 | // If the classes are not equal, we go into a slow path. |
| 4957 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4958 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4959 | codegen_->AddSlowPath(slow_path); |
| 4960 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4961 | __ movl(out, Immediate(1)); |
| 4962 | __ jmp(&done); |
| 4963 | } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4964 | |
| 4965 | if (instruction->MustDoNullCheck() || instruction->IsClassFinal()) { |
| 4966 | __ Bind(&zero); |
| 4967 | __ movl(out, Immediate(0)); |
| 4968 | } |
| 4969 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4970 | if (slow_path != nullptr) { |
| 4971 | __ Bind(slow_path->GetExitLabel()); |
| 4972 | } |
| 4973 | __ Bind(&done); |
| 4974 | } |
| 4975 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4976 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
| 4977 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4978 | instruction, LocationSummary::kCallOnSlowPath); |
| 4979 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4980 | locations->SetInAt(1, Location::Any()); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4981 | // Note that TypeCheckSlowPathX86 uses this register too. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4982 | locations->AddTemp(Location::RequiresRegister()); |
| 4983 | } |
| 4984 | |
| 4985 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 4986 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4987 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4988 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4989 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4990 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4991 | SlowPathCodeX86* slow_path = |
| 4992 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4993 | codegen_->AddSlowPath(slow_path); |
| 4994 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4995 | // Avoid null check if we know obj is not null. |
| 4996 | if (instruction->MustDoNullCheck()) { |
| 4997 | __ testl(obj, obj); |
| 4998 | __ j(kEqual, slow_path->GetExitLabel()); |
| 4999 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5000 | // Compare the class of `obj` with `cls`. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5001 | __ movl(temp, Address(obj, class_offset)); |
| 5002 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5003 | if (cls.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5004 | __ cmpl(temp, cls.AsRegister<Register>()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5005 | } else { |
| 5006 | DCHECK(cls.IsStackSlot()) << cls; |
| 5007 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5008 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5009 | // The checkcast succeeds if the classes are equal (fast path). |
| 5010 | // Otherwise, we need to go into the slow path to check the types. |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5011 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5012 | __ Bind(slow_path->GetExitLabel()); |
| 5013 | } |
| 5014 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5015 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5016 | LocationSummary* locations = |
| 5017 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5018 | InvokeRuntimeCallingConvention calling_convention; |
| 5019 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5020 | } |
| 5021 | |
| 5022 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5023 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5024 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5025 | instruction, |
| 5026 | instruction->GetDexPc(), |
| 5027 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5028 | } |
| 5029 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5030 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5031 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5032 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5033 | |
| 5034 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5035 | LocationSummary* locations = |
| 5036 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5037 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5038 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5039 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5040 | locations->SetInAt(1, Location::Any()); |
| 5041 | locations->SetOut(Location::SameAsFirstInput()); |
| 5042 | } |
| 5043 | |
| 5044 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 5045 | HandleBitwiseOperation(instruction); |
| 5046 | } |
| 5047 | |
| 5048 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 5049 | HandleBitwiseOperation(instruction); |
| 5050 | } |
| 5051 | |
| 5052 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 5053 | HandleBitwiseOperation(instruction); |
| 5054 | } |
| 5055 | |
| 5056 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5057 | LocationSummary* locations = instruction->GetLocations(); |
| 5058 | Location first = locations->InAt(0); |
| 5059 | Location second = locations->InAt(1); |
| 5060 | DCHECK(first.Equals(locations->Out())); |
| 5061 | |
| 5062 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5063 | if (second.IsRegister()) { |
| 5064 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5065 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5066 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5067 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5068 | } else { |
| 5069 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5070 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5071 | } |
| 5072 | } else if (second.IsConstant()) { |
| 5073 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5074 | __ andl(first.AsRegister<Register>(), |
| 5075 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5076 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5077 | __ orl(first.AsRegister<Register>(), |
| 5078 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5079 | } else { |
| 5080 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5081 | __ xorl(first.AsRegister<Register>(), |
| 5082 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5083 | } |
| 5084 | } else { |
| 5085 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5086 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5087 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5088 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5089 | } else { |
| 5090 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5091 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5092 | } |
| 5093 | } |
| 5094 | } else { |
| 5095 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5096 | if (second.IsRegisterPair()) { |
| 5097 | if (instruction->IsAnd()) { |
| 5098 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5099 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5100 | } else if (instruction->IsOr()) { |
| 5101 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5102 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5103 | } else { |
| 5104 | DCHECK(instruction->IsXor()); |
| 5105 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5106 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5107 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5108 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5109 | if (instruction->IsAnd()) { |
| 5110 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5111 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5112 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5113 | } else if (instruction->IsOr()) { |
| 5114 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5115 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5116 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5117 | } else { |
| 5118 | DCHECK(instruction->IsXor()); |
| 5119 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5120 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5121 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5122 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5123 | } else { |
| 5124 | DCHECK(second.IsConstant()) << second; |
| 5125 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5126 | int32_t low_value = Low32Bits(value); |
| 5127 | int32_t high_value = High32Bits(value); |
| 5128 | Immediate low(low_value); |
| 5129 | Immediate high(high_value); |
| 5130 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5131 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5132 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5133 | if (low_value == 0) { |
| 5134 | __ xorl(first_low, first_low); |
| 5135 | } else if (low_value != -1) { |
| 5136 | __ andl(first_low, low); |
| 5137 | } |
| 5138 | if (high_value == 0) { |
| 5139 | __ xorl(first_high, first_high); |
| 5140 | } else if (high_value != -1) { |
| 5141 | __ andl(first_high, high); |
| 5142 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5143 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5144 | if (low_value != 0) { |
| 5145 | __ orl(first_low, low); |
| 5146 | } |
| 5147 | if (high_value != 0) { |
| 5148 | __ orl(first_high, high); |
| 5149 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5150 | } else { |
| 5151 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5152 | if (low_value != 0) { |
| 5153 | __ xorl(first_low, low); |
| 5154 | } |
| 5155 | if (high_value != 0) { |
| 5156 | __ xorl(first_high, high); |
| 5157 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5158 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5159 | } |
| 5160 | } |
| 5161 | } |
| 5162 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5163 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5164 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5165 | UNUSED(instruction); |
| 5166 | LOG(FATAL) << "Unreachable"; |
| 5167 | } |
| 5168 | |
| 5169 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5170 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5171 | UNUSED(instruction); |
| 5172 | LOG(FATAL) << "Unreachable"; |
| 5173 | } |
| 5174 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5175 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5176 | DCHECK(codegen_->IsBaseline()); |
| 5177 | LocationSummary* locations = |
| 5178 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5179 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5180 | } |
| 5181 | |
| 5182 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5183 | DCHECK(codegen_->IsBaseline()); |
| 5184 | // Will be generated at use site. |
| 5185 | } |
| 5186 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5187 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 5188 | HX86ComputeBaseMethodAddress* insn) { |
| 5189 | LocationSummary* locations = |
| 5190 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5191 | locations->SetOut(Location::RequiresRegister()); |
| 5192 | } |
| 5193 | |
| 5194 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 5195 | HX86ComputeBaseMethodAddress* insn) { |
| 5196 | LocationSummary* locations = insn->GetLocations(); |
| 5197 | Register reg = locations->Out().AsRegister<Register>(); |
| 5198 | |
| 5199 | // Generate call to next instruction. |
| 5200 | Label next_instruction; |
| 5201 | __ call(&next_instruction); |
| 5202 | __ Bind(&next_instruction); |
| 5203 | |
| 5204 | // Remember this offset for later use with constant area. |
| 5205 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 5206 | |
| 5207 | // Grab the return address off the stack. |
| 5208 | __ popl(reg); |
| 5209 | } |
| 5210 | |
| 5211 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 5212 | HX86LoadFromConstantTable* insn) { |
| 5213 | LocationSummary* locations = |
| 5214 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5215 | |
| 5216 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5217 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 5218 | |
| 5219 | // If we don't need to be materialized, we only need the inputs to be set. |
| 5220 | if (!insn->NeedsMaterialization()) { |
| 5221 | return; |
| 5222 | } |
| 5223 | |
| 5224 | switch (insn->GetType()) { |
| 5225 | case Primitive::kPrimFloat: |
| 5226 | case Primitive::kPrimDouble: |
| 5227 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5228 | break; |
| 5229 | |
| 5230 | case Primitive::kPrimInt: |
| 5231 | locations->SetOut(Location::RequiresRegister()); |
| 5232 | break; |
| 5233 | |
| 5234 | default: |
| 5235 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 5240 | if (!insn->NeedsMaterialization()) { |
| 5241 | return; |
| 5242 | } |
| 5243 | |
| 5244 | LocationSummary* locations = insn->GetLocations(); |
| 5245 | Location out = locations->Out(); |
| 5246 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 5247 | HConstant *value = insn->GetConstant(); |
| 5248 | |
| 5249 | switch (insn->GetType()) { |
| 5250 | case Primitive::kPrimFloat: |
| 5251 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 5252 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 5253 | break; |
| 5254 | |
| 5255 | case Primitive::kPrimDouble: |
| 5256 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 5257 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 5258 | break; |
| 5259 | |
| 5260 | case Primitive::kPrimInt: |
| 5261 | __ movl(out.AsRegister<Register>(), |
| 5262 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 5263 | break; |
| 5264 | |
| 5265 | default: |
| 5266 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5267 | } |
| 5268 | } |
| 5269 | |
| 5270 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 5271 | // Generate the constant area if needed. |
| 5272 | X86Assembler* assembler = GetAssembler(); |
| 5273 | if (!assembler->IsConstantAreaEmpty()) { |
| 5274 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5275 | // byte values. |
| 5276 | assembler->Align(4, 0); |
| 5277 | constant_area_start_ = assembler->CodeSize(); |
| 5278 | assembler->AddConstantArea(); |
| 5279 | } |
| 5280 | |
| 5281 | // And finish up. |
| 5282 | CodeGenerator::Finalize(allocator); |
| 5283 | } |
| 5284 | |
| 5285 | /** |
| 5286 | * Class to handle late fixup of offsets into constant area. |
| 5287 | */ |
| 5288 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 5289 | public: |
| 5290 | RIPFixup(const CodeGeneratorX86& codegen, int offset) |
| 5291 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5292 | |
| 5293 | private: |
| 5294 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5295 | // Patch the correct offset for the instruction. The place to patch is the |
| 5296 | // last 4 bytes of the instruction. |
| 5297 | // The value to patch is the distance from the offset in the constant area |
| 5298 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| 5299 | int32_t constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5300 | int32_t relative_position = constant_offset - codegen_.GetMethodAddressOffset();; |
| 5301 | |
| 5302 | // Patch in the right value. |
| 5303 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5304 | } |
| 5305 | |
| 5306 | const CodeGeneratorX86& codegen_; |
| 5307 | |
| 5308 | // Location in constant area that the fixup refers to. |
| 5309 | int offset_into_constant_area_; |
| 5310 | }; |
| 5311 | |
| 5312 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 5313 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5314 | return Address(reg, kDummy32BitOffset, fixup); |
| 5315 | } |
| 5316 | |
| 5317 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 5318 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5319 | return Address(reg, kDummy32BitOffset, fixup); |
| 5320 | } |
| 5321 | |
| 5322 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 5323 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5324 | return Address(reg, kDummy32BitOffset, fixup); |
| 5325 | } |
| 5326 | |
| 5327 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 5328 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5329 | return Address(reg, kDummy32BitOffset, fixup); |
| 5330 | } |
| 5331 | |
| 5332 | /** |
| 5333 | * Finds instructions that need the constant area base as an input. |
| 5334 | */ |
| 5335 | class ConstantHandlerVisitor : public HGraphVisitor { |
| 5336 | public: |
| 5337 | explicit ConstantHandlerVisitor(HGraph* graph) : HGraphVisitor(graph), base_(nullptr) {} |
| 5338 | |
| 5339 | private: |
| 5340 | void VisitAdd(HAdd* add) OVERRIDE { |
| 5341 | BinaryFP(add); |
| 5342 | } |
| 5343 | |
| 5344 | void VisitSub(HSub* sub) OVERRIDE { |
| 5345 | BinaryFP(sub); |
| 5346 | } |
| 5347 | |
| 5348 | void VisitMul(HMul* mul) OVERRIDE { |
| 5349 | BinaryFP(mul); |
| 5350 | } |
| 5351 | |
| 5352 | void VisitDiv(HDiv* div) OVERRIDE { |
| 5353 | BinaryFP(div); |
| 5354 | } |
| 5355 | |
| 5356 | void VisitReturn(HReturn* ret) OVERRIDE { |
| 5357 | HConstant* value = ret->InputAt(0)->AsConstant(); |
| 5358 | if ((value != nullptr && Primitive::IsFloatingPointType(value->GetType()))) { |
| 5359 | ReplaceInput(ret, value, 0, true); |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 5364 | HandleInvoke(invoke); |
| 5365 | } |
| 5366 | |
| 5367 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 5368 | HandleInvoke(invoke); |
| 5369 | } |
| 5370 | |
| 5371 | void VisitInvokeInterface(HInvokeInterface* invoke) OVERRIDE { |
| 5372 | HandleInvoke(invoke); |
| 5373 | } |
| 5374 | |
| 5375 | void BinaryFP(HBinaryOperation* bin) { |
| 5376 | HConstant* rhs = bin->InputAt(1)->AsConstant(); |
| 5377 | if (rhs != nullptr && Primitive::IsFloatingPointType(bin->GetResultType())) { |
| 5378 | ReplaceInput(bin, rhs, 1, false); |
| 5379 | } |
| 5380 | } |
| 5381 | |
| 5382 | void InitializeConstantAreaPointer(HInstruction* user) { |
| 5383 | // Ensure we only initialize the pointer once. |
| 5384 | if (base_ != nullptr) { |
| 5385 | return; |
| 5386 | } |
| 5387 | |
| 5388 | HGraph* graph = GetGraph(); |
| 5389 | HBasicBlock* entry = graph->GetEntryBlock(); |
| 5390 | base_ = new (graph->GetArena()) HX86ComputeBaseMethodAddress(); |
| 5391 | HInstruction* insert_pos = (user->GetBlock() == entry) ? user : entry->GetLastInstruction(); |
| 5392 | entry->InsertInstructionBefore(base_, insert_pos); |
| 5393 | DCHECK(base_ != nullptr); |
| 5394 | } |
| 5395 | |
| 5396 | void ReplaceInput(HInstruction* insn, HConstant* value, int input_index, bool materialize) { |
| 5397 | InitializeConstantAreaPointer(insn); |
| 5398 | HGraph* graph = GetGraph(); |
| 5399 | HBasicBlock* block = insn->GetBlock(); |
| 5400 | HX86LoadFromConstantTable* load_constant = |
| 5401 | new (graph->GetArena()) HX86LoadFromConstantTable(base_, value, materialize); |
| 5402 | block->InsertInstructionBefore(load_constant, insn); |
| 5403 | insn->ReplaceInput(load_constant, input_index); |
| 5404 | } |
| 5405 | |
| 5406 | void HandleInvoke(HInvoke* invoke) { |
| 5407 | // Ensure that we can load FP arguments from the constant area. |
| 5408 | for (size_t i = 0, e = invoke->InputCount(); i < e; i++) { |
| 5409 | HConstant* input = invoke->InputAt(i)->AsConstant(); |
| 5410 | if (input != nullptr && Primitive::IsFloatingPointType(input->GetType())) { |
| 5411 | ReplaceInput(invoke, input, i, true); |
| 5412 | } |
| 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | // The generated HX86ComputeBaseMethodAddress in the entry block needed as an |
| 5417 | // input to the HX86LoadFromConstantTable instructions. |
| 5418 | HX86ComputeBaseMethodAddress* base_; |
| 5419 | }; |
| 5420 | |
| 5421 | void ConstantAreaFixups::Run() { |
| 5422 | ConstantHandlerVisitor visitor(graph_); |
| 5423 | visitor.VisitInsertionOrder(); |
| 5424 | } |
| 5425 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5426 | #undef __ |
| 5427 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5428 | } // namespace x86 |
| 5429 | } // namespace art |